Skip to content

Commit

Permalink
Separate package util into config and watch package
Browse files Browse the repository at this point in the history
  • Loading branch information
mbohlool committed Nov 23, 2016
1 parent 44395d4 commit 26ac2c4
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 22 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand All @@ -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.")
```
Expand Down
4 changes: 2 additions & 2 deletions examples/example1.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:")
Expand Down
10 changes: 5 additions & 5 deletions examples/example2.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")

Expand Down
4 changes: 2 additions & 2 deletions examples/example3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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" %
Expand Down
3 changes: 2 additions & 1 deletion kubernetes/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@
# limitations under the License.

import kubernetes.client
import kubernetes.util
import kubernetes.config
import kubernetes.watch
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,3 @@
# limitations under the License.

from .kube_config import load_kube_config
from .watch import Watch
File renamed without changes.
15 changes: 15 additions & 0 deletions kubernetes/watch/__init__.py
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions kubernetes/util/watch.py → kubernetes/watch/watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ def stream(self, func, *args, **kwargs):
'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
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@
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.
Expand Down

0 comments on commit 26ac2c4

Please sign in to comment.