From db761a979c61b01c4d33feddcb5616a4b16bb689 Mon Sep 17 00:00:00 2001 From: myname4423 <57184070+myname4423@users.noreply.github.com> Date: Tue, 25 Jun 2024 14:58:53 +0800 Subject: [PATCH] add 2 fields to status to support showing result of kubectl get (#220) Signed-off-by: yunbo Co-authored-by: yunbo --- api/v1beta1/rollout_types.go | 11 +++++++++-- .../crd/bases/rollouts.kruise.io_rollouts.yaml | 15 +++++++++++++-- pkg/controller/rollout/rollout_progressing.go | 2 ++ .../rollout/rollout_progressing_test.go | 18 ++++++++++++++++++ pkg/controller/rollout/rollout_status.go | 4 ++++ 5 files changed, 46 insertions(+), 4 deletions(-) diff --git a/api/v1beta1/rollout_types.go b/api/v1beta1/rollout_types.go index 9f074597..02c0af66 100644 --- a/api/v1beta1/rollout_types.go +++ b/api/v1beta1/rollout_types.go @@ -308,6 +308,10 @@ type RolloutStatus struct { Phase RolloutPhase `json:"phase,omitempty"` // Message provides details on why the rollout is in its current phase Message string `json:"message,omitempty"` + // These two values will be synchronized with the same fileds in CanaryStatus or BlueGreeenStatus + // mainly used to provide info for kubectl get command + CurrentStepIndex int32 `json:"currentStepIndex"` + CurrentStepState CanaryStepState `json:"currentStepState"` } // RolloutCondition describes the state of a rollout at a certain point. @@ -430,6 +434,9 @@ type BlueGreenStatus struct { // GetSubStatus returns the ethier canary or bluegreen status func (r *RolloutStatus) GetSubStatus() *CommonStatus { + if r.CanaryStatus == nil && r.BlueGreenStatus == nil { + return nil + } if r.CanaryStatus != nil { return &(r.CanaryStatus.CommonStatus) } @@ -559,8 +566,8 @@ const ( //+kubebuilder:subresource:status // +kubebuilder:storageversion // +kubebuilder:printcolumn:name="STATUS",type="string",JSONPath=".status.phase",description="The rollout status phase" -// +kubebuilder:printcolumn:name="CANARY_STEP",type="integer",JSONPath=".status.canaryStatus.currentStepIndex",description="The rollout canary status step" -// +kubebuilder:printcolumn:name="CANARY_STATE",type="string",JSONPath=".status.canaryStatus.currentStepState",description="The rollout canary status step state" +// +kubebuilder:printcolumn:name="CANARY_STEP",type="integer",JSONPath=".status.currentStepIndex",description="The rollout canary status step" +// +kubebuilder:printcolumn:name="CANARY_STATE",type="string",JSONPath=".status.currentStepState",description="The rollout canary status step state" // +kubebuilder:printcolumn:name="MESSAGE",type="string",JSONPath=".status.message",description="The rollout canary status message" // +kubebuilder:printcolumn:name="AGE",type=date,JSONPath=".metadata.creationTimestamp" diff --git a/config/crd/bases/rollouts.kruise.io_rollouts.yaml b/config/crd/bases/rollouts.kruise.io_rollouts.yaml index 4c1b8743..fe1a7fdc 100644 --- a/config/crd/bases/rollouts.kruise.io_rollouts.yaml +++ b/config/crd/bases/rollouts.kruise.io_rollouts.yaml @@ -548,11 +548,11 @@ spec: name: STATUS type: string - description: The rollout canary status step - jsonPath: .status.canaryStatus.currentStepIndex + jsonPath: .status.currentStepIndex name: CANARY_STEP type: integer - description: The rollout canary status step state - jsonPath: .status.canaryStatus.currentStepState + jsonPath: .status.currentStepState name: CANARY_STATE type: string - description: The rollout canary status message @@ -1594,6 +1594,14 @@ spec: - type type: object type: array + currentStepIndex: + description: These two values will be synchronized with the same fileds + in CanaryStatus or BlueGreeenStatus mainly used to provide info + for kubectl get command + format: int32 + type: integer + currentStepState: + type: string message: description: Message provides details on why the rollout is in its current phase @@ -1607,6 +1615,9 @@ spec: description: BlueGreenStatus *BlueGreenStatus `json:"blueGreenStatus,omitempty"` Phase is the rollout phase. type: string + required: + - currentStepIndex + - currentStepState type: object type: object served: true diff --git a/pkg/controller/rollout/rollout_progressing.go b/pkg/controller/rollout/rollout_progressing.go index 24f9943b..2e6512a3 100644 --- a/pkg/controller/rollout/rollout_progressing.go +++ b/pkg/controller/rollout/rollout_progressing.go @@ -78,6 +78,8 @@ func (r *RolloutReconciler) reconcileRolloutProgressing(rollout *v1beta1.Rollout CurrentStepState: v1beta1.CanaryStepStateInit, LastUpdateTime: &metav1.Time{Time: time.Now()}, } + newStatus.CurrentStepIndex = commonStatus.CurrentStepIndex + newStatus.CurrentStepState = commonStatus.CurrentStepState if rollout.Spec.Strategy.IsBlueGreenRelease() { newStatus.BlueGreenStatus = &v1beta1.BlueGreenStatus{ CommonStatus: commonStatus, diff --git a/pkg/controller/rollout/rollout_progressing_test.go b/pkg/controller/rollout/rollout_progressing_test.go index 6513faff..51246c14 100644 --- a/pkg/controller/rollout/rollout_progressing_test.go +++ b/pkg/controller/rollout/rollout_progressing_test.go @@ -72,6 +72,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { s.CanaryStatus.NextStepIndex = 2 // now the first step is no longer StepStateUpgrade, it is StepStateInit now s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateInit + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, expectTr: func() *v1alpha1.TrafficRouting { @@ -108,6 +110,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(s, *cond) + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, }, @@ -165,6 +169,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonInRolling util.SetRolloutCondition(s, *cond) + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, }, @@ -223,6 +229,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { cond.Reason = v1alpha1.ProgressingReasonFinalising cond.Status = corev1.ConditionTrue util.SetRolloutCondition(s, *cond) + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, }, @@ -282,6 +290,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { cond.Reason = v1alpha1.ProgressingReasonFinalising cond.Status = corev1.ConditionTrue util.SetRolloutCondition(s, *cond) + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, expectTr: func() *v1alpha1.TrafficRouting { @@ -343,6 +353,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { cond2.Reason = v1alpha1.ProgressingReasonFinalising cond2.Status = corev1.ConditionTrue util.SetRolloutCondition(s, *cond2) + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, }, @@ -397,6 +409,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { cond1.LastUpdateTime = metav1.Time{} cond1.LastTransitionTime = metav1.Time{} util.SetRolloutCondition(s, *cond1) + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, }, @@ -454,6 +468,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonCancelling util.SetRolloutCondition(s, *cond) + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, }, @@ -511,6 +527,8 @@ func TestReconcileRolloutProgressing(t *testing.T) { cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing) cond.Reason = v1alpha1.ProgressingReasonCancelling util.SetRolloutCondition(s, *cond) + s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex + s.CurrentStepState = s.CanaryStatus.CurrentStepState return s }, }, diff --git a/pkg/controller/rollout/rollout_status.go b/pkg/controller/rollout/rollout_status.go index dbd0f103..69a13d07 100755 --- a/pkg/controller/rollout/rollout_status.go +++ b/pkg/controller/rollout/rollout_status.go @@ -204,6 +204,10 @@ func (r *RolloutReconciler) calculateRolloutHash(rollout *v1beta1.Rollout) error } func (r *RolloutReconciler) updateRolloutStatusInternal(rollout *v1beta1.Rollout, newStatus v1beta1.RolloutStatus) error { + if newStatus.GetSubStatus() != nil { + newStatus.CurrentStepIndex = newStatus.GetSubStatus().CurrentStepIndex + newStatus.CurrentStepState = newStatus.GetSubStatus().CurrentStepState + } if reflect.DeepEqual(rollout.Status, newStatus) { return nil }