From ba359f32a43b9af1e52657c6c0406777675e1b32 Mon Sep 17 00:00:00 2001 From: yunbo Date: Wed, 29 May 2024 15:39:08 +0800 Subject: [PATCH] add status conversion Signed-off-by: yunbo --- api/v1alpha1/conversion.go | 4 ++++ api/v1alpha1/rollout_types.go | 8 ++++++++ api/v1beta1/rollout_types.go | 20 +++++++++---------- .../bases/rollouts.kruise.io_rollouts.yaml | 12 +++++++++++ pkg/controller/rollout/rollout_progressing.go | 2 +- pkg/controller/rollout/rollout_status.go | 2 +- 6 files changed, 35 insertions(+), 13 deletions(-) diff --git a/api/v1alpha1/conversion.go b/api/v1alpha1/conversion.go index 13b98b2..6872c91 100644 --- a/api/v1alpha1/conversion.go +++ b/api/v1alpha1/conversion.go @@ -114,6 +114,8 @@ func (src *Rollout) ConvertTo(dst conversion.Hub) error { CurrentStepState: v1beta1.CanaryStepState(src.Status.CanaryStatus.CurrentStepState), Message: src.Status.CanaryStatus.Message, LastUpdateTime: src.Status.CanaryStatus.LastUpdateTime, + FinalisingStep: v1beta1.FinalisingStepType(src.Status.CanaryStatus.FinalisingStep), + NextStepIndex: src.Status.CanaryStatus.NextStepIndex, }, CanaryRevision: src.Status.CanaryStatus.CanaryRevision, CanaryReplicas: src.Status.CanaryStatus.CanaryReplicas, @@ -258,6 +260,8 @@ func (dst *Rollout) ConvertFrom(src conversion.Hub) error { CurrentStepState: CanaryStepState(srcV1beta1.Status.CanaryStatus.CurrentStepState), Message: srcV1beta1.Status.CanaryStatus.Message, LastUpdateTime: srcV1beta1.Status.CanaryStatus.LastUpdateTime, + FinalisingStep: FinalizeStateType(srcV1beta1.Status.CanaryStatus.FinalisingStep), + NextStepIndex: srcV1beta1.Status.CanaryStatus.NextStepIndex, } return nil default: diff --git a/api/v1alpha1/rollout_types.go b/api/v1alpha1/rollout_types.go index 39b6ca5..df3fa93 100644 --- a/api/v1alpha1/rollout_types.go +++ b/api/v1alpha1/rollout_types.go @@ -242,6 +242,14 @@ type CanaryStatus struct { CanaryReplicas int32 `json:"canaryReplicas"` // CanaryReadyReplicas the numbers of ready canary revision pods CanaryReadyReplicas int32 `json:"canaryReadyReplicas"` + // NextStepIndex defines the next step of the rollout is on. + // In normal case, NextStepIndex is equal to CurrentStepIndex + 1 + // If the current step is the last step, NextStepIndex is equal to 0 + // Before the release, NextStepIndex is also equal to 0 + // It is allowed to modify NextStepIndex by design, + // e.g. if CurrentStepIndex is 2, user can patch NextStepIndex to 3 (if exists) to + // achieve batch jump, or patch NextStepIndex to 1 to implement a re-execution of step 1 + NextStepIndex int32 `json:"nextStepIndex"` // +optional CurrentStepIndex int32 `json:"currentStepIndex"` CurrentStepState CanaryStepState `json:"currentStepState"` diff --git a/api/v1beta1/rollout_types.go b/api/v1beta1/rollout_types.go index 9d6b548..d1b7b75 100644 --- a/api/v1beta1/rollout_types.go +++ b/api/v1beta1/rollout_types.go @@ -369,10 +369,12 @@ type CommonStatus struct { // It is allowed to modify NextStepIndex by design, // e.g. if CurrentStepIndex is 2, user can patch NextStepIndex to 3 (if exists) to // achieve batch jump, or patch NextStepIndex to 1 to implement a re-execution of step 1 - NextStepIndex int32 `json:"nextStepIndex"` - CurrentStepState CanaryStepState `json:"currentStepState"` - Message string `json:"message,omitempty"` - LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"` + NextStepIndex int32 `json:"nextStepIndex"` + // FinalisingStep the step of finalising + FinalisingStep FinalisingStepType `json:"finalisingStep"` + CurrentStepState CanaryStepState `json:"currentStepState"` + Message string `json:"message,omitempty"` + LastUpdateTime *metav1.Time `json:"lastUpdateTime,omitempty"` } // CanaryStatus status fields that only pertain to the canary rollout @@ -386,8 +388,6 @@ type CanaryStatus struct { CanaryReplicas int32 `json:"canaryReplicas"` // CanaryReadyReplicas the numbers of ready canary revision pods CanaryReadyReplicas int32 `json:"canaryReadyReplicas"` - // FinalisingStep the step of finalising - FinalisingStep FinalisingStepType `json:"finalisingStep"` } // BlueGreenStatus status fields that only pertain to the blueGreen rollout @@ -395,13 +395,11 @@ type BlueGreenStatus struct { CommonStatus `json:",inline"` // CanaryRevision is calculated by rollout based on podTemplateHash, and the internal logic flow uses // It may be different from rs podTemplateHash in different k8s versions, so it cannot be used as service selector label - CanaryRevision string `json:"updatedRevision"` + UpdatedRevision string `json:"updatedRevision"` // UpdatedReplicas the numbers of updated pods UpdatedReplicas int32 `json:"updatedReplicas"` // UpdatedReadyReplicas the numbers of updated ready pods UpdatedReadyReplicas int32 `json:"updatedReadyReplicas"` - // FinalisingStep the step of finalising - FinalisingStep FinalisingStepType `json:"finalisingStep"` } // GetSubStatus returns the ethier canary or bluegreen status @@ -427,7 +425,7 @@ func (r *RolloutStatus) GetCanaryRevision() string { if r.CanaryStatus != nil { return r.CanaryStatus.CanaryRevision } - return r.BlueGreenStatus.CanaryRevision + return r.BlueGreenStatus.UpdatedRevision } func (r *RolloutStatus) SetCanaryRevision(revision string) { @@ -435,7 +433,7 @@ func (r *RolloutStatus) SetCanaryRevision(revision string) { r.CanaryStatus.CanaryRevision = revision } if r.BlueGreenStatus != nil { - r.BlueGreenStatus.CanaryRevision = revision + r.BlueGreenStatus.UpdatedRevision = revision } } diff --git a/config/crd/bases/rollouts.kruise.io_rollouts.yaml b/config/crd/bases/rollouts.kruise.io_rollouts.yaml index 495d19d..f257c70 100644 --- a/config/crd/bases/rollouts.kruise.io_rollouts.yaml +++ b/config/crd/bases/rollouts.kruise.io_rollouts.yaml @@ -446,6 +446,17 @@ spec: type: string message: type: string + nextStepIndex: + description: NextStepIndex defines the next step of the rollout + is on. In normal case, NextStepIndex is equal to CurrentStepIndex + + 1 If the current step is the last step, NextStepIndex is equal + to 0 Before the release, NextStepIndex is also equal to 0 It + is allowed to modify NextStepIndex by design, e.g. if CurrentStepIndex + is 2, user can patch NextStepIndex to 3 (if exists) to achieve + batch jump, or patch NextStepIndex to 1 to implement a re-execution + of step 1 + format: int32 + type: integer observedRolloutID: description: ObservedRolloutID will record the newest spec.RolloutID if status.canaryRevision equals to workload.updateRevision @@ -470,6 +481,7 @@ spec: - canaryRevision - currentStepState - finalisingStep + - nextStepIndex - podTemplateHash type: object conditions: diff --git a/pkg/controller/rollout/rollout_progressing.go b/pkg/controller/rollout/rollout_progressing.go index 9eae32a..42b7eff 100644 --- a/pkg/controller/rollout/rollout_progressing.go +++ b/pkg/controller/rollout/rollout_progressing.go @@ -80,7 +80,7 @@ func (r *RolloutReconciler) reconcileRolloutProgressing(rollout *v1beta1.Rollout CurrentStepState: v1beta1.CanaryStepStateInit, LastUpdateTime: &metav1.Time{Time: time.Now()}, }, - CanaryRevision: rolloutContext.Workload.CanaryRevision, + UpdatedRevision: rolloutContext.Workload.CanaryRevision, } } else { newStatus.CanaryStatus = &v1beta1.CanaryStatus{ diff --git a/pkg/controller/rollout/rollout_status.go b/pkg/controller/rollout/rollout_status.go index c1c8a37..015bca1 100755 --- a/pkg/controller/rollout/rollout_status.go +++ b/pkg/controller/rollout/rollout_status.go @@ -135,7 +135,7 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1beta1.Rollout) (re CurrentStepState: v1beta1.CanaryStepStateCompleted, RolloutHash: rollout.Annotations[util.RolloutHashAnnotation], }, - CanaryRevision: workload.CanaryRevision, + UpdatedRevision: workload.CanaryRevision, } } else { newStatus.CanaryStatus = &v1beta1.CanaryStatus{