Skip to content

Commit

Permalink
add 2 fields to status to support showing result of kubectl get (#220)
Browse files Browse the repository at this point in the history
Signed-off-by: yunbo <[email protected]>
Co-authored-by: yunbo <[email protected]>
  • Loading branch information
myname4423 and Funinu authored Jun 25, 2024
1 parent aa28f4e commit db761a9
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
11 changes: 9 additions & 2 deletions api/v1beta1/rollout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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"

Expand Down
15 changes: 13 additions & 2 deletions config/crd/bases/rollouts.kruise.io_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/rollout/rollout_progressing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 18 additions & 0 deletions pkg/controller/rollout/rollout_progressing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
},
},
Expand Down Expand Up @@ -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
},
},
Expand Down Expand Up @@ -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
},
},
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
},
},
Expand Down Expand Up @@ -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
},
},
Expand Down Expand Up @@ -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
},
},
Expand Down Expand Up @@ -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
},
},
Expand Down
4 changes: 4 additions & 0 deletions pkg/controller/rollout/rollout_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit db761a9

Please sign in to comment.