From 58a95e6781c5f16e0453409c9e58c55d6aa41312 Mon Sep 17 00:00:00 2001 From: Jon Date: Sun, 19 Nov 2023 16:06:01 +0930 Subject: [PATCH] refactor(node_labels): removed from config.yaml and set to be a manifest on prime node this also removes the restriction of not being able to set `node-role` label. !10 nofusscomputing/infrastructure/configuration-management/project-production!4 --- tasks/k3s/configure.yaml | 21 +++++++++++++++++++++ templates/k3s-config.yaml.j2 | 12 +----------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/tasks/k3s/configure.yaml b/tasks/k3s/configure.yaml index d40075e..4a6718b 100644 --- a/tasks/k3s/configure.yaml +++ b/tasks/k3s/configure.yaml @@ -33,3 +33,24 @@ - src: iptables-kubernetes.rules.j2 dest: "/etc/iptables.rules.d/iptables-kubernetes.rules" notify: firewall_reloader + + +- name: Add Kubernetes Node Labels + ansible.builtin.copy: + content: |- + apiVersion: v1 + kind: Node + metadata: + name: "{{ inventory_hostname }}" + labels: + {{ item | to_nice_yaml | indent(4) }} + dest: /var/lib/rancher/k3s/server/manifests/node-manifest-{{ inventory_hostname }}.yaml + owner: root + group: root + mode: '700' + delegate_to: "{{ kubernetes_config.cluster.prime.name }}" + with_items: + - "{{ kubernetes_config.hosts[inventory_hostname].labels }}" + when: + - ( kubernetes_config.hosts[inventory_hostname].labels is defined and + kubernetes_config.hosts[inventory_hostname].labels|default('')|length > 0 ) diff --git a/templates/k3s-config.yaml.j2 b/templates/k3s-config.yaml.j2 index 3eb351a..9122726 100644 --- a/templates/k3s-config.yaml.j2 +++ b/templates/k3s-config.yaml.j2 @@ -20,6 +20,7 @@ cluster-init: true disable-network-policy: true disable: - traefik + - metrics-server etcd-snapshot-retention: {{ kubernetes_etcd_snapshot_retention | int }} etcd-snapshot-schedule-cron: "{{ kubernetes_etcd_snapshot_cron_schedule }}" flannel-backend: none @@ -41,17 +42,6 @@ kubelet-arg: - system-reserved=cpu={{ kubelet_arg_system_reserved_cpu }},memory={{ kubelet_arg_system_reserved_memory }},ephemeral-storage={{ kubelet_arg_system_reserved_storage }} {% if host_external_ip | default('') %}node-external-ip: "{{ host_external_ip }}"{% endif %} -{% if - kubernetes_config.hosts[inventory_hostname].labels is defined - and - kubernetes_config.hosts[inventory_hostname].labels | default([]) | list | length > 0 --%} -node-label: {%- for node_label in kubernetes_config.hosts[inventory_hostname].labels | dict2items +%} - - {{ node_label.key }}={{ node_label.value }} - -{%- endfor %} -{%- endif %} - {% if not Kubernetes_Prime | default(false) | bool -%} server: https://{{ hostvars[kubernetes_config.cluster.prime.name].ansible_host }}:6443 {%- endif %}