Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2958cf0

Browse files
author
Scott Lee
committed
Address PR comments
1 parent 04c499c commit 2958cf0

9 files changed

+33
-31
lines changed

examples/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# Python Client Examples
22

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

88
## Setup
99

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

1414
## Contributions

examples/api_discovery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# limitations under the License.
1414

1515
"""
16-
Reads the list of the available API versions and prints them.
17-
Similar to running `kubectl api-versions`.
16+
Reads the list of available API versions and prints them. Similar to running
17+
`kubectl api-versions`.
1818
"""
1919

2020
from kubernetes import client, config

examples/in_cluster_config.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
# limitations under the License.
1414

1515
"""
16-
Showcases loading the Kubernetes config from within the cluster. This script
16+
Shows how to load a Kubernetes config from within a cluster. This script
1717
must be run within a pod. You can start a pod with a Python image (for
1818
example, `python:latest`), exec into the pod, install the library, then run
1919
this example.
2020
2121
If you get 403 errors from the API server you will have to configure RBAC to
22-
add the permission to list pods by applying the following manifest:
22+
add permission to list pods by applying the following manifest:
2323
2424
---
2525
kind: ClusterRole

examples/ingress_create.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
"""
1616
Creates deployment, service, and ingress objects. The ingress allows external
17-
network access within the cluster.
17+
network access to the cluster.
1818
"""
1919

2020
from kubernetes import client, config

examples/job_crud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
"""
16-
Creates, updates, and deletes a Job object.
16+
Creates, updates, and deletes a job object.
1717
"""
1818

1919
from os import path

examples/multiple_clusters.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,23 +30,25 @@ def main():
3030
return
3131
contexts = [context['name'] for context in contexts]
3232
active_index = contexts.index(active_context['name'])
33-
option, _ = pick(contexts, title="Pick the context to load",
34-
default_index=active_index)
35-
# Configs can be set in Configuration class directly or using helper
36-
# utility
37-
config.load_kube_config(context=option)
38-
39-
print("Active host is %s" % configuration.Configuration().host)
40-
41-
v1 = client.CoreV1Api()
42-
print("Listing pods with their IPs:")
43-
ret = v1.list_pod_for_all_namespaces(watch=False)
44-
for item in ret.items:
45-
print(
46-
"%s\t%s\t%s" %
47-
(item.status.pod_ip,
48-
item.metadata.namespace,
49-
item.metadata.name))
33+
cluster1, first_index = pick(contexts, title="Pick the first context",
34+
default_index=active_index)
35+
cluster2, _ = pick(contexts, title="Pick the second context",
36+
default_index=first_index)
37+
38+
client1 = client.CoreV1Api(
39+
api_client=config.new_client_from_config(context=cluster1))
40+
client2 = client.CoreV1Api(
41+
api_client=config.new_client_from_config(context=cluster2))
42+
43+
print("\nList of pods on %s:" % cluster1)
44+
for i in client1.list_pod_for_all_namespaces().items:
45+
print("%s\t%s\t%s" %
46+
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))
47+
48+
print("\n\nList of pods on %s:" % cluster2)
49+
for i in client2.list_pod_for_all_namespaces().items:
50+
print("%s\t%s\t%s" %
51+
(i.status.pod_ip, i.metadata.namespace, i.metadata.name))
5052

5153

5254
if __name__ == '__main__':

examples/out_of_cluster_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
"""
16-
Showcases loading the Kubernetes config from outside of the cluster.
16+
Shows how to load a Kubernetes config from outside of the cluster.
1717
"""
1818

1919
from kubernetes import client, config

examples/pod_exec.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# limitations under the License.
1414

1515
"""
16-
Showcases the functionality of exec using a Busybox container.
16+
Shows the functionality of exec using a Busybox container.
1717
"""
1818

1919
import time

examples/pod_namespace_watch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"""
1616
Uses watch to print the stream of events from list namespaces and list pods.
1717
The script will wait for 10 events related to namespaces to occur within
18-
the `timeout_seconds` threshold and then move on to waiting for 10 events
18+
the `timeout_seconds` threshold and then move on to wait for another 10 events
1919
related to pods to occur within the `timeout_seconds` threshold.
2020
"""
2121

0 commit comments

Comments
 (0)