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
8 changes: 8 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ rules:
- ""
resources:
- configmaps
verbs:
- delete
- get
- list
- watch
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
Expand Down
2 changes: 1 addition & 1 deletion controllers/classifier_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ type ClassifierReconciler struct {
//+kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters,verbs=get;watch;list;update
//+kubebuilder:rbac:groups=cluster.x-k8s.io,resources=clusters/status,verbs=get;watch;list
//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch
//+kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch
//+kubebuilder:rbac:groups="",resources=configmaps,verbs=get;list;watch;delete
//+kubebuilder:rbac:groups="apps",resources=deployments,verbs=get;list;watch

func (r *ClassifierReconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) {
Expand Down
10 changes: 10 additions & 0 deletions controllers/classifier_deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import (
logs "github.com/projectsveltos/libsveltos/lib/logsettings"
"github.com/projectsveltos/libsveltos/lib/patcher"
"github.com/projectsveltos/libsveltos/lib/pullmode"
"github.com/projectsveltos/libsveltos/lib/sveltos_upgrade"
)

type getCurrentHash func(classifier *libsveltosv1beta1.Classifier) []byte
Expand Down Expand Up @@ -2072,6 +2073,15 @@ func removeSveltosAgentFromManagementCluster(ctx context.Context,
manager.RemoveSveltosAgentDeploymentName(clusterNamespace, clusterName, clusterType)
}

// Propagate the error here (unlike the deletes in the loop above): cleanClusterStaleResources
// turns this into a requeue, so it gets retried via the reconciler and the periodic sweep
// instead of leaving the version ConfigMap behind for good.
if err := sveltos_upgrade.DeleteSveltosAgentVersion(ctx, getManagementClusterClient(), getSveltosNamespace(),
clusterNamespace, clusterName, clusterType, true, logger); err != nil {
logger.V(logs.LogInfo).Info(fmt.Sprintf("failed to delete sveltos-agent version configMap: %v", err))
return err
}

return nil
}

Expand Down
36 changes: 36 additions & 0 deletions controllers/classifier_deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
"github.com/projectsveltos/libsveltos/lib/deployer"
fakedeployer "github.com/projectsveltos/libsveltos/lib/deployer/fake"
"github.com/projectsveltos/libsveltos/lib/sveltos_upgrade"
)

const (
Expand Down Expand Up @@ -592,6 +593,17 @@ var _ = Describe("Classifier Deployer", func() {
clusterName := randomString()
clusterType := libsveltosv1beta1.ClusterTypeSveltos

// The version ConfigMap is created in clusterNamespace itself (matching a real CAPI/Sveltos
// cluster's namespace), so - unlike the rest of this test, which never touches clusterNamespace
// as a real object - it needs to actually exist for that Create to pass namespace admission.
ns := &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: clusterNamespace,
},
}
Expect(testEnv.Create(context.TODO(), ns)).To(Succeed())
Expect(waitForObject(context.TODO(), testEnv.Client, ns)).To(Succeed())

_, err := keymanager.GetKeyManagerInstance(context.TODO(), testEnv.Client)
Expect(err).To(BeNil())

Expand Down Expand Up @@ -623,6 +635,23 @@ var _ = Describe("Classifier Deployer", func() {
return false
}, timeout, pollingInterval).Should(BeTrue())

Expect(sveltos_upgrade.StoreSveltosAgentVersion(context.TODO(), testEnv.Client, sveltosNamespace, "v1.0.0",
clusterNamespace, clusterName, clusterType, true, logger)).To(Succeed())

var versionConfigMap corev1.ConfigMap
Eventually(func() bool {
versionConfigMaps := &corev1.ConfigMapList{}
err := testEnv.List(context.TODO(), versionConfigMaps, client.InNamespace(clusterNamespace), client.MatchingLabels{
sveltos_upgrade.ClusterNameLabel: clusterName,
sveltos_upgrade.ClusterTypeLabel: strings.ToLower(string(clusterType)),
})
if err != nil || len(versionConfigMaps.Items) != 1 {
return false
}
versionConfigMap = versionConfigMaps.Items[0]
return true
}, timeout, pollingInterval).Should(BeTrue())

Expect(controllers.RemoveSveltosAgentFromManagementCluster(context.TODO(), clusterNamespace, clusterName,
clusterType, logger)).To(Succeed())

Expand All @@ -641,6 +670,13 @@ var _ = Describe("Classifier Deployer", func() {
}
return true
}, timeout, pollingInterval).Should(BeTrue())

Eventually(func() bool {
err := testEnv.Get(context.TODO(),
types.NamespacedName{Namespace: versionConfigMap.Namespace, Name: versionConfigMap.Name},
&corev1.ConfigMap{})
return apierrors.IsNotFound(err)
}, timeout, pollingInterval).Should(BeTrue())
})

It("getSveltosAgentPatches reads post render patches from ConfigMap", func() {
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/onsi/ginkgo/v2 v2.32.1
github.com/onsi/gomega v1.42.1
github.com/pkg/errors v0.9.1
github.com/projectsveltos/libsveltos v1.14.0
github.com/projectsveltos/libsveltos v1.14.1-0.20260830170459-49d8e4e94b6e
github.com/prometheus/client_golang v1.24.1
github.com/spf13/pflag v1.0.10
github.com/yuin/gopher-lua v1.1.2
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINE
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/projectsveltos/libsveltos v1.14.0 h1:vw+kbGfsMcKk69AdQsjpdhlZK0LI/07Y+292noB9F+8=
github.com/projectsveltos/libsveltos v1.14.0/go.mod h1:U6iGj5KoC/PcTD2vh3XU6gy7g11suThT6sZSEpmLEkU=
github.com/projectsveltos/libsveltos v1.14.1-0.20260830170459-49d8e4e94b6e h1:jIOPS81hUuFNwGCTgGV/M4eFbsVCd1vpByYgWYMyngg=
github.com/projectsveltos/libsveltos v1.14.1-0.20260830170459-49d8e4e94b6e/go.mod h1:U6iGj5KoC/PcTD2vh3XU6gy7g11suThT6sZSEpmLEkU=
github.com/projectsveltos/lua-utils/glua-json v0.0.0-20251212200258-2b3cdcb7c0f5 h1:khnc+994UszxZYu69J+R5FKiLA/Nk1JQj0EYAkwTWz0=
github.com/projectsveltos/lua-utils/glua-json v0.0.0-20251212200258-2b3cdcb7c0f5/go.mod h1:yVL8KQFa9tmcxgwl9nwIMtKgtmIVC1zaFRSCfOwYvPY=
github.com/projectsveltos/lua-utils/glua-runes v0.0.0-20251212200258-2b3cdcb7c0f5 h1:YbsebwRwTRhV8QacvEAdFqxcxHdeu7JTVtsBovbkgos=
Expand Down
8 changes: 8 additions & 0 deletions manifest/manifest.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ rules:
- ""
resources:
- configmaps
verbs:
- delete
- get
- list
- watch
- apiGroups:
- ""
resources:
- secrets
verbs:
- get
Expand Down