Selaa lähdekoodia

roles that apply arbitrary labels to nodes and namespaces

Grega Bremec 1 kuukausi sitten
vanhempi
commit
1f03947f63

+ 4 - 0
p0f/operators/roles/apply-namespace-labels/defaults/main.yml

@@ -0,0 +1,4 @@
+---
+# Variables that are usually overridden.
+kubeadmin_config: "tmp/kubeconfig-ocp4"
+...

+ 28 - 0
p0f/operators/roles/apply-namespace-labels/tasks/main.yml

@@ -0,0 +1,28 @@
+---
+# Applies infra labels to key projects.
+#
+# Required variables:
+#
+#   namespace_labels      a dictionary of namespace names to label, each one
+#                         containing a dictionary of label key-value pairs
+#
+# Optional variables:
+#
+#   kubeadmin_config      the administrator kubeconfig file (tmp/kubeconfig-ocp4)
+#
+- name: Iterate over all the namespaces in the namespace_labels variable
+  kubernetes.core.k8s:
+    kubeconfig: "{{ kubeadmin_config }}"
+    validate_certs: no
+    api_version: v1
+    kind: namespace
+    name: "{{ namespace }}"
+    template: templates/namespace-patch.yml
+  loop: "{{ namespace_labels.keys() }}"
+  loop_control:
+    loop_var: namespace
+    label: "{{ namespace }}"
+  when:
+    - namespace_labels is defined
+    - namespace_labels.keys() | length > 0
+...

+ 8 - 0
p0f/operators/roles/apply-namespace-labels/templates/namespace-patch.yml

@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Namespace
+metadata:
+  name: {{ namespace }}
+  labels:
+{% for key in namespace_labels[namespace].keys() %}
+    {{ key }}: "{{ namespace_labels[namespace][key] }}"
+{% endfor %}

+ 4 - 0
p0f/operators/roles/apply-node-labels/defaults/main.yml

@@ -0,0 +1,4 @@
+---
+# Variables that are usually overridden.
+kubeadmin_config: "tmp/kubeconfig-ocp4"
+...

+ 30 - 0
p0f/operators/roles/apply-node-labels/tasks/main.yml

@@ -0,0 +1,30 @@
+---
+# Applies egress labels to worker nodes.
+#
+# Required variables:
+#
+#   cluster_inventory_group   the inventory group listing the nodes to be labeled
+#
+# For each node, we are looking for a dictionary called node_labels and apply
+# any labels specified in it to the corresponding node.
+#
+# Optional variables:
+#
+#   kubeadmin_config          the administrator kubeconfig file (tmp/kubeconfig-ocp4)
+#
+- name: Iterate over all the nodes in the inventory group
+  kubernetes.core.k8s:
+    kubeconfig: "{{ kubeadmin_config }}"
+    validate_certs: no
+    api_version: v1
+    kind: node
+    name: "{{ node }}"
+    template: templates/node-patch.yml
+  loop: "{{ groups[cluster_inventory_group] }}"
+  loop_control:
+    loop_var: node
+    label: "{{ node }}"
+  when:
+    - hostvars[node].node_labels is defined
+    - hostvars[node].node_labels.keys() | length > 0
+...

+ 8 - 0
p0f/operators/roles/apply-node-labels/templates/node-patch.yml

@@ -0,0 +1,8 @@
+apiVersion: v1
+kind: Node
+metadata:
+  name: {{ node }}
+  labels:
+{% for key in hostvars[node].node_labels.keys() %}
+    {{ key }}: "{{ hostvars[node].node_labels[key] }}"
+{% endfor %}