From 2b63e5519f0b8796ebb96991af64db309f0445e5 Mon Sep 17 00:00:00 2001 From: Gianluca Mardente Date: Sat, 18 Apr 2026 17:47:12 +0200 Subject: [PATCH] (bug) advance drift-detection-manager This picks a fix in drift-detection-manager making sure Sveltos detects and fixes configuration drift for resources deployed by Sveltos because of KustomizationRefs. This PR also adds a tests that verifies this scenario: 1. Flux is deployed by Sveltos in the management cluster 2. A GitRepository is created 3. A second ClusterProfile references the GitRepository in the KustomizationRefs section 4. Test verifies resources are correctly deployed 5. One of those resources is deleted by pointing directly to the managed cluster 6. Test verifies resource is recreated --- Makefile | 2 +- cmd/main.go | 2 +- config/default/manager_auth_proxy_patch.yaml | 2 +- config/default/manager_image_patch.yaml | 4 +- go.mod | 16 +- go.sum | 32 +-- hack/tools/go.mod | 6 +- hack/tools/go.sum | 12 +- manifest/deployment-agentless.yaml | 6 +- manifest/deployment-shard.yaml | 6 +- manifest/manifest.yaml | 6 +- ...drift-detection-manager-in-mgmt-cluster.go | 4 +- ...ift-detection-manager-in-mgmt-cluster.yaml | 4 +- .../drift-detection-manager.go | 4 +- .../drift-detection-manager.yaml | 4 +- test/fv/fv_suite_test.go | 2 + test/fv/kustomize_test.go | 201 ++++++++++++++---- test/pullmode-sveltosapplier.yaml | 2 +- 18 files changed, 220 insertions(+), 95 deletions(-) diff --git a/Makefile b/Makefile index 41b3707e..578dc9a9 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ OS ?= $(shell uname -s) OS := $(shell echo $(OS) | tr '[:upper:]' '[:lower:]') K8S_LATEST_VER ?= $(shell curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt) export CONTROLLER_IMG ?= $(REGISTRY)/$(IMAGE_NAME) -TAG ?= v1.8.0 +TAG ?= main .PHONY: all all: build diff --git a/cmd/main.go b/cmd/main.go index 2e4c0348..cee551bc 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -374,7 +374,7 @@ func fluxCRDHandler(gvk *schema.GroupVersionKind, action crd.ChangeType) { return } - if gvk.Group == sourcev1.GroupVersion.Group { + if gvk.Group == sourcev1.GroupVersion.Group && gvk.Kind == sourcev1.GitRepositoryKind { setupLog.V(logs.LogInfo).Info("Initiating graceful restart due to Flux CRD update", "GVK", gvk.String(), "Action", string(action)) diff --git a/config/default/manager_auth_proxy_patch.yaml b/config/default/manager_auth_proxy_patch.yaml index b2aa7d92..c5b2205e 100644 --- a/config/default/manager_auth_proxy_patch.yaml +++ b/config/default/manager_auth_proxy_patch.yaml @@ -22,7 +22,7 @@ spec: - --shard-key= - --capi-onboard-annotation= - "--v=5" - - "--version=v1.8.0" + - "--version=main" - "--agent-in-mgmt-cluster=false" env: - name: GOMEMLIMIT diff --git a/config/default/manager_image_patch.yaml b/config/default/manager_image_patch.yaml index b8248b53..22ae3140 100644 --- a/config/default/manager_image_patch.yaml +++ b/config/default/manager_image_patch.yaml @@ -7,8 +7,8 @@ spec: template: spec: initContainers: - - image: docker.io/projectsveltos/addon-controller:v1.8.0 + - image: docker.io/projectsveltos/addon-controller:main name: initialization containers: - - image: docker.io/projectsveltos/addon-controller:v1.8.0 + - image: docker.io/projectsveltos/addon-controller:main name: controller diff --git a/go.mod b/go.mod index 635d7310..f4389d4e 100644 --- a/go.mod +++ b/go.mod @@ -9,8 +9,8 @@ require ( github.com/dariubs/percent v1.0.0 github.com/docker/cli v29.4.0+incompatible github.com/fluxcd/pkg/apis/meta v1.26.0 - github.com/fluxcd/pkg/http/fetch v0.22.0 - github.com/fluxcd/pkg/tar v0.17.0 + github.com/fluxcd/pkg/http/fetch v0.24.0 + github.com/fluxcd/pkg/tar v1.1.0 github.com/fluxcd/source-controller/api v1.8.2 github.com/gdexlab/go-render v1.0.1 github.com/go-logr/logr v1.4.3 @@ -25,12 +25,12 @@ require ( github.com/yuin/gopher-lua v1.1.2 golang.org/x/text v0.36.0 helm.sh/helm/v4 v4.1.4 - k8s.io/api v0.35.3 - k8s.io/apiextensions-apiserver v0.35.3 - k8s.io/apimachinery v0.35.3 + k8s.io/api v0.35.4 + k8s.io/apiextensions-apiserver v0.35.4 + k8s.io/apimachinery v0.35.4 k8s.io/cli-runtime v0.35.3 - k8s.io/client-go v0.35.3 - k8s.io/component-base v0.35.3 + k8s.io/client-go v0.35.4 + k8s.io/component-base v0.35.4 k8s.io/klog/v2 v2.140.0 k8s.io/utils v0.0.0-20260319190234-28399d86e0b5 sigs.k8s.io/cluster-api v1.12.5 @@ -171,7 +171,7 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect gotest.tools/v3 v3.4.0 // indirect - k8s.io/apiserver v0.35.3 // indirect + k8s.io/apiserver v0.35.4 // indirect k8s.io/cluster-bootstrap v0.34.2 // indirect k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect k8s.io/kubectl v0.35.1 // indirect diff --git a/go.sum b/go.sum index 284181a1..1c4f73cf 100644 --- a/go.sum +++ b/go.sum @@ -100,10 +100,10 @@ github.com/fluxcd/pkg/apis/acl v0.9.0 h1:wBpgsKT+jcyZEcM//OmZr9RiF8klL3ebrDp2u2T github.com/fluxcd/pkg/apis/acl v0.9.0/go.mod h1:TttNS+gocsGLwnvmgVi3/Yscwqrjc17+vhgYfqkfrV4= github.com/fluxcd/pkg/apis/meta v1.26.0 h1:dxP1FfBpTCYso6odzRcltVnnRuBb2VyhhgV0VX9YbUE= github.com/fluxcd/pkg/apis/meta v1.26.0/go.mod h1:c7o6mJGLCMvNrfdinGZehkrdZuFT9vZdZNrn66DtVD0= -github.com/fluxcd/pkg/http/fetch v0.22.0 h1:FT8CfstPE/e7+KRxNrx8ZJ1Uj5rkR5wXOtvQJurNQ0U= -github.com/fluxcd/pkg/http/fetch v0.22.0/go.mod h1:X+8wF3peP79TyyDSgCJiavz+fAcYaf7CRXSeu7ccsPA= -github.com/fluxcd/pkg/tar v0.17.0 h1:uNxbFXy8ly8C7fJ8D7w3rjTNJFrb4Hp1aY/30XkfvxY= -github.com/fluxcd/pkg/tar v0.17.0/go.mod h1:b1xyIRYDD0ket4SV5u0UXYv+ZdN/O/HmIO5jZQdHQls= +github.com/fluxcd/pkg/http/fetch v0.24.0 h1:helmjE86zZG6UTcWDV0IxkKpDKWh96FKeGDSz+W1ZcM= +github.com/fluxcd/pkg/http/fetch v0.24.0/go.mod h1:4gGHbadYT5PpVELFfzPx+3FrXSJupcTxu4qciYsFZas= +github.com/fluxcd/pkg/tar v1.1.0 h1:BQWTQtoJCbqbAjtWp7lNCjRfP+/jYL6xFW5/ik5fAZ0= +github.com/fluxcd/pkg/tar v1.1.0/go.mod h1:b1xyIRYDD0ket4SV5u0UXYv+ZdN/O/HmIO5jZQdHQls= github.com/fluxcd/pkg/testserver v0.13.0 h1:xEpBcEYtD7bwvZ+i0ZmChxKkDo/wfQEV3xmnzVybSSg= github.com/fluxcd/pkg/testserver v0.13.0/go.mod h1:akRYv3FLQUsme15na9ihECRG6hBuqni4XEY9W8kzs8E= github.com/fluxcd/source-controller/api v1.8.2 h1:i0/6BeNCn+zRfX+gKh4PsFF2NBzBhwXt0wPImVlZObg= @@ -500,22 +500,22 @@ gotest.tools/v3 v3.4.0 h1:ZazjZUfuVeZGLAmlKKuyv3IKP5orXcwtOwDQH6YVr6o= gotest.tools/v3 v3.4.0/go.mod h1:CtbdzLSsqVhDgMtKsx03ird5YTGB3ar27v0u/yKBW5g= helm.sh/helm/v4 v4.1.4 h1:zwTrNkalG4f7SYigRSdQnYrTj0QEz1qzetzAlYoDVSo= helm.sh/helm/v4 v4.1.4/go.mod h1:5dSo8rRgn3OTkDAc/k0Ipw5/Q+BlqKIKZwa0XwSiINI= -k8s.io/api v0.35.3 h1:pA2fiBc6+N9PDf7SAiluKGEBuScsTzd2uYBkA5RzNWQ= -k8s.io/api v0.35.3/go.mod h1:9Y9tkBcFwKNq2sxwZTQh1Njh9qHl81D0As56tu42GA4= -k8s.io/apiextensions-apiserver v0.35.3 h1:2fQUhEO7P17sijylbdwt0nBdXP0TvHrHj0KeqHD8FiU= -k8s.io/apiextensions-apiserver v0.35.3/go.mod h1:tK4Kz58ykRpwAEkXUb634HD1ZAegEElktz/B3jgETd8= -k8s.io/apimachinery v0.35.3 h1:MeaUwQCV3tjKP4bcwWGgZ/cp/vpsRnQzqO6J6tJyoF8= -k8s.io/apimachinery v0.35.3/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns= -k8s.io/apiserver v0.35.3 h1:D2eIcfJ05hEAEewoSDg+05e0aSRwx8Y4Agvd/wiomUI= -k8s.io/apiserver v0.35.3/go.mod h1:JI0n9bHYzSgIxgIrfe21dbduJ9NHzKJ6RchcsmIKWKY= +k8s.io/api v0.35.4 h1:P7nFYKl5vo9AGUp1Z+Pmd3p2tA7bX2wbFWCvDeRv988= +k8s.io/api v0.35.4/go.mod h1:yl4lqySWOgYJJf9RERXKUwE9g2y+CkuwG+xmcOK8wXU= +k8s.io/apiextensions-apiserver v0.35.4 h1:HeP+Upp7ItdvnyGmub0yoix+2z5+ev4M5cE5TCgtOUU= +k8s.io/apiextensions-apiserver v0.35.4/go.mod h1:ogQlk+stIE8mnoRthSYCwlOS12fVqgWFiErMwPaXA7c= +k8s.io/apimachinery v0.35.4 h1:xtdom9RG7e+yDp71uoXoJDWEE2eOiHgeO4GdBzwWpds= +k8s.io/apimachinery v0.35.4/go.mod h1:NNi1taPOpep0jOj+oRha3mBJPqvi0hGdaV8TCqGQ+cc= +k8s.io/apiserver v0.35.4 h1:vtuFqNFmF9bPRdHDL2lpK6qCTPWDreZJL4LRPwVM6ho= +k8s.io/apiserver v0.35.4/go.mod h1:JnBcb+J8kFXKpZkgcbcUnPBBHi4qgBii1I7dLxFY/oo= k8s.io/cli-runtime v0.35.3 h1:UZq4ipNimtzBmhN7PPKbfAdqo8quK0H0UdGl6qAQnqI= k8s.io/cli-runtime v0.35.3/go.mod h1:O7MUmCqcKSd5xI+O5X7/pRkB5l0O2NIhOdUVwbHLXu4= -k8s.io/client-go v0.35.3 h1:s1lZbpN4uI6IxeTM2cpdtrwHcSOBML1ODNTCCfsP1pg= -k8s.io/client-go v0.35.3/go.mod h1:RzoXkc0mzpWIDvBrRnD+VlfXP+lRzqQjCmKtiwZ8Q9c= +k8s.io/client-go v0.35.4 h1:DN6fyaGuzK64UvnKO5fOA6ymSjvfGAnCAHAR0C66kD8= +k8s.io/client-go v0.35.4/go.mod h1:2Pg9WpsS4NeOpoYTfHHfMxBG8zFMSAUi4O/qoiJC3nY= k8s.io/cluster-bootstrap v0.34.2 h1:oKckPeunVCns37BntcsxaOesDul32yzGd3DFLjW2fc8= k8s.io/cluster-bootstrap v0.34.2/go.mod h1:f21byPR7X5nt12ivZi+J3pb4sG4SH6VySX8KAAJA8BY= -k8s.io/component-base v0.35.3 h1:mbKbzoIMy7JDWS/wqZobYW1JDVRn/RKRaoMQHP9c4P0= -k8s.io/component-base v0.35.3/go.mod h1:IZ8LEG30kPN4Et5NeC7vjNv5aU73ku5MS15iZyvyMYk= +k8s.io/component-base v0.35.4 h1:6n1tNJ87johN0Hif0Fs8K2GMthsaUwMqCebUDLYyv7U= +k8s.io/component-base v0.35.4/go.mod h1:qaDJgz5c1KYKla9occFmlJEfPpkuA55s90G509R+PeY= k8s.io/klog/v2 v2.140.0 h1:Tf+J3AH7xnUzZyVVXhTgGhEKnFqye14aadWv7bzXdzc= k8s.io/klog/v2 v2.140.0/go.mod h1:o+/RWfJ6PwpnFn7OyAG3QnO47BFsymfEfrz6XyYSSp0= k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 h1:Y3gxNAuB0OBLImH611+UDZcmKS3g6CthxToOb37KgwE= diff --git a/hack/tools/go.mod b/hack/tools/go.mod index 16924139..cb2c8ea4 100644 --- a/hack/tools/go.mod +++ b/hack/tools/go.mod @@ -7,7 +7,7 @@ require ( github.com/onsi/ginkgo/v2 v2.28.1 golang.org/x/oauth2 v0.36.0 golang.org/x/tools v0.44.0 - k8s.io/client-go v0.35.3 + k8s.io/client-go v0.35.4 sigs.k8s.io/controller-tools v0.20.1 sigs.k8s.io/kind v0.31.0 ) @@ -57,9 +57,9 @@ require ( gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect - k8s.io/api v0.35.3 // indirect + k8s.io/api v0.35.4 // indirect k8s.io/apiextensions-apiserver v0.35.0 // indirect - k8s.io/apimachinery v0.35.3 // indirect + k8s.io/apimachinery v0.35.4 // indirect k8s.io/code-generator v0.35.0 // indirect k8s.io/gengo/v2 v2.0.0-20250922181213-ec3ebc5fd46b // indirect k8s.io/klog/v2 v2.130.1 // indirect diff --git a/hack/tools/go.sum b/hack/tools/go.sum index 7cd8d908..8f4c389c 100644 --- a/hack/tools/go.sum +++ b/hack/tools/go.sum @@ -236,16 +236,16 @@ gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -k8s.io/api v0.35.3 h1:pA2fiBc6+N9PDf7SAiluKGEBuScsTzd2uYBkA5RzNWQ= -k8s.io/api v0.35.3/go.mod h1:9Y9tkBcFwKNq2sxwZTQh1Njh9qHl81D0As56tu42GA4= +k8s.io/api v0.35.4 h1:P7nFYKl5vo9AGUp1Z+Pmd3p2tA7bX2wbFWCvDeRv988= +k8s.io/api v0.35.4/go.mod h1:yl4lqySWOgYJJf9RERXKUwE9g2y+CkuwG+xmcOK8wXU= k8s.io/apiextensions-apiserver v0.35.0 h1:3xHk2rTOdWXXJM+RDQZJvdx0yEOgC0FgQ1PlJatA5T4= k8s.io/apiextensions-apiserver v0.35.0/go.mod h1:E1Ahk9SADaLQ4qtzYFkwUqusXTcaV2uw3l14aqpL2LU= -k8s.io/apimachinery v0.35.3 h1:MeaUwQCV3tjKP4bcwWGgZ/cp/vpsRnQzqO6J6tJyoF8= -k8s.io/apimachinery v0.35.3/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns= +k8s.io/apimachinery v0.35.4 h1:xtdom9RG7e+yDp71uoXoJDWEE2eOiHgeO4GdBzwWpds= +k8s.io/apimachinery v0.35.4/go.mod h1:NNi1taPOpep0jOj+oRha3mBJPqvi0hGdaV8TCqGQ+cc= k8s.io/apiserver v0.35.0 h1:CUGo5o+7hW9GcAEF3x3usT3fX4f9r8xmgQeCBDaOgX4= k8s.io/apiserver v0.35.0/go.mod h1:QUy1U4+PrzbJaM3XGu2tQ7U9A4udRRo5cyxkFX0GEds= -k8s.io/client-go v0.35.3 h1:s1lZbpN4uI6IxeTM2cpdtrwHcSOBML1ODNTCCfsP1pg= -k8s.io/client-go v0.35.3/go.mod h1:RzoXkc0mzpWIDvBrRnD+VlfXP+lRzqQjCmKtiwZ8Q9c= +k8s.io/client-go v0.35.4 h1:DN6fyaGuzK64UvnKO5fOA6ymSjvfGAnCAHAR0C66kD8= +k8s.io/client-go v0.35.4/go.mod h1:2Pg9WpsS4NeOpoYTfHHfMxBG8zFMSAUi4O/qoiJC3nY= k8s.io/code-generator v0.35.0 h1:TvrtfKYZTm9oDF2z+veFKSCcgZE3Igv0svY+ehCmjHQ= k8s.io/code-generator v0.35.0/go.mod h1:iS1gvVf3c/T71N5DOGYO+Gt3PdJ6B9LYSvIyQ4FHzgc= k8s.io/component-base v0.35.0 h1:+yBrOhzri2S1BVqyVSvcM3PtPyx5GUxCK2tinZz1G94= diff --git a/manifest/deployment-agentless.yaml b/manifest/deployment-agentless.yaml index 9dd41ba6..58ed7753 100644 --- a/manifest/deployment-agentless.yaml +++ b/manifest/deployment-agentless.yaml @@ -26,7 +26,7 @@ spec: - --shard-key= - --capi-onboard-annotation= - --v=5 - - --version=v1.8.0 + - --version=main - --agent-in-mgmt-cluster=true command: - /manager @@ -39,7 +39,7 @@ spec: valueFrom: resourceFieldRef: resource: limits.cpu - image: docker.io/projectsveltos/addon-controller:v1.8.0 + image: docker.io/projectsveltos/addon-controller:main livenessProbe: failureThreshold: 3 httpGet: @@ -85,7 +85,7 @@ spec: env: - name: IS_INITIALIZATION value: "true" - image: docker.io/projectsveltos/addon-controller:v1.8.0 + image: docker.io/projectsveltos/addon-controller:main name: initialization securityContext: allowPrivilegeEscalation: false diff --git a/manifest/deployment-shard.yaml b/manifest/deployment-shard.yaml index b15ff683..80bdb3f8 100644 --- a/manifest/deployment-shard.yaml +++ b/manifest/deployment-shard.yaml @@ -26,7 +26,7 @@ spec: - --shard-key={{.SHARD}} - --capi-onboard-annotation= - --v=5 - - --version=v1.8.0 + - --version=main - --agent-in-mgmt-cluster=false command: - /manager @@ -39,7 +39,7 @@ spec: valueFrom: resourceFieldRef: resource: limits.cpu - image: docker.io/projectsveltos/addon-controller:v1.8.0 + image: docker.io/projectsveltos/addon-controller:main livenessProbe: failureThreshold: 3 httpGet: @@ -85,7 +85,7 @@ spec: env: - name: IS_INITIALIZATION value: "true" - image: docker.io/projectsveltos/addon-controller:v1.8.0 + image: docker.io/projectsveltos/addon-controller:main name: initialization securityContext: allowPrivilegeEscalation: false diff --git a/manifest/manifest.yaml b/manifest/manifest.yaml index cb04db89..713758a8 100644 --- a/manifest/manifest.yaml +++ b/manifest/manifest.yaml @@ -8552,7 +8552,7 @@ spec: - --shard-key= - --capi-onboard-annotation= - --v=5 - - --version=v1.8.0 + - --version=main - --agent-in-mgmt-cluster=false command: - /manager @@ -8565,7 +8565,7 @@ spec: valueFrom: resourceFieldRef: resource: limits.cpu - image: docker.io/projectsveltos/addon-controller:v1.8.0 + image: docker.io/projectsveltos/addon-controller:main livenessProbe: failureThreshold: 3 httpGet: @@ -8611,7 +8611,7 @@ spec: env: - name: IS_INITIALIZATION value: "true" - image: docker.io/projectsveltos/addon-controller:v1.8.0 + image: docker.io/projectsveltos/addon-controller:main name: initialization securityContext: allowPrivilegeEscalation: false diff --git a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go index 345cd2a3..6af5e104 100644 --- a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go +++ b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.go @@ -44,10 +44,10 @@ spec: - --cluster-type= - --current-cluster=management-cluster - --run-mode=do-not-send-updates - - --version=v1.8.0 + - --version=main command: - /manager - image: docker.io/projectsveltos/drift-detection-manager@sha256:f9eee6977f395325fcd400b97e8b0c5ad51f024add207a5f08dcf27f42842df7 + image: docker.io/projectsveltos/drift-detection-manager@sha256:8bb5b9ba6ed65d1cc986e1ed75ea85817a5f94438a0dbf2b0592a3df4d926adf livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml index ca38aa66..b216222a 100644 --- a/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml +++ b/pkg/drift-detection/drift-detection-manager-in-mgmt-cluster.yaml @@ -26,10 +26,10 @@ spec: - --cluster-type= - --current-cluster=management-cluster - --run-mode=do-not-send-updates - - --version=v1.8.0 + - --version=main command: - /manager - image: docker.io/projectsveltos/drift-detection-manager@sha256:f9eee6977f395325fcd400b97e8b0c5ad51f024add207a5f08dcf27f42842df7 + image: docker.io/projectsveltos/drift-detection-manager@sha256:8bb5b9ba6ed65d1cc986e1ed75ea85817a5f94438a0dbf2b0592a3df4d926adf livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager.go b/pkg/drift-detection/drift-detection-manager.go index 0bec14a1..7ee40fba 100644 --- a/pkg/drift-detection/drift-detection-manager.go +++ b/pkg/drift-detection/drift-detection-manager.go @@ -146,7 +146,7 @@ spec: - --cluster-type= - --current-cluster=managed-cluster - --run-mode=do-not-send-updates - - --version=v1.8.0 + - --version=main command: - /manager env: @@ -158,7 +158,7 @@ spec: valueFrom: resourceFieldRef: resource: limits.cpu - image: docker.io/projectsveltos/drift-detection-manager@sha256:f9eee6977f395325fcd400b97e8b0c5ad51f024add207a5f08dcf27f42842df7 + image: docker.io/projectsveltos/drift-detection-manager@sha256:8bb5b9ba6ed65d1cc986e1ed75ea85817a5f94438a0dbf2b0592a3df4d926adf livenessProbe: failureThreshold: 3 httpGet: diff --git a/pkg/drift-detection/drift-detection-manager.yaml b/pkg/drift-detection/drift-detection-manager.yaml index acf3bf4a..f28fcf1c 100644 --- a/pkg/drift-detection/drift-detection-manager.yaml +++ b/pkg/drift-detection/drift-detection-manager.yaml @@ -128,7 +128,7 @@ spec: - --cluster-type= - --current-cluster=managed-cluster - --run-mode=do-not-send-updates - - --version=v1.8.0 + - --version=main command: - /manager env: @@ -140,7 +140,7 @@ spec: valueFrom: resourceFieldRef: resource: limits.cpu - image: docker.io/projectsveltos/drift-detection-manager@sha256:f9eee6977f395325fcd400b97e8b0c5ad51f024add207a5f08dcf27f42842df7 + image: docker.io/projectsveltos/drift-detection-manager@sha256:8bb5b9ba6ed65d1cc986e1ed75ea85817a5f94438a0dbf2b0592a3df4d926adf livenessProbe: failureThreshold: 3 httpGet: diff --git a/test/fv/fv_suite_test.go b/test/fv/fv_suite_test.go index 735a5fc9..9385deb6 100644 --- a/test/fv/fv_suite_test.go +++ b/test/fv/fv_suite_test.go @@ -28,6 +28,7 @@ import ( "github.com/TwiN/go-color" sourcev1 "github.com/fluxcd/source-controller/api/v1" ginkgotypes "github.com/onsi/ginkgo/v2/types" + networkingv1 "k8s.io/api/networking/v1" apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" @@ -96,6 +97,7 @@ var _ = BeforeSuite(func() { Expect(configv1beta1.AddToScheme(scheme)).To(Succeed()) Expect(sourcev1.AddToScheme(scheme)).To(Succeed()) Expect(apiextensionsv1.AddToScheme(scheme)).To(Succeed()) + Expect(networkingv1.AddToScheme(scheme)).To(Succeed()) var err error k8sClient, err = client.New(restConfig, client.Options{Scheme: scheme}) diff --git a/test/fv/kustomize_test.go b/test/fv/kustomize_test.go index 2a7b8cfa..c132e74e 100644 --- a/test/fv/kustomize_test.go +++ b/test/fv/kustomize_test.go @@ -18,6 +18,7 @@ package fv_test import ( "context" + "time" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -25,54 +26,70 @@ import ( sourcev1 "github.com/fluxcd/source-controller/api/v1" appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" + networkingv1 "k8s.io/api/networking/v1" apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" "k8s.io/client-go/util/retry" + "sigs.k8s.io/controller-runtime/pkg/client" configv1beta1 "github.com/projectsveltos/addon-controller/api/v1beta1" "github.com/projectsveltos/addon-controller/lib/clusterops" libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" ) -/* -* This test assumes Flux is installed and GitRepoistory flux-system/flux-system is referencing -* main branch of ssh://git@github.com/gianlucam76/kustomize -* This test is not run as part of CI. - */ var _ = Describe("Kustomize with GitRepository", func() { const ( - namePrefix = "kustomize-" + namePrefix = "kustomize-" + mgmt = "mgmt" + deploymentName = "the-deployment" ) - It("Deploy Kustomize resources with Flux", Label("EXTENDED"), func() { - Byf("Create a ClusterProfile matching Cluster %s/%s", kindWorkloadCluster.GetNamespace(), kindWorkloadCluster.GetName()) - clusterProfile := getClusterProfile(namePrefix, map[string]string{key: value}) - clusterProfile.Spec.SyncMode = configv1beta1.SyncModeContinuous - Expect(k8sClient.Create(context.TODO(), clusterProfile)).To(Succeed()) + It("Deploy Kustomize resources with Flux", Serial, Label("FV", "PULLMODE", "EXTENDED"), func() { + Byf("Create a ClusterProfile matching mgmt Cluster") + gitRepositoryNamespace := "flux2" + mgmtClusterProfile := &configv1beta1.ClusterProfile{ + ObjectMeta: metav1.ObjectMeta{ + Name: namePrefix + randomString(), + }, + Spec: configv1beta1.Spec{ + ClusterRefs: []corev1.ObjectReference{ + { + APIVersion: libsveltosv1beta1.GroupVersion.String(), + Kind: libsveltosv1beta1.SveltosClusterKind, + Namespace: mgmt, + Name: mgmt, + }, + }, + }, + } - verifyClusterProfileMatches(clusterProfile) + mgmtClusterProfile.Spec.SyncMode = configv1beta1.SyncModeContinuous + Expect(k8sClient.Create(context.TODO(), mgmtClusterProfile)).To(Succeed()) + Byf("Created ClusterProfile %s", mgmtClusterProfile.Name) verifyClusterSummary(clusterops.ClusterProfileLabelName, - clusterProfile.Name, &clusterProfile.Spec, - kindWorkloadCluster.GetNamespace(), kindWorkloadCluster.GetName(), getClusterType()) + mgmtClusterProfile.Name, &mgmtClusterProfile.Spec, + mgmt, mgmt, string(libsveltosv1beta1.ClusterTypeSveltos)) - targetNamespace := randomString() - - gitRepositoryNamespace := "flux-system" - gitRepositoryName := gitRepositoryNamespace - - Byf("Update ClusterProfile %s to reference GitRepository flux-system/flux-system", clusterProfile.Name) + By("Deploying Flux on the management cluster") currentClusterProfile := &configv1beta1.ClusterProfile{} err := retry.RetryOnConflict(retry.DefaultRetry, func() error { - Expect(k8sClient.Get(context.TODO(), - types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed()) - currentClusterProfile.Spec.KustomizationRefs = []configv1beta1.KustomizationRef{ + err := k8sClient.Get(context.TODO(), + types.NamespacedName{Name: mgmtClusterProfile.Name}, + currentClusterProfile) + if err != nil { + return err + } + currentClusterProfile.Spec.HelmCharts = []configv1beta1.HelmChart{ { - Kind: sourcev1.GitRepositoryKind, - Namespace: gitRepositoryNamespace, - Name: gitRepositoryName, - Path: "./helloWorld", - TargetNamespace: targetNamespace, + RepositoryURL: "https://fluxcd-community.github.io/helm-charts", + RepositoryName: "flux2", + ChartName: "flux2/flux2", + ChartVersion: "2.18.2", + ReleaseName: "flux2", + ReleaseNamespace: gitRepositoryNamespace, + HelmChartAction: configv1beta1.HelmChartActionInstall, }, } return k8sClient.Update(context.TODO(), currentClusterProfile) @@ -80,11 +97,66 @@ var _ = Describe("Kustomize with GitRepository", func() { Expect(err).To(BeNil()) Expect(k8sClient.Get(context.TODO(), - types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed()) + types.NamespacedName{Name: mgmtClusterProfile.Name}, currentClusterProfile)).To(Succeed()) - Byf("Verifying GitRepository %s/%s exists", gitRepositoryNamespace, gitRepositoryName) - gitRepository := &sourcev1.GitRepository{} - Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Namespace: gitRepositoryNamespace, Name: gitRepositoryName}, + clusterSummary := verifyClusterSummary(clusterops.ClusterProfileLabelName, + currentClusterProfile.Name, ¤tClusterProfile.Spec, + mgmt, mgmt, string(libsveltosv1beta1.ClusterTypeSveltos)) + + listOpts := []client.ListOption{ + client.InNamespace(gitRepositoryNamespace), + } + + time.Sleep(time.Minute) + + // When Flux is deployed, Sveltos restarts (so watchers on Flux resources can be started) + Byf("Waiting for Sveltos addon-controller to be healthy") + Eventually(func() bool { + deployment := &appsv1.Deployment{} + err := k8sClient.Get(context.TODO(), + types.NamespacedName{Namespace: "projectsveltos", Name: "addon-controller"}, + deployment) + return err == nil && deployment.Status.AvailableReplicas == 1 + }, timeout, pollingInterval).Should(BeTrue()) + + Byf("Verifying Flux deployments are present") + Eventually(func() bool { + deployments := &appsv1.DeploymentList{} + err := k8sClient.List(context.TODO(), deployments, listOpts...) + return err == nil && len(deployments.Items) > 0 + }, timeout, pollingInterval).Should(BeTrue()) + + Byf("Verifying ClusterSummary %s status is set to Deployed for Helm feature", clusterSummary.Name) + verifyFeatureStatusIsProvisioned(mgmt, clusterSummary.Name, libsveltosv1beta1.FeatureHelm) + + Byf("Deleting NetworkPolicy in the %s namespace", gitRepositoryNamespace) + netPolList := &networkingv1.NetworkPolicyList{} + + Expect(k8sClient.List(context.Background(), netPolList, listOpts...)).To(Succeed()) + for i := range netPolList.Items { + Expect(k8sClient.Delete(context.TODO(), &netPolList.Items[i])).To(Succeed()) + } + + gitRepositoryName := gitRepositoryNamespace + + Byf("Create GitRepository %s/%s", gitRepositoryNamespace, gitRepositoryName) + gitRepository := &sourcev1.GitRepository{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: gitRepositoryNamespace, + Name: gitRepositoryName, + }, + Spec: sourcev1.GitRepositorySpec{ + URL: "https://github.com/gianlucam76/kustomize", + Interval: metav1.Duration{Duration: time.Minute}, + Reference: &sourcev1.GitRepositoryRef{ + Branch: "main", + }, + }, + } + Expect(k8sClient.Create(context.TODO(), gitRepository)).To(Succeed()) + + Expect(k8sClient.Get(context.TODO(), + types.NamespacedName{Namespace: gitRepositoryNamespace, Name: gitRepositoryName}, gitRepository)).To(Succeed()) Byf("Verifying GitRepository %s/%s artifact is set", gitRepositoryNamespace, gitRepositoryName) @@ -96,7 +168,42 @@ var _ = Describe("Kustomize with GitRepository", func() { gitRepository.Status.Artifact != nil }, timeout, pollingInterval).Should(BeTrue()) - clusterSummary := verifyClusterSummary(clusterops.ClusterProfileLabelName, + Byf("Create a ClusterProfile matching Cluster %s/%s", + kindWorkloadCluster.GetNamespace(), kindWorkloadCluster.GetName()) + managedClusterProfile := getClusterProfile(namePrefix, map[string]string{key: value}) + managedClusterProfile.Spec.SyncMode = configv1beta1.SyncModeContinuousWithDriftDetection + Expect(k8sClient.Create(context.TODO(), managedClusterProfile)).To(Succeed()) + + verifyClusterProfileMatches(managedClusterProfile) + + verifyClusterSummary(clusterops.ClusterProfileLabelName, + managedClusterProfile.Name, &managedClusterProfile.Spec, kindWorkloadCluster.GetNamespace(), + kindWorkloadCluster.GetName(), getClusterType()) + + targetNamespace := randomString() + + Byf("Update ClusterProfile %s to reference GitRepository %s/%s", + managedClusterProfile.Name, gitRepositoryNamespace, gitRepositoryName) + err = retry.RetryOnConflict(retry.DefaultRetry, func() error { + Expect(k8sClient.Get(context.TODO(), + types.NamespacedName{Name: managedClusterProfile.Name}, currentClusterProfile)).To(Succeed()) + currentClusterProfile.Spec.KustomizationRefs = []configv1beta1.KustomizationRef{ + { + Kind: sourcev1.GitRepositoryKind, + Namespace: gitRepositoryNamespace, + Name: gitRepositoryName, + Path: "./helloWorld", + TargetNamespace: targetNamespace, + }, + } + return k8sClient.Update(context.TODO(), currentClusterProfile) + }) + Expect(err).To(BeNil()) + + Expect(k8sClient.Get(context.TODO(), + types.NamespacedName{Name: managedClusterProfile.Name}, currentClusterProfile)).To(Succeed()) + + clusterSummary = verifyClusterSummary(clusterops.ClusterProfileLabelName, currentClusterProfile.Name, ¤tClusterProfile.Spec, kindWorkloadCluster.GetNamespace(), kindWorkloadCluster.GetName(), getClusterType()) @@ -117,7 +224,7 @@ var _ = Describe("Kustomize with GitRepository", func() { Eventually(func() bool { currentDeployment := &appsv1.Deployment{} err = workloadClient.Get(context.TODO(), - types.NamespacedName{Namespace: targetNamespace, Name: "the-deployment"}, currentDeployment) + types.NamespacedName{Namespace: targetNamespace, Name: deploymentName}, currentDeployment) return err == nil }, timeout, pollingInterval).Should(BeTrue()) @@ -142,19 +249,34 @@ var _ = Describe("Kustomize with GitRepository", func() { currentDeployment := &appsv1.Deployment{} Expect(workloadClient.Get(context.TODO(), - types.NamespacedName{Namespace: targetNamespace, Name: "the-deployment"}, currentDeployment)).To(Succeed()) + types.NamespacedName{Namespace: targetNamespace, Name: deploymentName}, currentDeployment)).To(Succeed()) policies := []policy{ {kind: "Service", name: currentService.Name, namespace: targetNamespace, group: ""}, {kind: "ConfigMap", name: currentConfigMap.Name, namespace: targetNamespace, group: ""}, {kind: "Deployment", name: currentDeployment.Name, namespace: targetNamespace, group: "apps"}, } - verifyClusterConfiguration(configv1beta1.ClusterProfileKind, clusterProfile.Name, + verifyClusterConfiguration(configv1beta1.ClusterProfileKind, managedClusterProfile.Name, clusterSummary.Spec.ClusterNamespace, clusterSummary.Spec.ClusterName, libsveltosv1beta1.FeatureKustomize, policies, nil) + Byf("Deleting deployment") + Expect(workloadClient.Get(context.TODO(), + types.NamespacedName{Namespace: targetNamespace, Name: deploymentName}, currentDeployment)).To(Succeed()) + Expect(workloadClient.Delete(context.TODO(), currentDeployment)).To(Succeed()) + + Byf("Verifying proper Deployment is recreated in the workload cluster in namespace %s", targetNamespace) + Eventually(func() bool { + currentDeployment := &appsv1.Deployment{} + err = workloadClient.Get(context.TODO(), + types.NamespacedName{Namespace: targetNamespace, Name: deploymentName}, currentDeployment) + return err == nil && + currentDeployment.DeletionTimestamp.IsZero() + }, timeout, pollingInterval).Should(BeTrue()) + Byf("Changing clusterprofile to not reference GitRepository anymore") - Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: clusterProfile.Name}, currentClusterProfile)).To(Succeed()) + Expect(k8sClient.Get(context.TODO(), types.NamespacedName{Name: managedClusterProfile.Name}, + currentClusterProfile)).To(Succeed()) currentClusterProfile.Spec.KustomizationRefs = []configv1beta1.KustomizationRef{} Expect(k8sClient.Update(context.TODO(), currentClusterProfile)).To(Succeed()) @@ -175,7 +297,7 @@ var _ = Describe("Kustomize with GitRepository", func() { Eventually(func() bool { currentDeployment := &appsv1.Deployment{} err = workloadClient.Get(context.TODO(), - types.NamespacedName{Namespace: targetNamespace, Name: "the-deployment"}, currentDeployment) + types.NamespacedName{Namespace: targetNamespace, Name: deploymentName}, currentDeployment) return err != nil && apierrors.IsNotFound(err) }, timeout, pollingInterval).Should(BeTrue()) @@ -189,6 +311,7 @@ var _ = Describe("Kustomize with GitRepository", func() { apierrors.IsNotFound(err) }, timeout, pollingInterval).Should(BeTrue()) - deleteClusterProfile(clusterProfile) + deleteClusterProfile(managedClusterProfile) + deleteClusterProfile(mgmtClusterProfile) }) }) diff --git a/test/pullmode-sveltosapplier.yaml b/test/pullmode-sveltosapplier.yaml index 7fcc3844..f9b0991d 100644 --- a/test/pullmode-sveltosapplier.yaml +++ b/test/pullmode-sveltosapplier.yaml @@ -99,7 +99,7 @@ spec: valueFrom: fieldRef: fieldPath: metadata.namespace - image: docker.io/projectsveltos/sveltos-applier@sha256:5287c7916a28cbf08eba52deda5fb0c97f4dd40a189b90554a9a80f2c0fe76c4 + image: docker.io/projectsveltos/sveltos-applier@sha256:9d302bb7f61e8a4c13e4afdbbcc1fc2235fdc3209bf3c36ec260339d3e4f8ebd livenessProbe: failureThreshold: 3 httpGet: