diff --git a/controllers/export_test.go b/controllers/export_test.go index b49214cb..599241fa 100644 --- a/controllers/export_test.go +++ b/controllers/export_test.go @@ -252,6 +252,7 @@ var ( CollectResourceSummariesFromCluster = collectResourceSummariesFromCluster CollectAndProcessAllResourceSummaries = collectAndProcessAllResourceSummaries IsResourceSummaryInstalledCached = isResourceSummaryInstalledCached + SkipCollecting = skipCollecting ResetResourceSummaryInstalledCache = func() { resourceSummaryInstalledCacheMu.Lock() resourceSummaryInstalledCache = make(map[corev1.ObjectReference]bool) diff --git a/controllers/resourcesummary_collection_test.go b/controllers/resourcesummary_collection_test.go index 159bad78..c0112ec8 100644 --- a/controllers/resourcesummary_collection_test.go +++ b/controllers/resourcesummary_collection_test.go @@ -594,6 +594,45 @@ var _ = Describe("ResourceSummary Collection", func() { return currentSveltosRS.Status.HelmResourcesChanged }, "2s", pollingInterval).Should(BeTrue()) }) + + It("skipCollecting skips a SveltosCluster whose connection is down, even when it is marked ready", func() { + logger := textlogger.NewLogger(textlogger.NewConfig()) + + sveltosCluster := &libsveltosv1beta1.SveltosCluster{ + ObjectMeta: metav1.ObjectMeta{ + Namespace: randomString(), + Name: randomString(), + }, + Status: libsveltosv1beta1.SveltosClusterStatus{ + Ready: true, + ConnectionStatus: libsveltosv1beta1.ConnectionDown, + }, + } + c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(sveltosCluster).Build() + + clusterRef := &corev1.ObjectReference{ + Namespace: sveltosCluster.Namespace, + Name: sveltosCluster.Name, + Kind: libsveltosv1beta1.SveltosClusterKind, + APIVersion: libsveltosv1beta1.GroupVersion.String(), + } + + skip, err := controllers.SkipCollecting(context.TODO(), c, clusterRef, logger) + Expect(err).To(BeNil()) + Expect(skip).To(BeTrue()) + + // Once the connection is back, collection is not skipped anymore + currentSveltosCluster := &libsveltosv1beta1.SveltosCluster{} + Expect(c.Get(context.TODO(), + types.NamespacedName{Namespace: sveltosCluster.Namespace, Name: sveltosCluster.Name}, + currentSveltosCluster)).To(Succeed()) + currentSveltosCluster.Status.ConnectionStatus = libsveltosv1beta1.ConnectionHealthy + Expect(c.Update(context.TODO(), currentSveltosCluster)).To(Succeed()) + + skip, err = controllers.SkipCollecting(context.TODO(), c, clusterRef, logger) + Expect(err).To(BeNil()) + Expect(skip).To(BeFalse()) + }) }) // getResourceSummary returns a bare ResourceSummary. None of the tests in this file need it diff --git a/go.mod b/go.mod index f961ffa0..dd85b9a3 100644 --- a/go.mod +++ b/go.mod @@ -20,7 +20,7 @@ require ( github.com/onsi/gomega v1.44.0 github.com/opencontainers/image-spec v1.1.1 github.com/pkg/errors v0.9.1 - github.com/projectsveltos/libsveltos v1.16.1-0.20261007133830-d623a1556939 + github.com/projectsveltos/libsveltos v1.16.1-0.20261010130719-c6f30f77e62f github.com/prometheus/client_golang v1.25.0 github.com/sigstore/cosign/v3 v3.1.3 github.com/sigstore/sigstore v1.11.0 diff --git a/go.sum b/go.sum index 00d966cb..b6b78274 100644 --- a/go.sum +++ b/go.sum @@ -643,8 +643,8 @@ github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRI github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/poy/onpar v1.1.2 h1:QaNrNiZx0+Nar5dLgTVp5mXkyoVFIbepjyEoGSnhbAY= github.com/poy/onpar v1.1.2/go.mod h1:6X8FLNoxyr9kkmnlqpK6LSoiOtrO6MICtWwEuWkLjzg= -github.com/projectsveltos/libsveltos v1.16.1-0.20261007133830-d623a1556939 h1:yQuZm4uT19ZkdCPSU3hkheRszZOCXBEY4TILNudAm58= -github.com/projectsveltos/libsveltos v1.16.1-0.20261007133830-d623a1556939/go.mod h1:wup25BAf1SHuG6FsY8D+tnm1U3/3NiuzcKec/In/fB4= +github.com/projectsveltos/libsveltos v1.16.1-0.20261010130719-c6f30f77e62f h1:4+dAshhv+rdzFIlo6q5+3/8mSmxwiqxN1gxl5czeeF8= +github.com/projectsveltos/libsveltos v1.16.1-0.20261010130719-c6f30f77e62f/go.mod h1:wup25BAf1SHuG6FsY8D+tnm1U3/3NiuzcKec/In/fB4= 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=