From d2a744ed058a65d1caa7679cba1b138a940976fe Mon Sep 17 00:00:00 2001 From: pli01 Date: Tue, 11 Apr 2023 23:09:10 +0200 Subject: [PATCH 1/2] metrics_server: add extras nodeselector, affinity, tolerations --- .../kubernetes-apps/metrics_server/defaults/main.yml | 3 +++ .../templates/metrics-server-deployment.yaml.j2 | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/roles/kubernetes-apps/metrics_server/defaults/main.yml b/roles/kubernetes-apps/metrics_server/defaults/main.yml index 548cf0ee826..993eed6c1ea 100644 --- a/roles/kubernetes-apps/metrics_server/defaults/main.yml +++ b/roles/kubernetes-apps/metrics_server/defaults/main.yml @@ -9,3 +9,6 @@ metrics_server_requests_cpu: 100m metrics_server_requests_memory: 200Mi metrics_server_host_network: false metrics_server_replicas: 1 +# metrics_server_extra_tolerations: [] +# metrics_server_extra_affinity: {} +# metrics_server_nodeselector: {} diff --git a/roles/kubernetes-apps/metrics_server/templates/metrics-server-deployment.yaml.j2 b/roles/kubernetes-apps/metrics_server/templates/metrics-server-deployment.yaml.j2 index d44dc8f5e43..a38125752e7 100644 --- a/roles/kubernetes-apps/metrics_server/templates/metrics-server-deployment.yaml.j2 +++ b/roles/kubernetes-apps/metrics_server/templates/metrics-server-deployment.yaml.j2 @@ -84,12 +84,15 @@ spec: volumes: - name: tmp emptyDir: {} -{% if not masters_are_not_tainted %} tolerations: +{% if not masters_are_not_tainted %} - key: node-role.kubernetes.io/master effect: NoSchedule - key: node-role.kubernetes.io/control-plane effect: NoSchedule +{% endif %} +{% if metrics_server_extra_tolerations is defined %} + {{ metrics_server_extra_tolerations | list | to_nice_yaml(indent=2) | indent(8) }} {% endif %} affinity: podAntiAffinity: @@ -105,3 +108,10 @@ spec: topologyKey: kubernetes.io/hostname namespaces: - kube-system +{% if metrics_server_extra_affinity is defined %} + {{ metrics_server_extra_affinity | to_nice_yaml | indent(width=8) }} +{% endif %} +{% if metrics_server_nodeselector %} + nodeSelector: + {{ metrics_server_nodeselector | to_nice_yaml | indent(width=8) }} +{% endif %} From ec8df4eed62c811609c7e3a0a204060a87ce5b6f Mon Sep 17 00:00:00 2001 From: pli01 Date: Fri, 14 Apr 2023 13:43:37 +0200 Subject: [PATCH 2/2] fix tolerations invalid YAML if undefined --- .../templates/metrics-server-deployment.yaml.j2 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/roles/kubernetes-apps/metrics_server/templates/metrics-server-deployment.yaml.j2 b/roles/kubernetes-apps/metrics_server/templates/metrics-server-deployment.yaml.j2 index a38125752e7..686cde0fc23 100644 --- a/roles/kubernetes-apps/metrics_server/templates/metrics-server-deployment.yaml.j2 +++ b/roles/kubernetes-apps/metrics_server/templates/metrics-server-deployment.yaml.j2 @@ -84,6 +84,7 @@ spec: volumes: - name: tmp emptyDir: {} +{% if not masters_are_not_tainted or metrics_server_extra_tolerations is defined %} tolerations: {% if not masters_are_not_tainted %} - key: node-role.kubernetes.io/master @@ -93,6 +94,7 @@ spec: {% endif %} {% if metrics_server_extra_tolerations is defined %} {{ metrics_server_extra_tolerations | list | to_nice_yaml(indent=2) | indent(8) }} +{% endif %} {% endif %} affinity: podAntiAffinity: @@ -111,7 +113,7 @@ spec: {% if metrics_server_extra_affinity is defined %} {{ metrics_server_extra_affinity | to_nice_yaml | indent(width=8) }} {% endif %} -{% if metrics_server_nodeselector %} +{% if metrics_server_nodeselector is defined %} nodeSelector: {{ metrics_server_nodeselector | to_nice_yaml | indent(width=8) }} {% endif %}