From dba00f2d85f782fea9bc4aae9b0c434df97ac959 Mon Sep 17 00:00:00 2001
From: Max Gautier <mg@max.gautier.name>
Date: Mon, 23 Sep 2024 15:30:48 +0200
Subject: [PATCH] metrics-server: Unconditional control-plane tolerations

There is no harm on having unneeded toleration when control-plane node
are not tainted, so simplify the template to always use the toleration.
---
 roles/kubernetes-apps/metrics_server/tasks/main.yml          | 5 -----
 .../templates/metrics-server-deployment.yaml.j2              | 4 ----
 2 files changed, 9 deletions(-)

diff --git a/roles/kubernetes-apps/metrics_server/tasks/main.yml b/roles/kubernetes-apps/metrics_server/tasks/main.yml
index 9c4e7cb7c..1a32fdab9 100644
--- a/roles/kubernetes-apps/metrics_server/tasks/main.yml
+++ b/roles/kubernetes-apps/metrics_server/tasks/main.yml
@@ -1,9 +1,4 @@
 ---
-# If all control plane nodes have the node role, there are no tainted control plane nodes and toleration should not be specified.
-- name: Check all control plane nodes are node or not
-  set_fact:
-    control_plane_nodes_are_not_tainted: "{{ groups['kube_node'] | intersect(groups['kube_control_plane']) == groups['kube_control_plane'] }}"
-
 - name: Metrics Server | Delete addon dir
   file:
     path: "{{ kube_config_dir }}/addons/metrics_server"
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 746af17ad..a7052f9be 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
@@ -85,15 +85,11 @@ spec:
       volumes:
         - name: tmp
           emptyDir: {}
-{% if not control_plane_nodes_are_not_tainted or metrics_server_extra_tolerations is defined %}
       tolerations:
-{% if not control_plane_nodes_are_not_tainted %}
         - 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 %}
 {% endif %}
       affinity:
         podAntiAffinity:
-- 
GitLab