Skip to content

Commit

Permalink
rollout code optimization
Browse files Browse the repository at this point in the history
Signed-off-by: liheng.zms <[email protected]>
  • Loading branch information
zmberg committed Apr 12, 2022
1 parent 0b23feb commit c6fabf5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
6 changes: 3 additions & 3 deletions pkg/controller/rollout/trafficrouting.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import (
)

func (r *rolloutContext) doCanaryTrafficRouting() (bool, error) {
if r.rollout.Spec.Strategy.Canary.TrafficRoutings == nil {
if len(r.rollout.Spec.Strategy.Canary.TrafficRoutings) == 0 {
return true, nil
}

Expand Down Expand Up @@ -134,7 +134,7 @@ func (r *rolloutContext) doCanaryTrafficRouting() (bool, error) {
}

func (r *rolloutContext) restoreStableService() (bool, error) {
if r.rollout.Spec.Strategy.Canary.TrafficRoutings == nil {
if len(r.rollout.Spec.Strategy.Canary.TrafficRoutings) == 0 {
return true, nil
}

Expand Down Expand Up @@ -179,7 +179,7 @@ func (r *rolloutContext) restoreStableService() (bool, error) {
}

func (r *rolloutContext) doFinalisingTrafficRouting() (bool, error) {
if r.rollout.Spec.Strategy.Canary.TrafficRoutings == nil {
if len(r.rollout.Spec.Strategy.Canary.TrafficRoutings) == 0 {
return true, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ func validateRolloutSpecCanaryStrategy(canary *appsv1alpha1.CanaryStrategy, fldP
}

errList := validateRolloutSpecCanarySteps(canary.Steps, fldPath.Child("Steps"))
if len(canary.TrafficRoutings) > 1 {
errList = append(errList, field.Invalid(fldPath, canary.TrafficRoutings, "Rollout currently only support single TrafficRouting."))
}
for _, traffic := range canary.TrafficRoutings {
errList = append(errList, validateRolloutSpecCanaryTraffic(traffic, fldPath.Child("TrafficRouting"))...)
}
Expand Down
15 changes: 9 additions & 6 deletions test/e2e/rollout_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,15 +122,18 @@ var _ = SIGDescribe("Rollout", func() {
}

ResumeRolloutCanary := func(name string) {
Expect(retry.RetryOnConflict(retry.DefaultRetry, func() error {
Eventually(func() bool {
clone := &rolloutsv1alpha1.Rollout{}
err := GetObject(name, clone)
if err != nil {
return err
Expect(GetObject(name, clone)).NotTo(HaveOccurred())
if clone.Status.CanaryStatus.CurrentStepState != rolloutsv1alpha1.CanaryStepStatePaused {
fmt.Println("resume rollout success, and CurrentStepState", util.DumpJSON(clone.Status))
return true
}

body := fmt.Sprintf(`{"status":{"canaryStatus":{"currentStepState":"%s"}}}`, rolloutsv1alpha1.CanaryStepStateReady)
return k8sClient.Status().Patch(context.TODO(), clone, client.RawPatch(types.MergePatchType, []byte(body)))
})).NotTo(HaveOccurred())
Expect(k8sClient.Status().Patch(context.TODO(), clone, client.RawPatch(types.MergePatchType, []byte(body)))).NotTo(HaveOccurred())
return false
}, 10*time.Second, time.Second).Should(BeTrue())
}

WaitDeploymentAllPodsReady := func(deployment *apps.Deployment) {
Expand Down

0 comments on commit c6fabf5

Please sign in to comment.