Merge pull request #1435 from Priyankasaggu11929/psaggu-enhance_node_labels_example

simplify & enhance the node_labels.py example
This commit is contained in:
Kubernetes Prow Robot 2021-04-28 10:52:50 -07:00 committed by GitHub
commit c3f1a1c61e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,13 +13,14 @@
# limitations under the License.
"""
Changes the labels of the "minikube" node. Adds the label "foo" with value
"bar" and will overwrite the "foo" label if it already exists. Removes the
label "baz".
This example demonstrates the following:
- Get a list of all the cluster nodes
- Iterate through each node list item
- Add or overwirite label "foo" with the value "bar"
- Remove the label "baz"
- Return the list of node with updated labels
"""
from pprint import pprint
from kubernetes import client, config
@ -36,9 +37,14 @@ def main():
}
}
api_response = api_instance.patch_node("minikube", body)
# Listing the cluster nodes
node_list = api_instance.list_node()
pprint(api_response)
print("%s\t\t%s" % ("NAME", "LABELS"))
# Patching the node labels
for node in node_list.items:
api_response = api_instance.patch_node(node.metadata.name, body)
print("%s\t%s" % (node.metadata.name, node.metadata.labels))
if __name__ == '__main__':