Skip to content

Support removal of node labels via inventory variables #12752

@broboa

Description

@broboa

What would you like to be added

The node_labels inventory variables should support removal operations:

Allow null values to remove labels

node_labels:
  remove_this: null

Currently, kubespray only adds/updates labels. Removing them requires manual kubectl commands.

Proposed Change

--- a/roles/kubernetes/node-label/tasks/main.yml
+++ b/roles/kubernetes/node-label/tasks/main.yml
@@ -24,7 +24,7 @@

 - name: Populate inventory node label
   set_fact:
-    inventory_node_labels: "{{ inventory_node_labels + ['%s=%s' | format(item.key, item.value)] }}"
+    inventory_node_labels: "{{ inventory_node_labels + [('%s-' | format(item.key)) if item.value is none else ('%s=%s' | format(item.key, item.value))] }}"
   loop: "{{ node_labels | d({}) | dict2items }}"
   when:
     - node_labels is defined

Why is this needed

When managing node labels declaratively through inventory, there's no way to remove previously applied labels without manual intervention. This breaks the declarative model and requires out-of-band operations to clean up obsolete labels/taints.

Supporting removal syntax allows full lifecycle management of node labels through kubespray inventory.

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions