diff --git a/controllers/classifier_deployer.go b/controllers/classifier_deployer.go index b1885dd..e614973 100644 --- a/controllers/classifier_deployer.go +++ b/controllers/classifier_deployer.go @@ -1682,12 +1682,13 @@ func prepareSveltosAgentYAML(agentYAML, clusterNamespace, clusterName, mode stri } func prepareSveltosApplierYAML(agentYAML, clusterNamespace, clusterName string, - clusterType libsveltosv1beta1.ClusterType) string { + clusterType libsveltosv1beta1.ClusterType, watchNamespaces []string) string { agentYAML = strings.ReplaceAll(agentYAML, "cluster-namespace=", fmt.Sprintf("cluster-namespace=%s", clusterNamespace)) agentYAML = strings.ReplaceAll(agentYAML, "cluster-name=", fmt.Sprintf("cluster-name=%s", clusterName)) agentYAML = strings.ReplaceAll(agentYAML, "cluster-type=", fmt.Sprintf("cluster-type=%s", clusterType)) agentYAML = strings.ReplaceAll(agentYAML, "secret-with-kubeconfig=", fmt.Sprintf("secret-with-kubeconfig=%s-sveltos-kubeconfig", clusterName)) + agentYAML = strings.ReplaceAll(agentYAML, "watch-namespaces=", fmt.Sprintf("watch-namespaces=%s", strings.Join(watchNamespaces, ","))) registry := getSveltosAgentRegistry() if registry != "" { @@ -1805,8 +1806,14 @@ func upgradeSveltosApplierInManagedCluster(ctx context.Context, clusterNamespace return err } + watchNamespaces, err := getAgentWatchNamespaces(ctx, getManagementClusterClient(), + clusterNamespace, clusterName, clusterType, logger) + if err != nil { + return err + } + agentYAML := string(agent.GetSveltosApplierAML()) - agentYAML = prepareSveltosApplierYAML(agentYAML, clusterNamespace, clusterName, clusterType) + agentYAML = prepareSveltosApplierYAML(agentYAML, clusterNamespace, clusterName, clusterType, watchNamespaces) return deploySveltosApplierResources(ctx, clusterNamespace, clusterName, classifierName, agentYAML, patches, logger) diff --git a/controllers/classifier_deployer_test.go b/controllers/classifier_deployer_test.go index 12c618f..8b9de20 100644 --- a/controllers/classifier_deployer_test.go +++ b/controllers/classifier_deployer_test.go @@ -498,6 +498,34 @@ var _ = Describe("Classifier Deployer", func() { ContainElement("--watch-namespaces=ns1,ns2")) }) + It("prepareSveltosApplierYAML relays watch-namespaces into the sveltos-applier manifest", func() { + agentYAML := `- --cluster-namespace= +- --cluster-name= +- --cluster-type= +- --secret-with-kubeconfig= +- --watch-namespaces=` + + clusterNamespace := randomString() + clusterName := randomString() + watchNamespaces := []string{watchNamespaceNs1, watchNamespaceNs2} + + result := controllers.PrepareSveltosApplierYAML(agentYAML, clusterNamespace, clusterName, + libsveltosv1beta1.ClusterTypeCapi, watchNamespaces) + + Expect(result).To(ContainSubstring("--watch-namespaces=ns1,ns2")) + Expect(result).To(ContainSubstring(fmt.Sprintf("--cluster-namespace=%s", clusterNamespace))) + Expect(result).To(ContainSubstring(fmt.Sprintf("--cluster-name=%s", clusterName))) + }) + + It("prepareSveltosApplierYAML leaves watch-namespaces empty when no namespaces are configured", func() { + agentYAML := `- --watch-namespaces=` + + result := controllers.PrepareSveltosApplierYAML(agentYAML, randomString(), randomString(), + libsveltosv1beta1.ClusterTypeCapi, nil) + + Expect(result).To(Equal(agentYAML)) + }) + It("createAccessRequest creates AccessRequest instance", func() { classifier := getClassifierInstance(randomString()) diff --git a/controllers/export_test.go b/controllers/export_test.go index cc6d08d..1b358b4 100644 --- a/controllers/export_test.go +++ b/controllers/export_test.go @@ -50,6 +50,7 @@ var ( DeployDebuggingConfigurationCRD = deployDebuggingConfigurationCRD DeployClassifierInstance = deployClassifierInstance DeploySveltosAgentInManagedCluster = deploySveltosAgentInManagedCluster + PrepareSveltosApplierYAML = prepareSveltosApplierYAML ClassifierHash = classifierHash DeployClassifierInCluster = deployClassifierInCluster UndeployClassifierFromCluster = undeployClassifierFromCluster diff --git a/pkg/agent/sveltos-applier.go b/pkg/agent/sveltos-applier.go index d3f0c90..a5ef1a7 100644 --- a/pkg/agent/sveltos-applier.go +++ b/pkg/agent/sveltos-applier.go @@ -100,6 +100,7 @@ spec: - --cluster-name= - --cluster-type= - --secret-with-kubeconfig= + - --watch-namespaces= - --v=5 - --version=main command: @@ -117,7 +118,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - image: docker.io/projectsveltos/sveltos-applier@sha256:747f74958b935737a023e10871c7b97b81eb2c3c96cebeee5b3d679410de625d + image: docker.io/projectsveltos/sveltos-applier@sha256:6bea4f06b8d1d3fa988b018045727c715fce63d3d46b143e6b392aefc062e828 livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/agent/sveltos-applier.yaml b/pkg/agent/sveltos-applier.yaml index 9dc2809..e9e143d 100644 --- a/pkg/agent/sveltos-applier.yaml +++ b/pkg/agent/sveltos-applier.yaml @@ -82,6 +82,7 @@ spec: - --cluster-name= - --cluster-type= - --secret-with-kubeconfig= + - --watch-namespaces= - --v=5 - --version=main command: @@ -99,7 +100,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - image: docker.io/projectsveltos/sveltos-applier@sha256:747f74958b935737a023e10871c7b97b81eb2c3c96cebeee5b3d679410de625d + image: docker.io/projectsveltos/sveltos-applier@sha256:6bea4f06b8d1d3fa988b018045727c715fce63d3d46b143e6b392aefc062e828 livenessProbe: failureThreshold: 3 httpGet: diff --git a/test/pullmode-sveltosapplier.yaml b/test/pullmode-sveltosapplier.yaml index 4650780..aa61488 100644 --- a/test/pullmode-sveltosapplier.yaml +++ b/test/pullmode-sveltosapplier.yaml @@ -82,6 +82,7 @@ spec: - --cluster-name=clusterapi-workload - --cluster-type=sveltos - --secret-with-kubeconfig=clusterapi-workload-sveltos-kubeconfig + - --watch-namespaces= - --v=5 - --version=main command: @@ -99,7 +100,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - image: docker.io/projectsveltos/sveltos-applier@sha256:747f74958b935737a023e10871c7b97b81eb2c3c96cebeee5b3d679410de625d + image: docker.io/projectsveltos/sveltos-applier@sha256:6bea4f06b8d1d3fa988b018045727c715fce63d3d46b143e6b392aefc062e828 livenessProbe: failureThreshold: 3 httpGet: