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
21 changes: 16 additions & 5 deletions controllers/drift_detection_upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,17 +295,28 @@ func skipUpgrading(ctx context.Context, c client.Client, cluster client.Object,
return true, err
}

if !isDriftDetectionManagerDeployedInCluster(ctx, managedClient) {
return true, nil // nothing to upgrade
present, err := isDriftDetectionManagerDeployedInCluster(ctx, managedClient)
if err != nil {
logger.V(logs.LogInfo).Error(err, "failed to verify presence of drift-detection-manager deployment")
return true, err
}

return false, nil
return present, nil
}

func isDriftDetectionManagerDeployedInCluster(ctx context.Context, c client.Client) bool {
func isDriftDetectionManagerDeployedInCluster(ctx context.Context, c client.Client) (bool, error) {
deployment := &appsv1.Deployment{}
// A test in pkg/drift-detection makes sure this name is correct
err := c.Get(ctx, types.NamespacedName{Namespace: projectsveltos, Name: "drift-detection-manager"}, deployment)
return err == nil

if err != nil {
if apierrors.IsNotFound(err) {
return false, nil
}
return false, err
}

return true, nil
}

func getListOfClustersWithDriftDetection(ctx context.Context, c client.Client,
Expand Down
46 changes: 46 additions & 0 deletions pkg/drift-detection/drift_manager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
Copyright 2026. projectsveltos.io. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package driftdetection_test

import (
. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

driftdetection "github.com/projectsveltos/addon-controller/pkg/drift-detection"
"github.com/projectsveltos/libsveltos/lib/deployer"
"github.com/projectsveltos/libsveltos/lib/k8s_utils"
)

var _ = Describe("Validate drift-detection-manager YAML", func() {
It("Deployment name validation", func() {
driftDetectionManagerYAML := string(driftdetection.GetDriftDetectionManagerYAML())
Expect(len(driftDetectionManagerYAML)).ToNot(BeZero())

elements, err := deployer.CustomSplit(driftDetectionManagerYAML)
Expect(err).To(BeNil())
for i := range elements {
policy, err := k8s_utils.GetUnstructured([]byte(elements[i]))
Expect(err).To(BeNil())
if policy.GetKind() == "Deployment" {
// drift-detection upgrade logic (isDriftDetectionManagerDeployedInCluster)
// assumes this is the name
Expect(policy.GetName()).To(Equal("drift-detection-manager"))
Expect(policy.GetNamespace()).To(Equal("projectsveltos"))
}
}
})
})
29 changes: 29 additions & 0 deletions pkg/drift-detection/suite_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
Copyright 2026. projectsveltos.io. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package driftdetection_test

import (
"testing"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

func TestScope(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Scope Suite")
}
1 change: 1 addition & 0 deletions pkg/scope/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
Expand Down