Skip to content
Closed
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
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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.3.0
TAG ?= main

.PHONY: all
all: build
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_auth_proxy_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ spec:
- --shard-key=
- --capi-onboard-annotation=
- "--v=5"
- "--version=v1.3.0"
- "--version=main"
- "--agent-in-mgmt-cluster=false"
env:
- name: GOMEMLIMIT
Expand Down
2 changes: 1 addition & 1 deletion config/default/manager_image_patch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ spec:
spec:
containers:
# Change the value of image field below to your controller image URL
- image: docker.io/projectsveltos/addon-controller:v1.3.0
- image: docker.io/projectsveltos/addon-controller:main
name: controller
29 changes: 29 additions & 0 deletions controllers/drift_detection_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ import (
"github.com/go-logr/logr"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/client-go/rest"
clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2"
"sigs.k8s.io/controller-runtime/pkg/client"
Expand Down Expand Up @@ -255,5 +257,32 @@ func skipUpgrading(ctx context.Context, c client.Client, cluster client.Object,
return true, nil
}

// Verify if ResourceSummary CRD is present. Th
resourceCRDPresent, err := isResourceSummaryCRDPresent(ctx, c, logger)
if err != nil {
return true, err
}

if !resourceCRDPresent {
return true, nil
}

return false, nil
}

func isResourceSummaryCRDPresent(ctx context.Context, c client.Client, logger logr.Logger) (bool, error) {
resourceSummaryCRD := &apiextensionsv1.CustomResourceDefinition{}

err := c.Get(ctx, types.NamespacedName{Name: "resourcesummaries.lib.projectsveltos.io"},
resourceSummaryCRD)

if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
logger.V(logs.LogInfo).Error(err, "failed to verify presence of ResourceSummary CRD")
return false, err
}

return true, nil
}
53 changes: 53 additions & 0 deletions controllers/drift_detection_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ import (

"github.com/projectsveltos/addon-controller/controllers"
libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
libsveltoscrd "github.com/projectsveltos/libsveltos/lib/crd"
"github.com/projectsveltos/libsveltos/lib/k8s_utils"
)

