Address PR comments

This commit is contained in:
Scott Lee 2019-09-13 16:16:54 -07:00
parent 04c499c395
commit 2958cf0195
9 changed files with 31 additions and 29 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)
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)
print("Active host is %s" % configuration.Configuration().host)
client1 = client.CoreV1Api(
api_client=config.new_client_from_config(context=cluster1))
client2 = client.CoreV1Api(
api_client=config.new_client_from_config(context=cluster2))
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))
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__':

View File

@ -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

View File

@ -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

View File

@ -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.
"""