From 85546291c479f898f62238568d674bfcf0f017b1 Mon Sep 17 00:00:00 2001 From: nicolaferraro Date: Fri, 25 Mar 2022 11:34:39 +0100 Subject: [PATCH] operator: deprecate upgrading status field and replace with restarting --- .../apis/redpanda/v1alpha1/cluster_types.go | 23 +++++++++++-- .../redpanda.vectorized.io_clusters.yaml | 7 +++- .../cluster_controller_configuration.go | 6 ++-- .../k8s/pkg/resources/statefulset_update.go | 34 +++++++++---------- 4 files changed, 47 insertions(+), 23 deletions(-) diff --git a/src/go/k8s/apis/redpanda/v1alpha1/cluster_types.go b/src/go/k8s/apis/redpanda/v1alpha1/cluster_types.go index 7819942d3288..331613bfe421 100644 --- a/src/go/k8s/apis/redpanda/v1alpha1/cluster_types.go +++ b/src/go/k8s/apis/redpanda/v1alpha1/cluster_types.go @@ -283,9 +283,13 @@ type ClusterStatus struct { // Nodes of the provisioned redpanda nodes // +optional Nodes NodesList `json:"nodes,omitempty"` - // Indicates cluster is upgrading + // Indicates cluster is upgrading. // +optional - Upgrading bool `json:"upgrading"` + // Deprecated: replaced by "restarting" + DeprecatedUpgrading bool `json:"upgrading"` + // Indicates that a cluster is restarting due to an upgrade or a different reason + // +optional + Restarting bool `json:"restarting"` // Current version of the cluster. // +optional Version string `json:"version"` @@ -789,6 +793,21 @@ func (r *Cluster) IsSchemaRegistryMutualTLSEnabled() bool { r.Spec.Configuration.SchemaRegistry.TLS.RequireClientAuth } +// ClusterStatus + +// IsRestarting tells if the cluster is restarting due to a change in configuration or an upgrade in progress +func (s *ClusterStatus) IsRestarting() bool { + // Let's consider the old field for a transition period + return s.Restarting || s.DeprecatedUpgrading +} + +// SetRestarting sets the cluster as restarting +func (s *ClusterStatus) SetRestarting(restarting bool) { + s.Restarting = restarting + // keep deprecated upgrading field as some external tools may still rely on it + s.DeprecatedUpgrading = restarting +} + // TLSConfig is a generic TLS configuration type TLSConfig struct { Enabled bool `json:"enabled,omitempty"` diff --git a/src/go/k8s/config/crd/bases/redpanda.vectorized.io_clusters.yaml b/src/go/k8s/config/crd/bases/redpanda.vectorized.io_clusters.yaml index 1c9dc1f9ebad..008802ef0fbd 100644 --- a/src/go/k8s/config/crd/bases/redpanda.vectorized.io_clusters.yaml +++ b/src/go/k8s/config/crd/bases/redpanda.vectorized.io_clusters.yaml @@ -902,8 +902,13 @@ spec: description: Replicas show how many nodes are working in the cluster format: int32 type: integer + restarting: + description: Indicates that a cluster is restarting due to an upgrade + or a different reason + type: boolean upgrading: - description: Indicates cluster is upgrading + description: 'Indicates cluster is upgrading. Deprecated: replaced + by "restarting"' type: boolean version: description: Current version of the cluster. diff --git a/src/go/k8s/controllers/redpanda/cluster_controller_configuration.go b/src/go/k8s/controllers/redpanda/cluster_controller_configuration.go index fd670279223e..a8367198449e 100644 --- a/src/go/k8s/controllers/redpanda/cluster_controller_configuration.go +++ b/src/go/k8s/controllers/redpanda/cluster_controller_configuration.go @@ -303,16 +303,16 @@ func (r *ClusterReconciler) synchronizeStatusWithCluster( conditionData := mapStatusToCondition(status) conditionChanged := redpandaCluster.Status.SetCondition(conditionData.Type, conditionData.Status, conditionData.Reason, conditionData.Message) stsNeedsRestart := needsRestart(status) - if conditionChanged || (stsNeedsRestart && !redpandaCluster.Status.Upgrading) { + if conditionChanged || (stsNeedsRestart && !redpandaCluster.Status.IsRestarting()) { // Trigger restart here if needed if stsNeedsRestart { - redpandaCluster.Status.Upgrading = true + redpandaCluster.Status.SetRestarting(true) } log.Info("Updating configuration state for cluster", "status", conditionData.Status, "reason", conditionData.Reason, "message", conditionData.Message, - "upgrading", redpandaCluster.Status.Upgrading, + "restarting", redpandaCluster.Status.IsRestarting(), ) if err := r.Status().Update(ctx, redpandaCluster); err != nil { return nil, errorWithContext(err, "could not update condition on cluster") diff --git a/src/go/k8s/pkg/resources/statefulset_update.go b/src/go/k8s/pkg/resources/statefulset_update.go index 36b734512e47..4cd2d82e8c1e 100644 --- a/src/go/k8s/pkg/resources/statefulset_update.go +++ b/src/go/k8s/pkg/resources/statefulset_update.go @@ -44,13 +44,13 @@ var errRedpandaNotReady = errors.New("redpanda not ready") // CR by removing statefulset with orphans Pods. The stateful set is then recreated // and all Pods are restarted accordingly to the ordinal number. // -// The process maintains an Upgrading bool status that is set to true once the +// The process maintains an Restarting bool status that is set to true once the // generated stateful differentiate from the actual state. It is set back to // false when all pods are verified. // -// The steps are as follows: 1) check the Upgrading status or if the statefulset +// The steps are as follows: 1) check the Restarting status or if the statefulset // differentiate from the current stored statefulset definition 2) if true, -// set the Upgrading status to true and remove statefulset with the orphan Pods +// set the Restarting status to true and remove statefulset with the orphan Pods // 3) perform rolling update like removing Pods accordingly to theirs ordinal // number 4) requeue until the pod is in ready state 5) prior to a pod update // verify the previously updated pod and requeue as necessary. Currently, the @@ -67,7 +67,7 @@ func (r *StatefulSetResource) runUpdate( modified.Spec.Template.Annotations[CentralizedConfigurationHashAnnotationKey] = ann } - update, err := r.shouldUpdate(r.pandaCluster.Status.Upgrading, current, modified) + update, err := r.shouldUpdate(r.pandaCluster.Status.IsRestarting(), current, modified) if err != nil { return fmt.Errorf("unable to determine the update procedure: %w", err) } @@ -76,8 +76,8 @@ func (r *StatefulSetResource) runUpdate( return nil } - if err = r.updateUpgradingStatus(ctx, true); err != nil { - return fmt.Errorf("unable to turn on upgrading status in cluster custom resource: %w", err) + if err = r.updateRestartingStatus(ctx, true); err != nil { + return fmt.Errorf("unable to turn on restarting status in cluster custom resource: %w", err) } if err = r.updateStatefulSet(ctx, current, modified); err != nil { return err @@ -87,9 +87,9 @@ func (r *StatefulSetResource) runUpdate( return err } - // Update is complete for all pods (and all are ready). Set upgrading status to false. - if err = r.updateUpgradingStatus(ctx, false); err != nil { - return fmt.Errorf("unable to turn off upgrading status in cluster custom resource: %w", err) + // Update is complete for all pods (and all are ready). Set restarting status to false. + if err = r.updateRestartingStatus(ctx, false); err != nil { + return fmt.Errorf("unable to turn off restarting status in cluster custom resource: %w", err) } return nil @@ -196,7 +196,7 @@ func (r *StatefulSetResource) updateStatefulSet( // shouldUpdate returns true if changes on the CR require update func (r *StatefulSetResource) shouldUpdate( - isUpgrading bool, current, modified *appsv1.StatefulSet, + isRestarting bool, current, modified *appsv1.StatefulSet, ) (bool, error) { prepareResourceForPatch(current, modified) opts := []patch.CalculateOption{ @@ -209,16 +209,16 @@ func (r *StatefulSetResource) shouldUpdate( if err != nil { return false, err } - return !patchResult.IsEmpty() || isUpgrading, nil + return !patchResult.IsEmpty() || isRestarting, nil } -func (r *StatefulSetResource) updateUpgradingStatus( - ctx context.Context, upgrading bool, +func (r *StatefulSetResource) updateRestartingStatus( + ctx context.Context, restarting bool, ) error { - if !reflect.DeepEqual(upgrading, r.pandaCluster.Status.Upgrading) { - r.pandaCluster.Status.Upgrading = upgrading + if !reflect.DeepEqual(restarting, r.pandaCluster.Status.IsRestarting()) { + r.pandaCluster.Status.SetRestarting(restarting) r.logger.Info("Status updated", - "status", upgrading, + "restarting", restarting, "resource name", r.pandaCluster.Name) if err := r.Status().Update(ctx, r.pandaCluster); err != nil { return err @@ -370,7 +370,7 @@ func deleteKubernetesTokenVolumeMounts(obj []byte) ([]byte, error) { return obj, nil } -// Temporarily using the status/ready endpoint until we have a specific one for upgrading. +// Temporarily using the status/ready endpoint until we have a specific one for restarting. func (r *StatefulSetResource) queryRedpandaStatus( ctx context.Context, adminURL *url.URL, ) error {