simplify & enhance the node_labels.py example

This commit is contained in:
Priyanka Saggu 2021-04-27 21:04:42 +05:30 committed by GitHub
parent e2aad06bc4
commit 0e37654613
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -13,16 +13,16 @@
# 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
def main():
config.load_kube_config()
@ -35,10 +35,16 @@ def main():
"baz": None}
}
}
# Creating a list of cluster nodes
node_list = api_instance.list_node()
print("%s\t\t%s" % ("NAME", "LABELS"))
api_response = api_instance.patch_node("minikube", body)
pprint(api_response)
# 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__':