Skip to content

Commit

Permalink
Merge pull request #1435 from Priyankasaggu11929/psaggu-enhance_node_…
Browse files Browse the repository at this point in the history
…labels_example

simplify & enhance the node_labels.py example
  • Loading branch information
k8s-ci-robot authored Apr 28, 2021
2 parents b5fedc3 + 60e8c89 commit c3f1a1c
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions examples/node_labels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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__':
Expand Down

0 comments on commit c3f1a1c

Please sign in to comment.