Repository: kumahq/kuma
Pull request #10661 (2024-06-27 12:34:00)

fix(cni): set proper namespace for the taint controller (backport of #10651)
Automatic cherry-pick of #10651 for branch release-2.7

Generated by [action](https://github.com/kumahq/kuma/actions/runs/9696633320)

cherry-picked commit 86da5abf1b787bd70a7247461d8c57a4c610cfb1


Patch:
diff --git a/deployments/charts/kuma/templates/_helpers.tpl b/deployments/charts/kuma/templates/_helpers.tpl
index 7715ce2d7..572d68075 100644
--- a/deployments/charts/kuma/templates/_helpers.tpl
+++ b/deployments/charts/kuma/templates/_helpers.tpl
@@ -274,6 +274,8 @@ env:
   value: "true"
 - name: KUMA_RUNTIME_KUBERNETES_NODE_TAINT_CONTROLLER_CNI_APP
   value: "{{ include "kuma.name" . }}-cni"
+- name: KUMA_RUNTIME_KUBERNETES_NODE_TAINT_CONTROLLER_CNI_NAMESPACE
+  value: {{ .Values.cni.namespace }}
 {{- end }}
 {{- if .Values.experimental.ebpf.enabled }}
 - name: KUMA_RUNTIME_KUBERNETES_INJECTOR_EBPF_ENABLED


Test patch:
diff --git a/app/kumactl/cmd/install/testdata/install-control-plane.cni-enabled.golden.yaml b/app/kumactl/cmd/install/testdata/install-control-plane.cni-enabled.golden.yaml
index b19692df5..27115143c 100644
--- a/app/kumactl/cmd/install/testdata/install-control-plane.cni-enabled.golden.yaml
+++ b/app/kumactl/cmd/install/testdata/install-control-plane.cni-enabled.golden.yaml
@@ -651,6 +651,8 @@ spec:
               value: "docker.io/kumahq/kuma-dp:0.0.1"
             - name: KUMA_RUNTIME_KUBERNETES_NODE_TAINT_CONTROLLER_CNI_APP
               value: "kuma-cni"
+            - name: KUMA_RUNTIME_KUBERNETES_NODE_TAINT_CONTROLLER_CNI_NAMESPACE
+              value: "kube-system"
             - name: KUMA_RUNTIME_KUBERNETES_NODE_TAINT_CONTROLLER_ENABLED
               value: "true"
             - name: KUMA_RUNTIME_KUBERNETES_SERVICE_ACCOUNT_NAME
diff --git a/app/kumactl/cmd/install/testdata/install-cp-helm/fix4935.golden.yaml b/app/kumactl/cmd/install/testdata/install-cp-helm/fix4935.golden.yaml
index 299f1699a..7c35f764f 100644
--- a/app/kumactl/cmd/install/testdata/install-cp-helm/fix4935.golden.yaml
+++ b/app/kumactl/cmd/install/testdata/install-cp-helm/fix4935.golden.yaml
@@ -727,6 +727,8 @@ spec:
               value: "docker.io/kumahq/kuma-dp:0.0.1"
             - name: KUMA_RUNTIME_KUBERNETES_NODE_TAINT_CONTROLLER_CNI_APP
               value: "kuma-cni"
+            - name: KUMA_RUNTIME_KUBERNETES_NODE_TAINT_CONTROLLER_CNI_NAMESPACE
+              value: "kube-system"
             - name: KUMA_RUNTIME_KUBERNETES_NODE_TAINT_CONTROLLER_ENABLED
               value: "true"
             - name: KUMA_RUNTIME_KUBERNETES_SERVICE_ACCOUNT_NAME
diff --git a/test/e2e/cni/taint_controller_race.go b/test/e2e/cni/taint_controller_race.go
index cefa9dedc..2c3fc039d 100644
--- a/test/e2e/cni/taint_controller_race.go
+++ b/test/e2e/cni/taint_controller_race.go
@@ -23,6 +23,7 @@ kind: Mesh
 metadata:
   name: default
 `
+	customNamespace := "cni-namespace"
 
 	var cluster Cluster
 	var k8sCluster *K8sCluster
@@ -41,6 +42,7 @@ metadata:
 			"kuma-%s",
 			strings.ToLower(random.UniqueId()),
 		)
+		Expect(NewClusterSetup().Install(Namespace(customNamespace)).Setup(cluster)).To(Succeed())
 
 		err := NewClusterSetup().
 			Install(Kuma(core.Zone,
@@ -48,7 +50,9 @@ metadata:
 				WithHelmReleaseName(releaseName),
 				WithSkipDefaultMesh(true), // it's common case for HELM deployments that Mesh is also managed by HELM therefore it's not created by default
 				WithHelmOpt("cni.delayStartupSeconds", "40"),
+				WithHelmOpt("cni.namespace", customNamespace),
 				WithCNI(),
+				WithCNINamespace(customNamespace),
 			)).
 			Install(YamlK8s(defaultMesh)).
 			Setup(cluster)
diff --git a/test/framework/interface.go b/test/framework/interface.go
index 370920614..4ccf2f54b 100644
--- a/test/framework/interface.go
+++ b/test/framework/interface.go
@@ -42,6 +42,7 @@ type kumaDeploymentOptions struct {
 	zoneEgress                  bool
 	zoneEgressEnvoyAdminTunnel  bool
 	cni                         bool
+	cniNamespace                string
 	cpReplicas                  int
 	hdsDisabled                 bool
 	runPostgresMigration        bool
@@ -320,6 +321,12 @@ func WithCNI() KumaDeploymentOption {
 	})
 }
 
+func WithCNINamespace(namespace string) KumaDeploymentOption {
+	return KumaOptionFunc(func(o *kumaDeploymentOptions) {
+		o.cniNamespace = namespace
+	})
+}
+
 func WithGlobalAddress(address string) KumaDeploymentOption {
 	return KumaOptionFunc(func(o *kumaDeploymentOptions) {
 		o.globalAddress = address
diff --git a/test/framework/k8s_cluster.go b/test/framework/k8s_cluster.go
index 36225f23f..c19213db8 100644
--- a/test/framework/k8s_cluster.go
+++ b/test/framework/k8s_cluster.go
@@ -517,7 +517,13 @@ func (c *K8sCluster) DeployKuma(mode core.CpMode, opt ...KumaDeploymentOption) e
 	var wg sync.WaitGroup
 	var appsToInstall []appInstallation
 	if c.opts.cni {
-		appsToInstall = append(appsToInstall, appInstallation{Config.CNIApp, Config.CNINamespace, 1, nil})
+		namespace := ""
+		if c.opts.cniNamespace != "" {
+			namespace = c.opts.cniNamespace
+		} else {
+			namespace = Config.CNINamespace
+		}
+		appsToInstall = append(appsToInstall, appInstallation{Config.CNIApp, namespace, 1, nil})
 	}
 	if c.opts.zoneIngress {
 		appsToInstall = append(appsToInstall, appInstallation{Config.ZoneIngressApp, Config.KumaNamespace, 1, nil})