Skip to content

Commit

Permalink
Fix sanitization of DC label (fixes #622) (#623)
Browse files Browse the repository at this point in the history
  • Loading branch information
olim7t authored Mar 27, 2024
1 parent b1d1bde commit 66aa5f1
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion apis/cassandra/v1beta1/cassandradatacenter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions pkg/reconciliation/construct_statefulset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciliation/reconcile_datacenter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion tests/decommission_dc/decommission_dc_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions tests/test_all_the_things/test_all_the_things_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)

Expand Down Expand Up @@ -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)
Expand All @@ -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}}"
Expand Down Expand Up @@ -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))
Expand Down
4 changes: 2 additions & 2 deletions tests/util/ginkgo/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 66aa5f1

Please sign in to comment.