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
35 changes: 35 additions & 0 deletions controllers/mgmtcluster_classifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2/textlogger"
"sigs.k8s.io/controller-runtime/pkg/client/fake"

libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1"
Expand Down Expand Up @@ -93,6 +94,40 @@ var _ = Describe("ManagementClusterClassifier utils", func() {
})
})

Context("fetchResourcesForSelector", func() {
It("excludes a deleting resource unless ResourceSelector.IncludeDeletingResources is set", func() {
deleting := buildUnstructuredConfigMap("deleting-cm", map[string]string{testLabelEnv: testValueProd})
deleting.SetFinalizers([]string{"projectsveltos.io/test-finalizer"})
now := metav1.Now()
deleting.SetDeletionTimestamp(&now)

live := buildUnstructuredConfigMap("live-cm", map[string]string{testLabelEnv: testValueProd})

fakeClient := fake.NewClientBuilder().
WithScheme(mgmtTestScheme()).
WithObjects(deleting, live).
Build()

logger := textlogger.NewLogger(textlogger.NewConfig(textlogger.Verbosity(1)))

rs := &libsveltosv1beta1.ResourceSelector{
Group: "",
Version: corev1.SchemeGroupVersion.Version,
Kind: "ConfigMap",
}

resources, err := controllers.FetchResourcesForSelector(context.TODO(), fakeClient, rs, logger)
Expect(err).ToNot(HaveOccurred())
Expect(resources).To(HaveLen(1))
Expect(resources[0].GetName()).To(Equal(live.GetName()))

rs.IncludeDeletingResources = true
resources, err = controllers.FetchResourcesForSelector(context.TODO(), fakeClient, rs, logger)
Expect(err).ToNot(HaveOccurred())
Expect(resources).To(HaveLen(2))
})
})

Context("runClassificationLua", func() {
It("returns no clusters for empty resource list", func() {
script := `
Expand Down
2 changes: 1 addition & 1 deletion controllers/mgmtcluster_classifier_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func fetchResourcesForSelector(ctx context.Context, c client.Client,
for i := range list.Items {
u := &list.Items[i]

if !u.GetDeletionTimestamp().IsZero() {
if !rs.IncludeDeletingResources && !u.GetDeletionTimestamp().IsZero() {
continue
}
if rs.Name != "" && u.GetName() != rs.Name {
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.2
github.com/onsi/gomega v1.43.0
github.com/pkg/errors v0.9.1
github.com/projectsveltos/libsveltos v1.15.0
github.com/projectsveltos/libsveltos v1.15.1-0.20260916064556-4b7dcd8c38fd
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 @@ -208,8 +208,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.15.0 h1:O0iE6ZCnft4Dy9P5bgZUG384FdoQGtkE5wWk1g7L2Qk=
github.com/projectsveltos/libsveltos v1.15.0/go.mod h1:YKMqwREDkoQH84WTmixxsB8tN5V0cwOnWQ5hNjrg7xM=
github.com/projectsveltos/libsveltos v1.15.1-0.20260916064556-4b7dcd8c38fd h1:DDcvUiTbr37R6tHMrBtMFjcRtr39VGV1Mm/dVdhyQwE=
github.com/projectsveltos/libsveltos v1.15.1-0.20260916064556-4b7dcd8c38fd/go.mod h1:YKMqwREDkoQH84WTmixxsB8tN5V0cwOnWQ5hNjrg7xM=
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
2 changes: 1 addition & 1 deletion pkg/agent/sveltos-agent-in-mgmt-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: docker.io/projectsveltos/sveltos-agent@sha256:234ae2d4ace464b54bfbdb1affad42aca596ab1f55d581539faf7ae5c1479a86
image: docker.io/projectsveltos/sveltos-agent@sha256:aaaf3ab1e5798b005d959f5c614c14a1c630691f22d93df69ad6ad56186114a5
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/sveltos-agent-in-mgmt-cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: docker.io/projectsveltos/sveltos-agent@sha256:234ae2d4ace464b54bfbdb1affad42aca596ab1f55d581539faf7ae5c1479a86
image: docker.io/projectsveltos/sveltos-agent@sha256:aaaf3ab1e5798b005d959f5c614c14a1c630691f22d93df69ad6ad56186114a5
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/sveltos-agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: docker.io/projectsveltos/sveltos-agent@sha256:234ae2d4ace464b54bfbdb1affad42aca596ab1f55d581539faf7ae5c1479a86
image: docker.io/projectsveltos/sveltos-agent@sha256:aaaf3ab1e5798b005d959f5c614c14a1c630691f22d93df69ad6ad56186114a5
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down
2 changes: 1 addition & 1 deletion pkg/agent/sveltos-agent.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ spec:
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: docker.io/projectsveltos/sveltos-agent@sha256:234ae2d4ace464b54bfbdb1affad42aca596ab1f55d581539faf7ae5c1479a86
image: docker.io/projectsveltos/sveltos-agent@sha256:aaaf3ab1e5798b005d959f5c614c14a1c630691f22d93df69ad6ad56186114a5
livenessProbe:
failureThreshold: 3
httpGet:
Expand Down