From 5de8d7f809e2e79b65262debb735c3f1ba7f694e Mon Sep 17 00:00:00 2001 From: Michael Burman Date: Mon, 15 Apr 2024 16:38:49 +0300 Subject: [PATCH] Rename allow-update to cassandra.datastax.com/autoupdate-spec to indicate any automated change of StatefulSet spec --- CHANGELOG.md | 2 +- apis/cassandra/v1beta1/cassandradatacenter_types.go | 9 +++++++-- .../v1beta1/cassandradatacenter_webhook.go | 13 +++++++------ apis/cassandra/v1beta1/webhook_test.go | 6 +++--- pkg/reconciliation/constructor.go | 2 +- pkg/reconciliation/reconcile_racks_test.go | 2 +- .../upgrade_operator/upgrade_operator_suite_test.go | 4 ++-- 7 files changed, 22 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3cb5331..d975cd36 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ Changelog for Cass Operator, new PRs should update the `main / unreleased` secti ## unreleased -* [CHANGE] [#566](https://github.com/k8ssandra/cass-operator/issues/566) BREAKING: StatefulSets will no longer be updated if CassandraDatacenter is not modified, unless an annotation "cassandra.datastax.com/allow-upgrade" is set to the CassandraDatacenter with value "always" or "once". This means users of config secret should set this variable to "always" to keep their existing behavior. For other users, this means that the upgrades of operator will no longer automatically apply updated settings or system-logger image. The benefit is that updating the operator no longer causes the cluster to have a rolling restart. A new condition to indicate such change could be necessary is called "RequiresUpdate" and it will be set to True until the next refresh of reconcile has happened. +* [CHANGE] [#566](https://github.com/k8ssandra/cass-operator/issues/566) BREAKING: StatefulSets will no longer be automatically updated if CassandraDatacenter is not modified, unless an annotation "cassandra.datastax.com/autoupdate-spec" is set to the CassandraDatacenter with value "always" or "once". This means users of config secret should set this variable to "always" to keep their existing behavior. For other users, this means that for example the upgrades of operator will no longer automatically apply updated settings or system-logger image. The benefit is that updating the operator no longer causes the cluster to have a rolling restart. A new condition to indicate such change could be necessary is called "RequiresUpdate" and it will be set to True until the next refresh of reconcile has happened. * [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. diff --git a/apis/cassandra/v1beta1/cassandradatacenter_types.go b/apis/cassandra/v1beta1/cassandradatacenter_types.go index 3a00f39f..e2d17732 100644 --- a/apis/cassandra/v1beta1/cassandradatacenter_types.go +++ b/apis/cassandra/v1beta1/cassandradatacenter_types.go @@ -65,8 +65,11 @@ const ( // cluster has gone through scale up operation. NoAutomatedCleanupAnnotation = "cassandra.datastax.com/no-cleanup" - // UpdateAllowedAnnotation marks the Datacenter to allow upgrades to StatefulSets even if CassandraDatacenter object was not modified. Allowed values are "once" and "always" - UpdateAllowedAnnotation = "cassandra.datastax.com/allow-upgrade" + // UpdateAllowedAnnotation marks the Datacenter to allow upgrades to StatefulSets Spec even if CassandraDatacenter object was not modified. Allowed values are "once" and "always" + UpdateAllowedAnnotation = "cassandra.datastax.com/autoupdate-spec" + + AllowUpdateAlways AllowUpdateType = "always" + AllowUpdateOnce AllowUpdateType = "once" CassNodeState = "cassandra.datastax.com/node-state" @@ -77,6 +80,8 @@ const ( DefaultInternodePort = 7000 ) +type AllowUpdateType string + // ProgressState - this type exists so there's no chance of pushing random strings to our progress status type ProgressState string diff --git a/apis/cassandra/v1beta1/cassandradatacenter_webhook.go b/apis/cassandra/v1beta1/cassandradatacenter_webhook.go index e7029c9a..bacf3379 100644 --- a/apis/cassandra/v1beta1/cassandradatacenter_webhook.go +++ b/apis/cassandra/v1beta1/cassandradatacenter_webhook.go @@ -140,12 +140,6 @@ func ValidateSingleDatacenter(dc CassandraDatacenter) error { return err } - if metav1.HasAnnotation(dc.ObjectMeta, UpdateAllowedAnnotation) { - if dc.Annotations[UpdateAllowedAnnotation] != "once" && dc.Annotations[UpdateAllowedAnnotation] != "always" { - return attemptedTo("use %s annotation with value other than 'once' or 'always'", UpdateAllowedAnnotation) - } - } - return ValidateFQLConfig(dc) } @@ -343,6 +337,13 @@ func ValidateServiceLabelsAndAnnotations(dc CassandraDatacenter) error { } } + if metav1.HasAnnotation(dc.ObjectMeta, UpdateAllowedAnnotation) { + updateType := AllowUpdateType(dc.Annotations[UpdateAllowedAnnotation]) + if updateType != AllowUpdateAlways && updateType != AllowUpdateOnce { + return attemptedTo("use %s annotation with value other than 'once' or 'always'", UpdateAllowedAnnotation) + } + } + return nil } diff --git a/apis/cassandra/v1beta1/webhook_test.go b/apis/cassandra/v1beta1/webhook_test.go index 4637f5f6..c7210ce1 100644 --- a/apis/cassandra/v1beta1/webhook_test.go +++ b/apis/cassandra/v1beta1/webhook_test.go @@ -324,7 +324,7 @@ func Test_ValidateSingleDatacenter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "exampleDC", Annotations: map[string]string{ - "cassandra.datastax.com/allow-upgrade": "invalid", + "cassandra.datastax.com/autoupdate-spec": "invalid", }, }, Spec: CassandraDatacenterSpec{ @@ -332,7 +332,7 @@ func Test_ValidateSingleDatacenter(t *testing.T) { ServerVersion: "6.8.42", }, }, - errString: "use cassandra.datastax.com/allow-upgrade annotation with value other than 'once' or 'always'", + errString: "use cassandra.datastax.com/autoupdate-spec annotation with value other than 'once' or 'always'", }, { name: "Allow upgrade should accept once value", @@ -340,7 +340,7 @@ func Test_ValidateSingleDatacenter(t *testing.T) { ObjectMeta: metav1.ObjectMeta{ Name: "exampleDC", Annotations: map[string]string{ - "cassandra.datastax.com/allow-upgrade": "once", + "cassandra.datastax.com/autoupdate-spec": "once", }, }, Spec: CassandraDatacenterSpec{ diff --git a/pkg/reconciliation/constructor.go b/pkg/reconciliation/constructor.go index 3e034e79..bbd3dad5 100644 --- a/pkg/reconciliation/constructor.go +++ b/pkg/reconciliation/constructor.go @@ -71,7 +71,7 @@ func setOperatorProgressStatus(rc *ReconciliationContext, newState api.ProgressS } // The allow-upgrade=once annotation is temporary and should be removed after first successful reconcile - if metav1.HasAnnotation(rc.Datacenter.ObjectMeta, api.UpdateAllowedAnnotation) && rc.Datacenter.Annotations[api.UpdateAllowedAnnotation] == "once" { + if metav1.HasAnnotation(rc.Datacenter.ObjectMeta, api.UpdateAllowedAnnotation) && rc.Datacenter.Annotations[api.UpdateAllowedAnnotation] == string(api.AllowUpdateOnce) { // remove the annotation patch = client.MergeFrom(rc.Datacenter.DeepCopy()) delete(rc.Datacenter.ObjectMeta.Annotations, api.UpdateAllowedAnnotation) diff --git a/pkg/reconciliation/reconcile_racks_test.go b/pkg/reconciliation/reconcile_racks_test.go index 118ef796..6f9c28d9 100644 --- a/pkg/reconciliation/reconcile_racks_test.go +++ b/pkg/reconciliation/reconcile_racks_test.go @@ -371,7 +371,7 @@ func TestCheckRackPodTemplate_GenerationCheck(t *testing.T) { assert.Equal(corev1.ConditionTrue, cond.Status) // Add annotation - metav1.SetMetaDataAnnotation(&rc.Datacenter.ObjectMeta, api.UpdateAllowedAnnotation, "always") + metav1.SetMetaDataAnnotation(&rc.Datacenter.ObjectMeta, api.UpdateAllowedAnnotation, string(api.AllowUpdateAlways)) rc.Datacenter.Spec.ServerVersion = "6.8.44" // This needs to be reapplied, since we call Patch in the CheckRackPodTemplate() res = rc.CheckRackPodTemplate() diff --git a/tests/upgrade_operator/upgrade_operator_suite_test.go b/tests/upgrade_operator/upgrade_operator_suite_test.go index 60d44656..6a8eafd4 100644 --- a/tests/upgrade_operator/upgrade_operator_suite_test.go +++ b/tests/upgrade_operator/upgrade_operator_suite_test.go @@ -126,7 +126,7 @@ var _ = Describe(testName, func() { // Add annotation to allow upgrade to update the StatefulSets step = "add annotation to allow upgrade" - json = "{\"metadata\": {\"annotations\": {\"cassandra.datastax.com/allow-upgrade\": \"once\"}}}" + json = "{\"metadata\": {\"annotations\": {\"cassandra.datastax.com/autoupdate-spec\": \"once\"}}}" k = kubectl.PatchMerge(dcResource, json) ns.ExecAndLog(step, k) @@ -152,7 +152,7 @@ var _ = Describe(testName, func() { step = "get CassandraDatacenter allow-upgrade annotation" k = kubectl.Get("CassandraDatacenter", dcName).FormatOutput("jsonpath={.metadata.annotations}") annotations := ns.OutputAndLog(step, k) - Expect(annotations).To(Not(ContainSubstring("cassandra.datastax.com/allow-upgrade"))) + Expect(annotations).To(Not(ContainSubstring("cassandra.datastax.com/autoupdate-spec"))) // Verify delete still works correctly and that we won't leave any resources behind step = "deleting the dc"