Skip to content

Commit

Permalink
Address PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Scott Lee committed Sep 13, 2019
1 parent 04c499c commit 2958cf0
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 31 deletions.
10 changes: 5 additions & 5 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Python Client Examples

This directory contains various examples how to use the Python client. Please
read the description at the top of each script for more information about what
it does and any prequisite steps. Most scripts also include comments throughout
the code.
This directory contains various examples of how to use the Python client.
Please read the description at the top of each example for more information
about what the script does and any prequisites. Most scripts also include
comments throughout the code.

## Setup

These scripts require Python 2.7 or 3.5+ and the Kubernetes client which can be
installed via the directions
installed following the directions
[here](https://github.com/kubernetes-client/python#installation).

## Contributions
Expand Down
4 changes: 2 additions & 2 deletions examples/api_discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# limitations under the License.

"""
Reads the list of the available API versions and prints them.
Similar to running `kubectl api-versions`.
Reads the list of available API versions and prints them. Similar to running
`kubectl api-versions`.
"""

from kubernetes import client, config
Expand Down
4 changes: 2 additions & 2 deletions examples/in_cluster_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@
# limitations under the License.

"""
Showcases loading the Kubernetes config from within the cluster. This script
Shows how to load a Kubernetes config from within a cluster. This script
must be run within a pod. You can start a pod with a Python image (for
example, `python:latest`), exec into the pod, install the library, then run
this example.
If you get 403 errors from the API server you will have to configure RBAC to
add the permission to list pods by applying the following manifest:
add permission to list pods by applying the following manifest:
---
kind: ClusterRole
Expand Down
2 changes: 1 addition & 1 deletion examples/ingress_create.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

"""
Creates deployment, service, and ingress objects. The ingress allows external
network access within the cluster.
network access to the cluster.
"""

from kubernetes import client, config
Expand Down
2 changes: 1 addition & 1 deletion examples/job_crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

"""
Creates, updates, and deletes a Job object.
Creates, updates, and deletes a job object.
"""

from os import path
Expand Down
36 changes: 19 additions & 17 deletions examples/multiple_clusters.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,25 @@ def main():
return
contexts = [context['name'] for context in contexts]
active_index = contexts.index(active_context['name'])
option, _ = pick(contexts, title="Pick the context to load",
default_index=active_index)
# Configs can be set in Configuration class directly or using helper
# utility
config.load_kube_config(context=option)

print("Active host is %s" % configuration.Configuration().host)

v1 = client.CoreV1Api()
print("Listing pods with their IPs:")
ret = v1.list_pod_for_all_namespaces(watch=False)
for item in ret.items:
print(
"%s\t%s\t%s" %
(item.status.pod_ip,
item.metadata.namespace,
item.metadata.name))
cluster1, first_index = pick(contexts, title="Pick the first context",
default_index=active_index)
cluster2, _ = pick(contexts, title="Pick the second context",
default_index=first_index)

client1 = client.CoreV1Api(
api_client=config.new_client_from_config(context=cluster1))
client2 = client.CoreV1Api(
api_client=config.new_client_from_config(context=cluster2))

print("\nList of pods on %s:" % cluster1)
for i in client1.list_pod_for_all_namespaces().items:
print("%s\t%s\t%s" %
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))

print("\n\nList of pods on %s:" % cluster2)
for i in client2.list_pod_for_all_namespaces().items:
print("%s\t%s\t%s" %
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))


if __name__ == '__main__':
Expand Down
2 changes: 1 addition & 1 deletion examples/out_of_cluster_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

"""
Showcases loading the Kubernetes config from outside of the cluster.
Shows how to load a Kubernetes config from outside of the cluster.
"""

from kubernetes import client, config
Expand Down
2 changes: 1 addition & 1 deletion examples/pod_exec.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.

"""
Showcases the functionality of exec using a Busybox container.
Shows the functionality of exec using a Busybox container.
"""

import time
Expand Down
2 changes: 1 addition & 1 deletion examples/pod_namespace_watch.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"""
Uses watch to print the stream of events from list namespaces and list pods.
The script will wait for 10 events related to namespaces to occur within
the `timeout_seconds` threshold and then move on to waiting for 10 events
the `timeout_seconds` threshold and then move on to wait for another 10 events
related to pods to occur within the `timeout_seconds` threshold.
"""

Expand Down

0 comments on commit 2958cf0

Please sign in to comment.