From dbd4390041892b08fb8b5c62ce02b1fc98b707b7 Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Wed, 27 Nov 2024 11:32:18 +0200 Subject: [PATCH] More label fixes --- controllers/medusa/medusabackupjob_controller_test.go | 2 +- controllers/medusa/medusarestorejob_controller.go | 7 ++++--- pkg/cassandra/management.go | 5 +++-- pkg/medusa/utils.go | 2 +- test/e2e/suite_test.go | 2 +- 5 files changed, 10 insertions(+), 8 deletions(-) diff --git a/controllers/medusa/medusabackupjob_controller_test.go b/controllers/medusa/medusabackupjob_controller_test.go index e20ce82f8..3b8e3ac5f 100644 --- a/controllers/medusa/medusabackupjob_controller_test.go +++ b/controllers/medusa/medusabackupjob_controller_test.go @@ -504,7 +504,7 @@ func createDatacenterPods(t *testing.T, f *framework.Framework, ctx context.Cont Name: podName, Labels: map[string]string{ cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(dc.Spec.ClusterName), - cassdcapi.DatacenterLabel: dc.DatacenterName(), + cassdcapi.DatacenterLabel: dc.Name, }, }, Spec: corev1.PodSpec{ diff --git a/controllers/medusa/medusarestorejob_controller.go b/controllers/medusa/medusarestorejob_controller.go index 0c85551e1..4a70cf263 100644 --- a/controllers/medusa/medusarestorejob_controller.go +++ b/controllers/medusa/medusarestorejob_controller.go @@ -20,11 +20,12 @@ import ( "context" "encoding/json" "fmt" - "github.com/go-logr/logr" - "github.com/k8ssandra/k8ssandra-operator/pkg/shared" "net" "time" + "github.com/go-logr/logr" + "github.com/k8ssandra/k8ssandra-operator/pkg/shared" + appsv1 "k8s.io/api/apps/v1" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" @@ -237,7 +238,7 @@ func (r *MedusaRestoreJobReconciler) podTemplateSpecUpdateComplete(ctx context.C // StatefulSets are scaled back up. statefulsetList := &appsv1.StatefulSetList{} - labels := client.MatchingLabels{cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(req.Datacenter.Spec.ClusterName), cassdcapi.DatacenterLabel: req.Datacenter.DatacenterName()} + labels := client.MatchingLabels{cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(req.Datacenter.Spec.ClusterName), cassdcapi.DatacenterLabel: req.Datacenter.Name} if err := r.List(ctx, statefulsetList, labels); err != nil { req.Log.Error(err, "Failed to get StatefulSets") diff --git a/pkg/cassandra/management.go b/pkg/cassandra/management.go index 7a76d6a1a..e4a060453 100644 --- a/pkg/cassandra/management.go +++ b/pkg/cassandra/management.go @@ -3,9 +3,10 @@ package cassandra import ( "context" "fmt" + "strconv" + "github.com/k8ssandra/k8ssandra-operator/pkg/errors" "github.com/k8ssandra/k8ssandra-operator/pkg/utils" - "strconv" "github.com/go-logr/logr" cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1" @@ -135,7 +136,7 @@ func (r *defaultManagementApiFacade) CreateKeyspaceIfNotExists( func (r *defaultManagementApiFacade) fetchDatacenterPods() ([]corev1.Pod, error) { podList := &corev1.PodList{} labels := client.MatchingLabels{ - cassdcapi.DatacenterLabel: cassdcapi.CleanLabelValue(r.dc.DatacenterName()), + cassdcapi.DatacenterLabel: cassdcapi.CleanLabelValue(r.dc.Name), cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(r.dc.Spec.ClusterName)} if err := r.k8sClient.List(r.ctx, podList, labels); err != nil { return nil, err diff --git a/pkg/medusa/utils.go b/pkg/medusa/utils.go index cc04907a2..ad8f94592 100644 --- a/pkg/medusa/utils.go +++ b/pkg/medusa/utils.go @@ -14,7 +14,7 @@ func GetCassandraDatacenterPods(ctx context.Context, cassdc *cassdcapi.Cassandra podList := &corev1.PodList{} labels := client.MatchingLabels{ cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(cassdc.Spec.ClusterName), - cassdcapi.DatacenterLabel: cassdc.DatacenterName(), + cassdcapi.DatacenterLabel: cassdc.Name, } if err := r.List(ctx, podList, labels, client.InNamespace(cassdc.Namespace)); err != nil { logger.Error(err, "failed to get pods for cassandradatacenter", "CassandraDatacenter", cassdc.DatacenterName()) diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index 265e2a731..c0628b1c9 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -2239,7 +2239,7 @@ func checkInjectedVolumePresence(t *testing.T, ctx context.Context, f *framework return fmt.Errorf("cannot find busybox injected container in pod template spec") } - cassandraPods, err := f.GetCassandraDatacenterPods(t, ctx, dcKey, cassdc.DatacenterName()) + cassandraPods, err := f.GetCassandraDatacenterPods(t, ctx, dcKey, cassdc.Name) require.NoError(t, err, "failed listing Cassandra pods") cassandraIndex, cassandraFound := findContainerInPod(t, cassandraPods[0], "cassandra") require.True(t, cassandraFound, "cannot find cassandra container in cassandra pod")