From 08fc5e1cd7cd1ed64bfa02f8e98df9682b507b85 Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Wed, 27 Nov 2024 13:48:22 +0200 Subject: [PATCH] Return DcPrefix since it was used for resource names also, some more label changes --- controllers/k8ssandra/seeds.go | 2 +- .../medusa/medusabackupjob_controller_test.go | 5 +---- controllers/reaper/reaper_controller_test.go | 17 ++++++----------- pkg/cassandra/management.go | 4 +--- pkg/medusa/utils.go | 5 +---- test/e2e/suite_test.go | 2 +- 6 files changed, 11 insertions(+), 24 deletions(-) diff --git a/controllers/k8ssandra/seeds.go b/controllers/k8ssandra/seeds.go index 217c99234..bc2265ba3 100644 --- a/controllers/k8ssandra/seeds.go +++ b/controllers/k8ssandra/seeds.go @@ -35,7 +35,7 @@ func (r *K8ssandraClusterReconciler) findSeeds(ctx context.Context, kc *api.K8ss list := &corev1.PodList{} selector := map[string]string{ cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(cassClusterName), - cassdcapi.DatacenterLabel: dcTemplate.CassDcName(), + cassdcapi.DatacenterLabel: dcTemplate.Meta.Name, cassdcapi.SeedNodeLabel: "true", } diff --git a/controllers/medusa/medusabackupjob_controller_test.go b/controllers/medusa/medusabackupjob_controller_test.go index 3b8e3ac5f..62f136af9 100644 --- a/controllers/medusa/medusabackupjob_controller_test.go +++ b/controllers/medusa/medusabackupjob_controller_test.go @@ -502,10 +502,7 @@ func createDatacenterPods(t *testing.T, f *framework.Framework, ctx context.Cont ObjectMeta: metav1.ObjectMeta{ Namespace: dc.Namespace, Name: podName, - Labels: map[string]string{ - cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(dc.Spec.ClusterName), - cassdcapi.DatacenterLabel: dc.Name, - }, + Labels: dc.GetDatacenterLabels(), }, Spec: corev1.PodSpec{ Containers: []corev1.Container{ diff --git a/controllers/reaper/reaper_controller_test.go b/controllers/reaper/reaper_controller_test.go index edb66e248..b41183e2b 100644 --- a/controllers/reaper/reaper_controller_test.go +++ b/controllers/reaper/reaper_controller_test.go @@ -2,11 +2,12 @@ package reaper import ( "context" - "k8s.io/apimachinery/pkg/api/resource" - "k8s.io/utils/ptr" "testing" "time" + "k8s.io/apimachinery/pkg/api/resource" + "k8s.io/utils/ptr" + cassdcapi "github.com/k8ssandra/cass-operator/apis/cassandra/v1beta1" k8ssandraapi "github.com/k8ssandra/k8ssandra-operator/apis/k8ssandra/v1alpha1" reaperapi "github.com/k8ssandra/k8ssandra-operator/apis/reaper/v1alpha1" @@ -131,10 +132,7 @@ func beforeTest(t *testing.T, ctx context.Context, k8sClient client.Client, test ObjectMeta: metav1.ObjectMeta{ Name: "test-cassdc-pod1", Namespace: testNamespace, - Labels: map[string]string{ - cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(cassandraClusterName), - cassdcapi.DatacenterLabel: cassandraDatacenterName, - }, + Labels: cassdc.GetDatacenterLabels(), }, Spec: corev1.PodSpec{ Containers: []corev1.Container{{ @@ -162,11 +160,8 @@ func beforeTest(t *testing.T, ctx context.Context, k8sClient client.Client, test Namespace: testNamespace, }, Spec: corev1.ServiceSpec{ - Ports: []corev1.ServicePort{{Name: "mgmt-api-http", Port: int32(8080)}}, - Selector: map[string]string{ - cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(cassandraClusterName), - cassdcapi.DatacenterLabel: cassandraDatacenterName, - }, + Ports: []corev1.ServicePort{{Name: "mgmt-api-http", Port: int32(8080)}}, + Selector: cassdc.GetDatacenterLabels(), }, } err = k8sClient.Create(ctx, service) diff --git a/pkg/cassandra/management.go b/pkg/cassandra/management.go index e4a060453..7d38d9f0d 100644 --- a/pkg/cassandra/management.go +++ b/pkg/cassandra/management.go @@ -135,9 +135,7 @@ func (r *defaultManagementApiFacade) CreateKeyspaceIfNotExists( func (r *defaultManagementApiFacade) fetchDatacenterPods() ([]corev1.Pod, error) { podList := &corev1.PodList{} - labels := client.MatchingLabels{ - cassdcapi.DatacenterLabel: cassdcapi.CleanLabelValue(r.dc.Name), - cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(r.dc.Spec.ClusterName)} + labels := client.MatchingLabels(r.dc.GetDatacenterLabels()) if err := r.k8sClient.List(r.ctx, podList, labels); err != nil { return nil, err } else { diff --git a/pkg/medusa/utils.go b/pkg/medusa/utils.go index ad8f94592..6531f5e0e 100644 --- a/pkg/medusa/utils.go +++ b/pkg/medusa/utils.go @@ -12,10 +12,7 @@ import ( func GetCassandraDatacenterPods(ctx context.Context, cassdc *cassdcapi.CassandraDatacenter, r client.Reader, logger logr.Logger) ([]corev1.Pod, error) { podList := &corev1.PodList{} - labels := client.MatchingLabels{ - cassdcapi.ClusterLabel: cassdcapi.CleanLabelValue(cassdc.Spec.ClusterName), - cassdcapi.DatacenterLabel: cassdc.Name, - } + labels := client.MatchingLabels(cassdc.GetDatacenterLabels()) 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()) return nil, err diff --git a/test/e2e/suite_test.go b/test/e2e/suite_test.go index c0628b1c9..49085330d 100644 --- a/test/e2e/suite_test.go +++ b/test/e2e/suite_test.go @@ -2144,7 +2144,7 @@ func DcPrefix( cassdc := &cassdcapi.CassandraDatacenter{} err := f.Get(context.Background(), dcKey, cassdc) require.NoError(t, err) - return framework.CleanupForKubernetes(fmt.Sprintf("%s-%s", cassdc.Spec.ClusterName, cassdc.Name)) + return framework.CleanupForKubernetes(fmt.Sprintf("%s-%s", cassdc.Spec.ClusterName, cassdc.DatacenterName())) } func DcClusterName(