diff --git a/CHANGELOG.md b/CHANGELOG.md index 3753ec27..516fcccc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,7 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti * [CHANGE] [#618](https://github.com/k8ssandra/cass-operator/issues/618) Update dependencies to support controller-runtime 0.17.2, modify required parts. * [ENHANCEMENT] [#532](https://github.com/k8ssandra/cass-operator/issues/532) Instead of rejecting updates/creates with deprecated fields, return kubectl warnings. +* [BUGFIX] [#622](https://github.com/k8ssandra/cass-operator/issues/622) Fix sanitization of DC label ## v1.19.0 diff --git a/apis/cassandra/v1beta1/cassandradatacenter_types.go b/apis/cassandra/v1beta1/cassandradatacenter_types.go index 23c0af57..97a52be7 100644 --- a/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -570,7 +570,7 @@ func (dc *CassandraDatacenter) SetCondition(condition DatacenterCondition) { // GetDatacenterLabels ... func (dc *CassandraDatacenter) GetDatacenterLabels() map[string]string { labels := dc.GetClusterLabels() - labels[DatacenterLabel] = dc.SanitizedName() + labels[DatacenterLabel] = CleanLabelValue(dc.DatacenterName()) return labels } diff --git a/pkg/reconciliation/construct_statefulset_test.go b/pkg/reconciliation/construct_statefulset_test.go index 0d6d1760..09c29ea9 100644 --- a/pkg/reconciliation/construct_statefulset_test.go +++ b/pkg/reconciliation/construct_statefulset_test.go @@ -637,7 +637,7 @@ func Test_newStatefulSetForCassandraDatacenter_dcNameOverride(t *testing.T) { oplabels.NameLabel: oplabels.NameLabelValue, oplabels.CreatedByLabel: oplabels.CreatedByLabelValue, oplabels.VersionLabel: "4.0.1", - api.DatacenterLabel: "mysuperdc", + api.DatacenterLabel: "MySuperDC", api.ClusterLabel: "piclem", api.RackLabel: dc.Spec.Racks[0].Name, } @@ -648,7 +648,7 @@ func Test_newStatefulSetForCassandraDatacenter_dcNameOverride(t *testing.T) { oplabels.NameLabel: oplabels.NameLabelValue, oplabels.CreatedByLabel: oplabels.CreatedByLabelValue, oplabels.VersionLabel: "4.0.1", - api.DatacenterLabel: "mysuperdc", + api.DatacenterLabel: "MySuperDC", api.ClusterLabel: "piclem", api.RackLabel: dc.Spec.Racks[0].Name, api.CassNodeState: stateReadyToStart, diff --git a/pkg/reconciliation/reconcile_datacenter.go b/pkg/reconciliation/reconcile_datacenter.go index d9ff927e..56b9cfb3 100644 --- a/pkg/reconciliation/reconcile_datacenter.go +++ b/pkg/reconciliation/reconcile_datacenter.go @@ -144,7 +144,7 @@ func (rc *ReconciliationContext) listPVCs() (*corev1.PersistentVolumeClaimList, rc.ReqLogger.Info("reconciler::listPVCs") selector := map[string]string{ - api.DatacenterLabel: rc.Datacenter.Name, + api.DatacenterLabel: api.CleanLabelValue(rc.Datacenter.DatacenterName()), } listOptions := &client.ListOptions{ diff --git a/tests/decommission_dc/decommission_dc_suite_test.go b/tests/decommission_dc/decommission_dc_suite_test.go index 4958858d..7aa3c746 100644 --- a/tests/decommission_dc/decommission_dc_suite_test.go +++ b/tests/decommission_dc/decommission_dc_suite_test.go @@ -24,7 +24,7 @@ var ( dc2Name = "dc2" dc1Yaml = "../testdata/default-two-rack-two-node-dc.yaml" dc2Yaml = "../testdata/default-two-rack-two-node-dc2.yaml" - dc1Label = fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanupForKubernetes(dc1OverrideName)) + dc1Label = fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanLabelValue(dc1OverrideName)) dc2Label = fmt.Sprintf("cassandra.datastax.com/datacenter=%s", dc2Name) seedLabel = "cassandra.datastax.com/seed-node=true" taskYaml = "../testdata/tasks/rebuild_task.yaml" diff --git a/tests/rolling_restart_with_override/rolling_restart_suite_with_override_test.go b/tests/rolling_restart_with_override/rolling_restart_suite_with_override_test.go index 0f6d4829..99b73826 100644 --- a/tests/rolling_restart_with_override/rolling_restart_suite_with_override_test.go +++ b/tests/rolling_restart_with_override/rolling_restart_suite_with_override_test.go @@ -86,7 +86,7 @@ var _ = Describe(testName, func() { step = "get ready pods" json = "jsonpath={.items[*].status.containerStatuses[0].ready}" k = kubectl.Get("pods"). - WithLabel(fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanupForKubernetes(dcNameOverride))). + WithLabel(fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanLabelValue(dcNameOverride))). WithFlag("field-selector", "status.phase=Running"). FormatOutput(json) @@ -105,7 +105,7 @@ var _ = Describe(testName, func() { // Verify each pod does have the annotation.. json := `jsonpath={.items[0].metadata.annotations.control\.k8ssandra\.io/restartedAt}` k = kubectl.Get("pods"). - WithLabel(fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanupForKubernetes(dcNameOverride))). + WithLabel(fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanLabelValue(dcNameOverride))). WithFlag("field-selector", "status.phase=Running"). FormatOutput(json) ns.WaitForOutputPatternAndLog(step, k, `^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$`, 360) diff --git a/tests/test_all_the_things/test_all_the_things_suite_test.go b/tests/test_all_the_things/test_all_the_things_suite_test.go index 68946e5a..ef0ccac4 100644 --- a/tests/test_all_the_things/test_all_the_things_suite_test.go +++ b/tests/test_all_the_things/test_all_the_things_suite_test.go @@ -28,7 +28,7 @@ var ( dcNameOverride = "My_Super_Dc" dcYaml = "../testdata/default-two-rack-two-node-dc.yaml" dcResource = fmt.Sprintf("CassandraDatacenter/%s", dcName) - dcLabel = fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanupForKubernetes(dcNameOverride)) + dcLabel = fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanLabelValue(dcNameOverride)) ns = ginkgo_util.NewWrapper(testName, namespace) ) @@ -89,7 +89,7 @@ var _ = Describe(testName, func() { ns.WaitForDatacenterOperatorProgress(dcName, "Updating", 60) ns.WaitForDatacenterConditionWithTimeout(dcName, "ScalingUp", string(corev1.ConditionFalse), 1200) // Ensure that when 'ScaleUp' becomes 'false' that our pods are in fact up and running - Expect(len(ns.GetDatacenterReadyPodNames(api.CleanupForKubernetes(dcNameOverride)))).To(Equal(4)) + Expect(len(ns.GetDatacenterReadyPodNames(api.CleanLabelValue(dcNameOverride)))).To(Equal(4)) ns.ExpectDoneReconciling(dcName) ns.WaitForDatacenterReady(dcName) @@ -114,7 +114,7 @@ var _ = Describe(testName, func() { FormatOutput(json) ns.WaitForOutputAndLog(step, k, "4", 20) - ns.WaitForDatacenterToHaveNoPods(api.CleanupForKubernetes(dcNameOverride)) + ns.WaitForDatacenterToHaveNoPods(api.CleanLabelValue(dcNameOverride)) step = "resume the dc" json = "{\"spec\": {\"stopped\": false}}" @@ -148,7 +148,7 @@ var _ = Describe(testName, func() { found, err := regexp.MatchString("node/drain status=200 OK", logOutput) if err == nil && !found { - ns.Log(fmt.Sprintf("logOutput, pod: statefulset.kubernetes.io/pod-name=cluster1-%s-r1-sts-0 => %s", api.CleanupForKubernetes(dcNameOverride), logOutput)) + ns.Log(fmt.Sprintf("logOutput, pod: statefulset.kubernetes.io/pod-name=cluster1-%s-r1-sts-0 => %s", api.CleanLabelValue(dcNameOverride), logOutput)) } if err != nil { ns.Log(fmt.Sprintf("Regexp parsing failed: %v", err)) diff --git a/tests/util/ginkgo/lib.go b/tests/util/ginkgo/lib.go index a4553582..e94f38b4 100644 --- a/tests/util/ginkgo/lib.go +++ b/tests/util/ginkgo/lib.go @@ -409,7 +409,7 @@ func (ns *NsWrapper) WaitForDatacenterReadyPodCountWithTimeout(dcName string, co step := "waiting for the node to become ready" json := "jsonpath={.items[*].status.containerStatuses[0].ready}" k := kubectl.Get("pods"). - WithLabel(fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanupForKubernetes(dcName))). + WithLabel(fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanLabelValue(dcName))). WithFlag("field-selector", "status.phase=Running"). FormatOutput(json) ns.WaitForOutputAndLog(step, k, duplicate("true", count), timeout) @@ -516,7 +516,7 @@ func (ns *NsWrapper) GetDatacenterPodNames(dcName string) []string { func (ns *NsWrapper) GetDatacenterReadyPodNames(dcName string) []string { json := "jsonpath={.items[?(@.status.containerStatuses[0].ready==true)].metadata.name}" k := kubectl.Get("pods"). - WithFlag("selector", fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanupForKubernetes(dcName))). + WithFlag("selector", fmt.Sprintf("cassandra.datastax.com/datacenter=%s", api.CleanLabelValue(dcName))). FormatOutput(json) output := ns.OutputPanic(k)