Skip to content

Commit

Permalink
operator: deprecate upgrading status field and replace with restarting
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaferraro committed Apr 20, 2022
1 parent cc27bc1 commit 8554629
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 23 deletions.
23 changes: 21 additions & 2 deletions src/go/k8s/apis/redpanda/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
34 changes: 17 additions & 17 deletions src/go/k8s/pkg/resources/statefulset_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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{
Expand All @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 8554629

Please sign in to comment.