var _ = Describe("Drift Detection Upgrade", func() {
Expand Down Expand Up @@ -107,12 +109,16 @@ var _ = Describe("Drift Detection Upgrade", func() {
}
Expect(addTypeInformationToObject(scheme, capiClusterNotPaused)).To(Succeed())

resourceSummaryCRD, err := k8s_utils.GetUnstructured(libsveltoscrd.GetResourceSummaryCRDYAML())
Expect(err).To(BeNil())

initObjects := []client.Object{
sveltosClusterPaused,
sveltosClusterNotReady,
sveltosClusterReadyAndNotPaused,
capiClusterPaused,
capiClusterNotPaused,
resourceSummaryCRD,
}

c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).
Expand All @@ -138,4 +144,51 @@ var _ = Describe("Drift Detection Upgrade", func() {
Expect(err).To(BeNil())
Expect(skip).To(BeFalse())
})

It("skipUpgrading skips clusters with no ResourceSummary CRD", func() {
sveltosClusterReadyAndNotPaused := &libsveltosv1beta1.SveltosCluster{
ObjectMeta: metav1.ObjectMeta{
Name: randomString(),
Namespace: randomString(),
},
Spec: libsveltosv1beta1.SveltosClusterSpec{
Paused: false,
},
Status: libsveltosv1beta1.SveltosClusterStatus{
Ready: true,
},
}
Expect(addTypeInformationToObject(scheme, sveltosClusterReadyAndNotPaused)).To(Succeed())

initialized := true
capiClusterNotPaused := &clusterv1.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: randomString(),
Namespace: randomString(),
},
Spec: clusterv1.ClusterSpec{},
Status: clusterv1.ClusterStatus{
Initialization: clusterv1.ClusterInitializationStatus{
ControlPlaneInitialized: &initialized,
},
},
}
Expect(addTypeInformationToObject(scheme, capiClusterNotPaused)).To(Succeed())

initObjects := []client.Object{
sveltosClusterReadyAndNotPaused,
capiClusterNotPaused,
}

c := fake.NewClientBuilder().WithScheme(scheme).WithStatusSubresource(initObjects...).
WithObjects(initObjects...).Build()

skip, err := controllers.SkipUpgrading(context.TODO(), c, sveltosClusterReadyAndNotPaused, logger)
Expect(err).To(BeNil())
Expect(skip).To(BeTrue())

skip, err = controllers.SkipUpgrading(context.TODO(), c, capiClusterNotPaused, logger)
Expect(err).To(BeNil())
Expect(skip).To(BeTrue())
})
})
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ require (
github.com/Masterminds/semver/v3 v3.4.0
github.com/TwiN/go-color v1.4.1
github.com/dariubs/percent v1.0.0
github.com/docker/cli v29.1.2+incompatible
github.com/docker/cli v29.1.3+incompatible
github.com/fluxcd/pkg/apis/meta v1.23.0
github.com/fluxcd/pkg/http/fetch v0.21.0
github.com/fluxcd/pkg/tar v0.16.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ github.com/dlclark/regexp2 v1.11.0 h1:G/nrcoOa7ZXlpoa/91N3X7mM3r8eIlMBBJZvsz/mxK
github.com/dlclark/regexp2 v1.11.0/go.mod h1:DHkYz0B9wPfa6wondMfaivmHpzrQ3v9q8cnmRbL6yW8=
github.com/docker/cli v29.1.2+incompatible h1:s4QI7drXpIo78OM+CwuthPsO5kCf8cpNsck5PsLVTH8=
github.com/docker/cli v29.1.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/cli v29.1.3+incompatible h1:+kz9uDWgs+mAaIZojWfFt4d53/jv0ZUOOoSh5ZnH36c=
github.com/docker/cli v29.1.3+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8=
github.com/docker/docker-credential-helpers v0.8.2 h1:bX3YxiGzFP5sOXWc3bTPEXdEaZSeVMrFgOr3T+zrFAo=
github.com/docker/docker-credential-helpers v0.8.2/go.mod h1:P3ci7E3lwkZg6XiHdRKft1KckHiO9a2rNtyFbZ/ry9M=
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c h1:+pKlWGMw7gf6bQ+oDZB4KHQFypsfjYlq/C4rfL7D3g8=
Expand Down
4 changes: 2 additions & 2 deletions manifest/deployment-agentless.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- --shard-key=
- --capi-onboard-annotation=
- --v=5
- --version=v1.3.0
- --version=main
- --agent-in-mgmt-cluster=true
command:
- /manager
Expand All @@ -37,7 +37,7 @@ spec:
valueFrom:
resourceFieldRef:
resource: limits.cpu
image: docker.io/projectsveltos/addon-controller:v1.3.0
image: docker.io/projectsveltos/addon-controller:main
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
4 changes: 2 additions & 2 deletions manifest/deployment-shard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ spec:
- --shard-key={{.SHARD}}
- --capi-onboard-annotation=
- --v=5
- --version=v1.3.0
- --version=main
- --agent-in-mgmt-cluster=false
command:
- /manager
Expand All @@ -37,7 +37,7 @@ spec:
valueFrom:
resourceFieldRef:
resource: limits.cpu
image: docker.io/projectsveltos/addon-controller:v1.3.0
image: docker.io/projectsveltos/addon-controller:main
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
4 changes: 2 additions & 2 deletions manifest/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6951,7 +6951,7 @@ spec:
- --shard-key=
- --capi-onboard-annotation=
- --v=5
- --version=v1.3.0
- --version=main
- --agent-in-mgmt-cluster=false
command:
- /manager
Expand All @@ -6964,7 +6964,7 @@ spec:
valueFrom:
resourceFieldRef:
resource: limits.cpu
image: docker.io/projectsveltos/addon-controller:v1.3.0
image: docker.io/projectsveltos/addon-controller:main
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ spec:
- --cluster-type=
- --current-cluster=management-cluster
- --run-mode=do-not-send-updates
- --version=v1.3.0
- --version=main
command:
- /manager
image: docker.io/projectsveltos/drift-detection-manager@sha256:3714d0c31508628812418f7fd02675068d4959729ccb98b8f37095b8745c1f29
image: docker.io/projectsveltos/drift-detection-manager@sha256:00db897303f998716f80bba57378a688902539da25d88760260380382c8ad4da
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,10 @@ spec:
- --cluster-type=
- --current-cluster=management-cluster
- --run-mode=do-not-send-updates
- --version=v1.3.0
- --version=main
command:
- /manager
image: docker.io/projectsveltos/drift-detection-manager@sha256:3714d0c31508628812418f7fd02675068d4959729ccb98b8f37095b8745c1f29
image: docker.io/projectsveltos/drift-detection-manager@sha256:00db897303f998716f80bba57378a688902539da25d88760260380382c8ad4da
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
4 changes: 2 additions & 2 deletions pkg/drift-detection/drift-detection-manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,10 @@ spec:
- --cluster-type=
- --current-cluster=managed-cluster
- --run-mode=do-not-send-updates
- --version=v1.3.0
- --version=main
command:
- /manager
image: docker.io/projectsveltos/drift-detection-manager@sha256:3714d0c31508628812418f7fd02675068d4959729ccb98b8f37095b8745c1f29
image: docker.io/projectsveltos/drift-detection-manager@sha256:00db897303f998716f80bba57378a688902539da25d88760260380382c8ad4da
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
4 changes: 2 additions & 2 deletions pkg/drift-detection/drift-detection-manager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,10 @@ spec:
- --cluster-type=
- --current-cluster=managed-cluster
- --run-mode=do-not-send-updates
- --version=v1.3.0
- --version=main
command:
- /manager
image: docker.io/projectsveltos/drift-detection-manager@sha256:3714d0c31508628812418f7fd02675068d4959729ccb98b8f37095b8745c1f29
image: docker.io/projectsveltos/drift-detection-manager@sha256:00db897303f998716f80bba57378a688902539da25d88760260380382c8ad4da
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
Loading