Skip to content

Commit

Permalink
Rename allow-update to cassandra.datastax.com/autoupdate-spec to indi…
Browse files Browse the repository at this point in the history
…cate any automated change of StatefulSet spec
  • Loading branch information
burmanm committed Apr 15, 2024
1 parent 8810e38 commit 5de8d7f
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
9 changes: 7 additions & 2 deletions apis/cassandra/v1beta1/cassandradatacenter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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

Expand Down
13 changes: 7 additions & 6 deletions apis/cassandra/v1beta1/cassandradatacenter_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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
}

Expand Down
6 changes: 3 additions & 3 deletions apis/cassandra/v1beta1/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -324,23 +324,23 @@ 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{
ServerType: "dse",
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",
dc: &CassandraDatacenter{
ObjectMeta: metav1.ObjectMeta{
Name: "exampleDC",
Annotations: map[string]string{
"cassandra.datastax.com/allow-upgrade": "once",
"cassandra.datastax.com/autoupdate-spec": "once",
},
},
Spec: CassandraDatacenterSpec{
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciliation/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/reconciliation/reconcile_racks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions tests/upgrade_operator/upgrade_operator_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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"
Expand Down

0 comments on commit 5de8d7f

Please sign in to comment.