Skip to content

Commit

Permalink
fix patch rollout batch id
Browse files Browse the repository at this point in the history
Signed-off-by: zhihao jian <[email protected]>
  • Loading branch information
zhihao jian committed Dec 26, 2024
1 parent efbd8ba commit eb69d8d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 2 deletions.
7 changes: 7 additions & 0 deletions pkg/controller/rollout/rollout_bluegreen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestBlueGreenRunCanary(t *testing.T) {
obj.Status.BlueGreenStatus.UpdatedRevision = "6f8cc56547"
obj.Status.BlueGreenStatus.CurrentStepIndex = 1
obj.Status.BlueGreenStatus.NextStepIndex = 2
obj.Status.BlueGreenStatus.ObservedRolloutID = "88bd5dbfd"
obj.Status.BlueGreenStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade
cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing)
cond.Reason = v1alpha1.ProgressingReasonInRolling
Expand All @@ -79,6 +80,7 @@ func TestBlueGreenRunCanary(t *testing.T) {
s.BlueGreenStatus.CurrentStepIndex = 1
s.BlueGreenStatus.NextStepIndex = 2
s.BlueGreenStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade
s.BlueGreenStatus.ObservedRolloutID = "88bd5dbfd"
cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing)
cond.Reason = v1alpha1.ProgressingReasonInRolling
util.SetRolloutCondition(s, *cond)
Expand All @@ -102,6 +104,7 @@ func TestBlueGreenRunCanary(t *testing.T) {
}
br.Spec.ReleasePlan.BatchPartition = utilpointer.Int32(0)
br.Spec.ReleasePlan.RollingStyle = v1beta1.BlueGreenRollingStyle
br.Spec.ReleasePlan.RolloutID = "88bd5dbfd"
return br
},
},
Expand All @@ -128,6 +131,7 @@ func TestBlueGreenRunCanary(t *testing.T) {
obj.Status.BlueGreenStatus.CurrentStepIndex = 1
obj.Status.BlueGreenStatus.NextStepIndex = 2
obj.Status.BlueGreenStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade
obj.Status.BlueGreenStatus.ObservedRolloutID = "88bd5dbfd"
cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing)
cond.Reason = v1alpha1.ProgressingReasonInRolling
util.SetRolloutCondition(&obj.Status, *cond)
Expand All @@ -148,6 +152,7 @@ func TestBlueGreenRunCanary(t *testing.T) {
}
br.Spec.ReleasePlan.BatchPartition = utilpointer.Int32(0)
br.Spec.ReleasePlan.RollingStyle = v1beta1.BlueGreenRollingStyle
br.Spec.ReleasePlan.RolloutID = "88bd5dbfd"
br.Status = v1beta1.BatchReleaseStatus{
ObservedGeneration: 1,
ObservedReleasePlanHash: util.HashReleasePlanBatches(&br.Spec.ReleasePlan),
Expand All @@ -171,6 +176,7 @@ func TestBlueGreenRunCanary(t *testing.T) {
s.BlueGreenStatus.UpdatedReadyReplicas = 1
s.BlueGreenStatus.CurrentStepIndex = 1
s.BlueGreenStatus.NextStepIndex = 2
s.BlueGreenStatus.ObservedRolloutID = "88bd5dbfd"
s.BlueGreenStatus.CurrentStepState = v1beta1.CanaryStepStateTrafficRouting
cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing)
cond.Reason = v1alpha1.ProgressingReasonInRolling
Expand All @@ -195,6 +201,7 @@ func TestBlueGreenRunCanary(t *testing.T) {
}
br.Spec.ReleasePlan.BatchPartition = utilpointer.Int32(0)
br.Spec.ReleasePlan.RollingStyle = v1beta1.BlueGreenRollingStyle
br.Spec.ReleasePlan.RolloutID = "88bd5dbfd"
return br
},
},
Expand Down
5 changes: 5 additions & 0 deletions pkg/controller/rollout/rollout_canary_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func TestRunCanary(t *testing.T) {
br.Spec.ReleasePlan.BatchPartition = utilpointer.Int32(0)
br.Spec.ReleasePlan.EnableExtraWorkloadForCanary = true
br.Spec.ReleasePlan.RollingStyle = v1beta1.CanaryRollingStyle
br.Spec.ReleasePlan.RolloutID = "88bd5dbfd"
return br
},
},
Expand Down Expand Up @@ -143,6 +144,7 @@ func TestRunCanary(t *testing.T) {
obj.Status.CanaryStatus.CurrentStepIndex = 1
obj.Status.CanaryStatus.NextStepIndex = 2
obj.Status.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateUpgrade
obj.Status.CanaryStatus.ObservedRolloutID = "88bd5dbfd"
cond := util.GetRolloutCondition(obj.Status, v1beta1.RolloutConditionProgressing)
cond.Reason = v1alpha1.ProgressingReasonInRolling
util.SetRolloutCondition(&obj.Status, *cond)
Expand All @@ -164,6 +166,7 @@ func TestRunCanary(t *testing.T) {
br.Spec.ReleasePlan.BatchPartition = utilpointer.Int32(0)
br.Spec.ReleasePlan.EnableExtraWorkloadForCanary = true
br.Spec.ReleasePlan.RollingStyle = v1beta1.CanaryRollingStyle
br.Spec.ReleasePlan.RolloutID = "88bd5dbfd"
br.Status = v1beta1.BatchReleaseStatus{
ObservedGeneration: 1,
// since we use RollingStyle over EnableExtraWorkloadForCanary now, former hardcoded hash
Expand All @@ -190,6 +193,7 @@ func TestRunCanary(t *testing.T) {
s.CanaryStatus.CurrentStepIndex = 1
s.CanaryStatus.NextStepIndex = 2
s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateTrafficRouting
s.CanaryStatus.ObservedRolloutID = "88bd5dbfd"
cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing)
cond.Reason = v1alpha1.ProgressingReasonInRolling
util.SetRolloutCondition(s, *cond)
Expand All @@ -214,6 +218,7 @@ func TestRunCanary(t *testing.T) {
br.Spec.ReleasePlan.BatchPartition = utilpointer.Int32(0)
br.Spec.ReleasePlan.EnableExtraWorkloadForCanary = true
br.Spec.ReleasePlan.RollingStyle = v1beta1.CanaryRollingStyle
br.Spec.ReleasePlan.RolloutID = "88bd5dbfd"
return br
},
},
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/rollout/rollout_progressing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ func TestReconcileRolloutProgressing(t *testing.T) {
s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateInit
s.CurrentStepIndex = s.CanaryStatus.CurrentStepIndex
s.CurrentStepState = s.CanaryStatus.CurrentStepState
s.CanaryStatus.ObservedRolloutID = "88bd5dbfd"
return s
},
expectTr: func() *v1alpha1.TrafficRouting {
Expand Down Expand Up @@ -107,6 +108,7 @@ func TestReconcileRolloutProgressing(t *testing.T) {
s.CanaryStatus.CurrentStepIndex = 1
s.CanaryStatus.NextStepIndex = 2
s.CanaryStatus.CurrentStepState = v1beta1.CanaryStepStateInit
s.CanaryStatus.ObservedRolloutID = "88bd5dbfd"
cond := util.GetRolloutCondition(*s, v1beta1.RolloutConditionProgressing)
cond.Reason = v1alpha1.ProgressingReasonInRolling
util.SetRolloutCondition(s, *cond)
Expand Down
8 changes: 6 additions & 2 deletions pkg/controller/rollout/rollout_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (r *RolloutReconciler) calculateRolloutStatus(rollout *v1beta1.Rollout) (re
// newStatus.CanaryStatus.CurrentStepState == "Completed" {
// // do something after rollout
// }
//```
// ```
// But at the first deployment of Rollout/Workload, CanaryStatus isn't set due to no rollout progression,
// and PaaS platform cannot judge whether the deployment is completed base on the code above. So we have
// to update the status just like the rollout was completed.
Expand Down Expand Up @@ -349,7 +349,11 @@ func (r *RolloutReconciler) handleFinalizer(rollout *v1beta1.Rollout) error {

func getRolloutID(workload *util.Workload) string {
if workload != nil {
return workload.Labels[v1beta1.RolloutIDLabel]
rolloutID := workload.Labels[v1beta1.RolloutIDLabel]
if rolloutID == "" {
rolloutID = workload.CanaryRevision
}
return rolloutID
}
return ""
}

0 comments on commit eb69d8d

Please sign in to comment.