Skip to content

Commit

Permalink
fix status conversion
Browse files Browse the repository at this point in the history
Signed-off-by: yunbo <[email protected]>
  • Loading branch information
Funinu committed May 29, 2024
1 parent 36d5d43 commit 2d045c9
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 13 deletions.
4 changes: 4 additions & 0 deletions api/v1alpha1/conversion.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand Down
8 changes: 8 additions & 0 deletions api/v1alpha1/rollout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down
20 changes: 9 additions & 11 deletions api/v1beta1/rollout_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -386,22 +388,18 @@ 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
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
Expand All @@ -427,15 +425,15 @@ 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) {
if r.CanaryStatus != nil {
r.CanaryStatus.CanaryRevision = revision
}
if r.BlueGreenStatus != nil {
r.BlueGreenStatus.CanaryRevision = revision
r.BlueGreenStatus.UpdatedRevision = revision
}
}

Expand Down
12 changes: 12 additions & 0 deletions config/crd/bases/rollouts.kruise.io_rollouts.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -470,6 +481,7 @@ spec:
- canaryRevision
- currentStepState
- finalisingStep
- nextStepIndex
- podTemplateHash
type: object
conditions:
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/rollout/rollout_progressing.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/rollout/rollout_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit 2d045c9

Please sign in to comment.