Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions controllers/classifier_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions controllers/classifier_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down
1 change: 1 addition & 0 deletions controllers/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ var (
DeployDebuggingConfigurationCRD = deployDebuggingConfigurationCRD
DeployClassifierInstance = deployClassifierInstance
DeploySveltosAgentInManagedCluster = deploySveltosAgentInManagedCluster
PrepareSveltosApplierYAML = prepareSveltosApplierYAML
ClassifierHash = classifierHash
DeployClassifierInCluster = deployClassifierInCluster
UndeployClassifierFromCluster = undeployClassifierFromCluster
Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/sveltos-applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ spec:
- --cluster-name=
- --cluster-type=
- --secret-with-kubeconfig=
- --watch-namespaces=
- --v=5
- --version=main
command:
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion pkg/agent/sveltos-applier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ spec:
- --cluster-name=
- --cluster-type=
- --secret-with-kubeconfig=
- --watch-namespaces=
- --v=5
- --version=main
command:
Expand All @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion test/pullmode-sveltosapplier.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
Loading