Merge pull request #35 from kubernetes-incubator/o1

Separate package util into config and watch package
This commit is contained in:
mbohlool 2016-11-22 17:55:04 -08:00 committed by GitHub
commit 149d0ad7ef
11 changed files with 38 additions and 22 deletions

View File

@ -11,10 +11,10 @@ list all pods:
```python
import os
from kubernetes import client, util
from kubernetes import client, config
# Configs can be set in Configuration class directly or using helper utility
util.load_kube_config(os.environ["HOME"] + '/.kube/config')
config.load_kube_config(os.environ["HOME"] + '/.kube/config')
v1=client.CoreV1Api()
print("Listing pods with their IPs:")
@ -28,19 +28,19 @@ watch on namespace object:
```python
import os
from kubernetes import client, util
from kubernetes import client, config, watch
# Configs can be set in Configuration class directly or using helper utility
util.load_kube_config(os.environ["HOME"] + '/.kube/config')
config.load_kube_config(os.environ["HOME"] + '/.kube/config')
v1 = client.CoreV1Api()
count = 10
watch = util.Watch()
for event in watch.stream(v1.list_namespace, _request_timeout=60):
w = watch.Watch()
for event in w.stream(v1.list_namespace, _request_timeout=60):
print("Event: %s %s" % (event['type'], event['object'].metadata.name))
count -= 1
if not count:
watch.stop()
w.stop()
print("Ended.")
```

View File

@ -14,13 +14,13 @@
import os
from kubernetes import client, util
from kubernetes import client, config
def main():
# Configs can be set in Configuration class directly or using helper
# utility
util.load_kube_config(os.environ["HOME"] + '/.kube/config')
config.load_kube_config(os.environ["HOME"] + '/.kube/config')
v1 = client.CoreV1Api()
print("Listing pods with their IPs:")

View File

@ -14,22 +14,22 @@
import os
from kubernetes import client, util
from kubernetes import client, config, watch
def main():
# Configs can be set in Configuration class directly or using helper
# utility
util.load_kube_config(os.environ["HOME"] + '/.kube/config')
config.load_kube_config(os.environ["HOME"] + '/.kube/config')
v1 = client.CoreV1Api()
count = 10
watch = util.Watch()
for event in watch.stream(v1.list_namespace, timeout_seconds=10):
w = watch.Watch()
for event in w.stream(v1.list_namespace, timeout_seconds=10):
print("Event: %s %s" % (event['type'], event['object'].metadata.name))
count -= 1
if not count:
watch.stop()
w.stop()
print("Ended.")

View File

@ -14,13 +14,13 @@
import os
from kubernetes import client, util
from kubernetes import client, config
def main():
# Configs can be set in Configuration class directly or using helper
# utility
util.load_kube_config(os.environ["HOME"] + '/.kube/config')
config.load_kube_config(os.environ["HOME"] + '/.kube/config')
print("Supported APIs (* is preferred version):")
print("%-20s %s" %

View File

@ -13,4 +13,5 @@
# limitations under the License.
import kubernetes.client
import kubernetes.util
import kubernetes.config
import kubernetes.watch

View File

@ -13,4 +13,3 @@
# limitations under the License.
from .kube_config import load_kube_config
from .watch import Watch

View File

@ -0,0 +1,15 @@
# Copyright 2016 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from .watch import Watch

View File

@ -98,8 +98,8 @@ class Watch(object):
'object' value will be the same as 'raw_object'.
Example:
v1 = client.CoreV1Api()
watch = util.Watch()
v1 = kubernetes.client.CoreV1Api()
watch = kubernetes.watch.Watch()
for e in watch.stream(v1.list_namespace, resource_version=1127):
type = e['type']
object = e['object'] # object is one of type return_type

View File

@ -45,8 +45,9 @@ setup(
url="http://kubernetes.io",
keywords=["Swagger", "OpenAPI", "Kubernetes"],
install_requires=REQUIRES,
packages=['kubernetes', 'kubernetes.client', 'kubernetes.util',
'kubernetes.client.apis', 'kubernetes.client.models'],
packages=['kubernetes', 'kubernetes.client', 'kubernetes.config',
'kubernetes.watch', 'kubernetes.client.apis',
'kubernetes.client.models'],
include_package_data=True,
long_description="""\
Python client for talk to a kubernetes cluster.