From 42e2b717884225122970303aa4686fec7d4544d7 Mon Sep 17 00:00:00 2001 From: Gianluca Mardente Date: Tue, 20 Oct 2026 14:26:21 +0200 Subject: [PATCH] IsClusterPaused: consider the paused annotation on CAPI clusters --- lib/clusterproxy/cluster_utils.go | 8 ++------ lib/clusterproxy/cluster_utils_test.go | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/clusterproxy/cluster_utils.go b/lib/clusterproxy/cluster_utils.go index 0aa7ce2b..b4050e55 100644 --- a/lib/clusterproxy/cluster_utils.go +++ b/lib/clusterproxy/cluster_utils.go @@ -34,6 +34,7 @@ import ( "k8s.io/client-go/rest" "k8s.io/client-go/tools/clientcmd" clusterv1 "sigs.k8s.io/cluster-api/api/core/v1beta2" + "sigs.k8s.io/cluster-api/util/annotations" "sigs.k8s.io/controller-runtime/pkg/client" libsveltosv1beta1 "github.com/projectsveltos/libsveltos/api/v1beta1" @@ -103,12 +104,7 @@ func isCAPIClusterPaused(ctx context.Context, c client.Client, return false, err } - paused := false - if cluster.Spec.Paused != nil { - paused = *cluster.Spec.Paused - } - - return paused, nil + return annotations.IsPaused(cluster, cluster), nil } // isSveltosClusterPaused returns true if Cluster is paused diff --git a/lib/clusterproxy/cluster_utils_test.go b/lib/clusterproxy/cluster_utils_test.go index 94f26cbb..9db10966 100644 --- a/lib/clusterproxy/cluster_utils_test.go +++ b/lib/clusterproxy/cluster_utils_test.go @@ -113,6 +113,22 @@ var _ = Describe("Cluster utils", func() { Expect(paused).To(BeFalse()) }) + It("IsClusterPaused returns true for a CAPI Cluster with the paused annotation and Spec.Paused set to false", func() { + paused := false + cluster.Spec.Paused = &paused + cluster.Annotations = map[string]string{clusterv1.PausedAnnotation: ""} + initObjects := []client.Object{ + cluster, + } + + c := fake.NewClientBuilder().WithScheme(scheme).WithObjects(initObjects...).Build() + + isPaused, err := clusterproxy.IsClusterPaused(context.TODO(), c, cluster.Namespace, + cluster.Name, libsveltosv1beta1.ClusterTypeCapi) + Expect(err).To(BeNil()) + Expect(isPaused).To(BeTrue()) + }) + It("GetSecretData returns kubeconfig data", func() { randomData := []byte(randomString()) sveltosSecret := corev1.Secret{