diff --git a/pkg/apis/api-rules/violation_exceptions.list b/pkg/apis/api-rules/violation_exceptions.list index d679e3ce71..c600d77805 100644 --- a/pkg/apis/api-rules/violation_exceptions.list +++ b/pkg/apis/api-rules/violation_exceptions.list @@ -1,3 +1 @@ API rule violation: names_match,github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1,RolloutStatus,HPAReplicas -API rule violation: names_match,github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1,RolloutStrategy,BlueGreenStrategy -API rule violation: names_match,github.com/argoproj/argo-rollouts/pkg/apis/rollouts/v1alpha1,RolloutStrategy,CanaryStrategy diff --git a/pkg/apis/rollouts/v1alpha1/types.go b/pkg/apis/rollouts/v1alpha1/types.go index ba8445456d..24a853ff60 100644 --- a/pkg/apis/rollouts/v1alpha1/types.go +++ b/pkg/apis/rollouts/v1alpha1/types.go @@ -69,12 +69,11 @@ const ( ) // RolloutStrategy defines strategy to apply during next rollout -// TODO(jessesuen): rename field names to match json tags to remove api violations type RolloutStrategy struct { // +optional - BlueGreenStrategy *BlueGreenStrategy `json:"blueGreen,omitempty"` + BlueGreen *BlueGreenStrategy `json:"blueGreen,omitempty"` // +optional - CanaryStrategy *CanaryStrategy `json:"canary,omitempty"` + Canary *CanaryStrategy `json:"canary,omitempty"` } // BlueGreenStrategy defines parameters for Blue Green deployment diff --git a/pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go index 880d9c4f3e..828f12d8d6 100644 --- a/pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/rollouts/v1alpha1/zz_generated.deepcopy.go @@ -998,13 +998,13 @@ func (in *RolloutStatus) DeepCopy() *RolloutStatus { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *RolloutStrategy) DeepCopyInto(out *RolloutStrategy) { *out = *in - if in.BlueGreenStrategy != nil { - in, out := &in.BlueGreenStrategy, &out.BlueGreenStrategy + if in.BlueGreen != nil { + in, out := &in.BlueGreen, &out.BlueGreen *out = new(BlueGreenStrategy) (*in).DeepCopyInto(*out) } - if in.CanaryStrategy != nil { - in, out := &in.CanaryStrategy, &out.CanaryStrategy + if in.Canary != nil { + in, out := &in.Canary, &out.Canary *out = new(CanaryStrategy) (*in).DeepCopyInto(*out) } diff --git a/pkg/kubectl-argo-rollouts/cmd/list/list_test.go b/pkg/kubectl-argo-rollouts/cmd/list/list_test.go index 940d32fbf0..9f806badeb 100644 --- a/pkg/kubectl-argo-rollouts/cmd/list/list_test.go +++ b/pkg/kubectl-argo-rollouts/cmd/list/list_test.go @@ -28,7 +28,7 @@ func newCanaryRollout() *v1alpha1.Rollout { Spec: v1alpha1.RolloutSpec{ Replicas: pointer.Int32Ptr(5), Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ Steps: []v1alpha1.CanaryStep{ { SetWeight: pointer.Int32Ptr(10), @@ -64,7 +64,7 @@ func newBlueGreenRollout() *v1alpha1.Rollout { Spec: v1alpha1.RolloutSpec{ Replicas: pointer.Int32Ptr(5), Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{}, }, }, Status: v1alpha1.RolloutStatus{ diff --git a/pkg/kubectl-argo-rollouts/cmd/list/rollloutinfo.go b/pkg/kubectl-argo-rollouts/cmd/list/rollloutinfo.go index 6fa2bd981b..a14f0ae55f 100644 --- a/pkg/kubectl-argo-rollouts/cmd/list/rollloutinfo.go +++ b/pkg/kubectl-argo-rollouts/cmd/list/rollloutinfo.go @@ -45,10 +45,10 @@ func newRolloutInfo(ro v1alpha1.Rollout) rolloutInfo { ri.step = "-" ri.setWeight = "-" - if ro.Spec.Strategy.CanaryStrategy != nil { + if ro.Spec.Strategy.Canary != nil { ri.strategy = "Canary" - if ro.Status.CurrentStepIndex != nil && len(ro.Spec.Strategy.CanaryStrategy.Steps) > 0 { - ri.step = fmt.Sprintf("%d/%d", *ro.Status.CurrentStepIndex, len(ro.Spec.Strategy.CanaryStrategy.Steps)) + if ro.Status.CurrentStepIndex != nil && len(ro.Spec.Strategy.Canary.Steps) > 0 { + ri.step = fmt.Sprintf("%d/%d", *ro.Status.CurrentStepIndex, len(ro.Spec.Strategy.Canary.Steps)) } // NOTE that this is desired weight, not the actual current weight ri.setWeight = strconv.Itoa(int(replicasetutil.GetCurrentSetWeight(&ro))) @@ -59,7 +59,7 @@ func newRolloutInfo(ro v1alpha1.Rollout) rolloutInfo { // } else { // ri.weight = fmt.Sprintf("%d", (ro.Status.UpdatedReplicas*100)/ro.Status.AvailableReplicas) // } - } else if ro.Spec.Strategy.BlueGreenStrategy != nil { + } else if ro.Spec.Strategy.BlueGreen != nil { ri.strategy = "BlueGreen" } ri.status = rolloutStatus(&ro) @@ -121,13 +121,13 @@ func rolloutStatus(ro *v1alpha1.Rollout) string { // updated replicas are still becoming available return "Progressing" } - if ro.Spec.Strategy.BlueGreenStrategy != nil { + if ro.Spec.Strategy.BlueGreen != nil { if ro.Status.BlueGreen.ActiveSelector != "" && ro.Status.BlueGreen.ActiveSelector == ro.Status.CurrentPodHash { return "Healthy" } // service cutover pending return "Progressing" - } else if ro.Spec.Strategy.CanaryStrategy != nil { + } else if ro.Spec.Strategy.Canary != nil { if ro.Status.Canary.StableRS != "" && ro.Status.Canary.StableRS == ro.Status.CurrentPodHash { return "Healthy" } diff --git a/rollout/analysis.go b/rollout/analysis.go index eae1aacd8b..7151f4249c 100644 --- a/rollout/analysis.go +++ b/rollout/analysis.go @@ -86,7 +86,7 @@ func (c *RolloutController) reconcileBackgroundAnalysisRun(roCtx *canaryContext) newRS := roCtx.NewRS() currentArs := roCtx.CurrentAnalysisRuns() currentAr := analysisutil.FilterAnalysisRunsByName(currentArs, rollout.Status.Canary.CurrentBackgroundAnalysisRun) - if rollout.Spec.Strategy.CanaryStrategy.Analysis == nil { + if rollout.Spec.Strategy.Canary.Analysis == nil { err := c.cancelAnalysisRuns(roCtx, []*v1alpha1.AnalysisRun{currentAr}) if err != nil { return nil, err @@ -96,7 +96,7 @@ func (c *RolloutController) reconcileBackgroundAnalysisRun(roCtx *canaryContext) if currentAr == nil { podHash := replicasetutil.GetPodTemplateHash(newRS) backgroundLabels := analysisutil.BackgroundLabels(podHash) - currentAr, err := c.createAnalysisRun(roCtx, rollout.Spec.Strategy.CanaryStrategy.Analysis, backgroundLabels) + currentAr, err := c.createAnalysisRun(roCtx, rollout.Spec.Strategy.Canary.Analysis, backgroundLabels) if err == nil { roCtx.Log().WithField(logutil.AnalysisRunKey, currentAr.Name).Info("Created background AnalysisRun") } diff --git a/rollout/analysis_test.go b/rollout/analysis_test.go index 81f97fd30c..d757a2f250 100644 --- a/rollout/analysis_test.go +++ b/rollout/analysis_test.go @@ -63,7 +63,7 @@ func TestCreateBackgroundAnalysisRun(t *testing.T) { r1 := newCanaryRollout("foo", 10, nil, steps, pointer.Int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1)) r2 := bumpVersion(r1) ar := analysisRun(at, v1alpha1.RolloutTypeBackgroundRunLabel, r2) - r2.Spec.Strategy.CanaryStrategy.Analysis = &v1alpha1.RolloutAnalysisStep{ + r2.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisStep{ TemplateName: at.Name, } @@ -198,7 +198,7 @@ func TestFailCreateBackgroundAnalysisRunIfInvalidTemplateRef(t *testing.T) { r1 := newCanaryRollout("foo", 1, nil, steps, pointer.Int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1)) r2 := bumpVersion(r1) - r2.Spec.Strategy.CanaryStrategy.Analysis = &v1alpha1.RolloutAnalysisStep{ + r2.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisStep{ TemplateName: "invalid-template-ref", } @@ -232,7 +232,7 @@ func TestDoNothingWithAnalysisRunsWhileBackgroundAnalysisRunRunning(t *testing.T r1 := newCanaryRollout("foo", 1, nil, steps, pointer.Int32Ptr(0), intstr.FromInt(0), intstr.FromInt(1)) r2 := bumpVersion(r1) - r2.Spec.Strategy.CanaryStrategy.Analysis = &v1alpha1.RolloutAnalysisStep{ + r2.Spec.Strategy.Canary.Analysis = &v1alpha1.RolloutAnalysisStep{ TemplateName: at.Name, } ar := analysisRun(at, v1alpha1.RolloutTypeBackgroundRunLabel, r2) diff --git a/rollout/bluegreen.go b/rollout/bluegreen.go index a22bb1f6a5..37b142212d 100644 --- a/rollout/bluegreen.go +++ b/rollout/bluegreen.go @@ -146,7 +146,7 @@ func (c *RolloutController) reconcileBlueGreenPause(activeSvc, previewSvc *corev } pauseStartTime := rollout.Status.PauseStartTime - autoPromoteActiveServiceDelaySeconds := rollout.Spec.Strategy.BlueGreenStrategy.AutoPromotionSeconds + autoPromoteActiveServiceDelaySeconds := rollout.Spec.Strategy.BlueGreen.AutoPromotionSeconds if autoPromoteActiveServiceDelaySeconds != nil && pauseStartTime != nil { c.checkEnqueueRolloutDuringWait(rollout, *pauseStartTime, *autoPromoteActiveServiceDelaySeconds) } @@ -167,7 +167,7 @@ func (c *RolloutController) scaleDownOldReplicaSetsForBlueGreen(oldRSs []*appsv1 scaleDownAtTime, err := time.Parse(time.RFC3339, scaleDownAtStr) if err != nil { logCtx.Warnf("Unable to read scaleDownAt label on rs '%s'", targetRS.Name) - } else if rollout.Spec.Strategy.BlueGreenStrategy.ScaleDownDelayRevisionLimit != nil && annotationedRSs == *rollout.Spec.Strategy.BlueGreenStrategy.ScaleDownDelayRevisionLimit { + } else if rollout.Spec.Strategy.BlueGreen.ScaleDownDelayRevisionLimit != nil && annotationedRSs == *rollout.Spec.Strategy.BlueGreen.ScaleDownDelayRevisionLimit { logCtx.Info("At ScaleDownDelayRevisionLimit and scaling down the rest") } else { now := metav1.Now() @@ -247,7 +247,7 @@ func calculateScaleUpPreviewCheckPoint(roCtx *blueGreenContext, activeRS *appsv1 r := roCtx.Rollout() newRS := roCtx.NewRS() newRSAvailableCount := replicasetutil.GetAvailableReplicaCountForReplicaSets([]*appsv1.ReplicaSet{newRS}) - if r.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount != nil && newRSAvailableCount == *r.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount { + if r.Spec.Strategy.BlueGreen.PreviewReplicaCount != nil && newRSAvailableCount == *r.Spec.Strategy.BlueGreen.PreviewReplicaCount { return true } else if reconcileBlueGreenTemplateChange(roCtx) { return false @@ -290,8 +290,8 @@ func (c *RolloutController) scaleBlueGreen(rollout *v1alpha1.Rollout, newRS *app previewRS, _ := replicasetutil.GetReplicaSetByTemplateHash(allRS, rollout.Status.BlueGreen.PreviewSelector) if previewRS != nil { previewReplicas := rolloutReplicas - if rollout.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount != nil && !rollout.Status.BlueGreen.ScaleUpPreviewCheckPoint { - previewReplicas = *rollout.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount + if rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount != nil && !rollout.Status.BlueGreen.ScaleUpPreviewCheckPoint { + previewReplicas = *rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount } if *(previewRS.Spec.Replicas) != previewReplicas { _, _, err := c.scaleReplicaSetAndRecordEvent(previewRS, previewReplicas, rollout) diff --git a/rollout/bluegreen_test.go b/rollout/bluegreen_test.go index 637531d586..5a81011651 100644 --- a/rollout/bluegreen_test.go +++ b/rollout/bluegreen_test.go @@ -23,7 +23,7 @@ var ( func newBlueGreenRollout(name string, replicas int, revisionHistoryLimit *int32, activeSvc string, previewSvc string) *v1alpha1.Rollout { rollout := newRollout(name, replicas, revisionHistoryLimit, map[string]string{"foo": "bar"}) - rollout.Spec.Strategy.BlueGreenStrategy = &v1alpha1.BlueGreenStrategy{ + rollout.Spec.Strategy.BlueGreen = &v1alpha1.BlueGreenStrategy{ ActiveService: activeSvc, PreviewService: previewSvc, } @@ -131,7 +131,7 @@ func TestBlueGreenHandlePause(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) r2 := bumpVersion(r1) rs1 := newReplicaSetWithStatus(r1, 1, 1) rs2 := newReplicaSetWithStatus(r2, 1, 1) @@ -174,7 +174,7 @@ func TestBlueGreenHandlePause(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) r2 := bumpVersion(r1) rs1 := newReplicaSetWithStatus(r1, 1, 1) @@ -214,7 +214,7 @@ func TestBlueGreenHandlePause(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) r2 := bumpVersion(r1) rs1 := newReplicaSetWithStatus(r1, 1, 1) @@ -248,9 +248,9 @@ func TestBlueGreenHandlePause(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) r2 := bumpVersion(r1) - r2.Spec.Strategy.BlueGreenStrategy.AutoPromotionSeconds = pointer.Int32Ptr(10) + r2.Spec.Strategy.BlueGreen.AutoPromotionSeconds = pointer.Int32Ptr(10) rs1 := newReplicaSetWithStatus(r1, 1, 1) rs2 := newReplicaSetWithStatus(r2, 1, 1) @@ -283,9 +283,9 @@ func TestBlueGreenHandlePause(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) r2 := bumpVersion(r1) - r2.Spec.Strategy.BlueGreenStrategy.AutoPromotionSeconds = pointer.Int32Ptr(10) + r2.Spec.Strategy.BlueGreen.AutoPromotionSeconds = pointer.Int32Ptr(10) rs1 := newReplicaSetWithStatus(r1, 1, 1) rs2 := newReplicaSetWithStatus(r2, 1, 1) @@ -339,7 +339,7 @@ func TestBlueGreenHandlePause(t *testing.T) { rs2PodHash := rs2.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] r2 = updateBlueGreenRolloutStatus(r2, "", rs1PodHash, 1, 1, 2, 1, false, true) - r2.Spec.Strategy.BlueGreenStrategy.ScaleDownDelaySeconds = pointer.Int32Ptr(10) + r2.Spec.Strategy.BlueGreen.ScaleDownDelaySeconds = pointer.Int32Ptr(10) progressingCondition, _ := newProgressingCondition(conditions.NewReplicaSetReason, rs2) conditions.SetRolloutCondition(&r2.Status, progressingCondition) @@ -381,7 +381,7 @@ func TestBlueGreenHandlePause(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "") - r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) r2 := bumpVersion(r1) rs1 := newReplicaSetWithStatus(r1, 1, 1) @@ -423,7 +423,7 @@ func TestBlueGreenHandlePause(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) rs1 := newReplicaSetWithStatus(r1, 1, 1) rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] @@ -467,7 +467,7 @@ func TestBlueGreenHandlePause(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r1.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r1.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) r2 := bumpVersion(r1) rs1 := newReplicaSetWithStatus(r1, 1, 1) @@ -475,7 +475,7 @@ func TestBlueGreenHandlePause(t *testing.T) { rs1PodHash := rs1.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] rs2PodHash := rs2.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] - r2.Spec.Strategy.BlueGreenStrategy.ScaleDownDelaySeconds = pointer.Int32Ptr(10) + r2.Spec.Strategy.BlueGreen.ScaleDownDelaySeconds = pointer.Int32Ptr(10) r2 = updateBlueGreenRolloutStatus(r2, rs2PodHash, rs1PodHash, 1, 1, 2, 1, false, true) now := metav1.Now() r2.Status.PauseStartTime = &now @@ -568,7 +568,7 @@ func TestBlueGreenAddScaleDownDelayToPreviousActiveService(t *testing.T) { f.kubeobjects = append(f.kubeobjects, s, rs1, rs2) f.replicaSetLister = append(f.replicaSetLister, rs1, rs2) - r2.Spec.Strategy.BlueGreenStrategy.ScaleDownDelaySeconds = pointer.Int32Ptr(10) + r2.Spec.Strategy.BlueGreen.ScaleDownDelaySeconds = pointer.Int32Ptr(10) r2 = updateBlueGreenRolloutStatus(r2, "", rs1PodHash, 1, 1, 2, 1, false, true) f.rolloutLister = append(f.rolloutLister, r2) f.objects = append(f.objects, r2) @@ -601,7 +601,7 @@ func TestBlueGreenRolloutStatusHPAStatusFieldsActiveSelectorSet(t *testing.T) { defer f.Close() r := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled = pointer.BoolPtr(false) + r.Spec.Strategy.BlueGreen.AutoPromotionEnabled = pointer.BoolPtr(false) r2 := bumpVersion(r) rs1 := newReplicaSetWithStatus(r, 1, 1) @@ -715,7 +715,7 @@ func TestBlueGreenRolloutIgnoringScalingUsePreviewRSCount(t *testing.T) { defer f.Close() r1 := newBlueGreenRollout("foo", 1, nil, "active", "preview") - r1.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount = pointer.Int32Ptr(3) + r1.Spec.Strategy.BlueGreen.PreviewReplicaCount = pointer.Int32Ptr(3) rs1 := newReplicaSetWithStatus(r1, 1, 1) rs1.Spec.Replicas = pointer.Int32Ptr(2) r2 := bumpVersion(r1) @@ -966,7 +966,7 @@ func TestScaleDownLimit(t *testing.T) { r1 := newBlueGreenRollout("foo", 1, nil, "bar", "") r2 := bumpVersion(r1) r3 := bumpVersion(r2) - r3.Spec.Strategy.BlueGreenStrategy.ScaleDownDelayRevisionLimit = pointer.Int32Ptr(2) + r3.Spec.Strategy.BlueGreen.ScaleDownDelayRevisionLimit = pointer.Int32Ptr(2) rs1 := newReplicaSetWithStatus(r1, 1, 1) rs2 := newReplicaSetWithStatus(r2, 1, 1) diff --git a/rollout/canary.go b/rollout/canary.go index fd58b24a5b..79b5d9231f 100644 --- a/rollout/canary.go +++ b/rollout/canary.go @@ -105,13 +105,13 @@ func (c *RolloutController) reconcileStableRS(roCtx *canaryContext) (bool, error func (c *RolloutController) reconcileCanaryPause(roCtx *canaryContext) bool { rollout := roCtx.Rollout() logCtx := roCtx.Log() - if len(rollout.Spec.Strategy.CanaryStrategy.Steps) == 0 { + if len(rollout.Spec.Strategy.Canary.Steps) == 0 { logCtx.Info("Rollout does not have any steps") return false } currentStep, currentStepIndex := replicasetutil.GetCurrentCanaryStep(rollout) - if len(rollout.Spec.Strategy.CanaryStrategy.Steps) <= int(*currentStepIndex) { + if len(rollout.Spec.Strategy.Canary.Steps) <= int(*currentStepIndex) { logCtx.Info("No Steps remain in the canary steps") return false } @@ -242,7 +242,7 @@ func (c *RolloutController) syncRolloutStatusCanary(roCtx *canaryContext) error currentStep, currentStepIndex := replicasetutil.GetCurrentCanaryStep(r) newStatus.Canary.StableRS = r.Status.Canary.StableRS newStatus.CurrentStepHash = conditions.ComputeStepHash(r) - stepCount := int32(len(r.Spec.Strategy.CanaryStrategy.Steps)) + stepCount := int32(len(r.Spec.Strategy.Canary.Steps)) if replicasetutil.PodTemplateOrStepsChanged(r, newRS) { newStatus.CurrentStepIndex = replicasetutil.ResetCurrentStepIndex(r) @@ -315,7 +315,7 @@ func (c *RolloutController) syncRolloutStatusCanary(roCtx *canaryContext) error if completedCurrentCanaryStep(roCtx) { *currentStepIndex++ newStatus.CurrentStepIndex = currentStepIndex - if int(*currentStepIndex) == len(r.Spec.Strategy.CanaryStrategy.Steps) { + if int(*currentStepIndex) == len(r.Spec.Strategy.Canary.Steps) { c.recorder.Event(r, corev1.EventTypeNormal, "SettingStableRS", "Completed all steps") } logCtx.Infof("Incrementing the Current Step Index to %d", *currentStepIndex) diff --git a/rollout/canary_test.go b/rollout/canary_test.go index 44010d538d..df009a6abc 100644 --- a/rollout/canary_test.go +++ b/rollout/canary_test.go @@ -26,7 +26,7 @@ import ( func newCanaryRollout(name string, replicas int, revisionHistoryLimit *int32, steps []v1alpha1.CanaryStep, stepIndex *int32, maxSurge, maxUnavailable intstr.IntOrString) *v1alpha1.Rollout { selector := map[string]string{"foo": "bar"} rollout := newRollout(name, replicas, revisionHistoryLimit, selector) - rollout.Spec.Strategy.CanaryStrategy = &v1alpha1.CanaryStrategy{ + rollout.Spec.Strategy.Canary = &v1alpha1.CanaryStrategy{ MaxUnavailable: &maxUnavailable, MaxSurge: &maxSurge, Steps: steps, @@ -285,7 +285,7 @@ func TestResetCurrentStepIndexOnStepChange(t *testing.T) { r1 := newCanaryRollout("foo", 10, nil, steps, int32Ptr(1), intstr.FromInt(0), intstr.FromInt(1)) r2 := bumpVersion(r1) expectedCurrentPodHash := r2.Status.CurrentPodHash - r2.Spec.Strategy.CanaryStrategy.Steps = append(steps, v1alpha1.CanaryStep{Pause: &v1alpha1.RolloutPause{}}) + r2.Spec.Strategy.Canary.Steps = append(steps, v1alpha1.CanaryStep{Pause: &v1alpha1.RolloutPause{}}) expectedCurrentStepHash := conditions.ComputeStepHash(r2) rs1 := newReplicaSetWithStatus(r1, 10, 10) @@ -639,7 +639,7 @@ func TestGradualShiftToNewStable(t *testing.T) { r2 = updateCanaryRolloutStatus(r2, rs1PodHash, 13, 4, 13, false) maxSurge := intstr.FromInt(3) - r2.Spec.Strategy.CanaryStrategy.MaxSurge = &maxSurge + r2.Spec.Strategy.Canary.MaxSurge = &maxSurge r2.Status.CurrentPodHash = rs2.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] f.rolloutLister = append(f.rolloutLister, r2) f.objects = append(f.objects, r2) @@ -682,7 +682,7 @@ func TestRollBackToStableAndStepChange(t *testing.T) { f.replicaSetLister = append(f.replicaSetLister, rs1, rs2) r2 = updateCanaryRolloutStatus(r2, rs1PodHash, 10, 9, 10, false) - r2.Spec.Strategy.CanaryStrategy.Steps[0].SetWeight = pointer.Int32Ptr(20) + r2.Spec.Strategy.Canary.Steps[0].SetWeight = pointer.Int32Ptr(20) f.rolloutLister = append(f.rolloutLister, r2) f.objects = append(f.objects, r2) @@ -968,7 +968,7 @@ func TestCanaryRolloutWithCanaryService(t *testing.T) { canarySvc := newService("canary", 80, nil) rollout := newCanaryRollout("foo", 0, nil, nil, nil, intstr.FromInt(1), intstr.FromInt(0)) rs := newReplicaSetWithStatus(rollout, 0, 0) - rollout.Spec.Strategy.CanaryStrategy.CanaryService = canarySvc.Name + rollout.Spec.Strategy.Canary.CanaryService = canarySvc.Name f.rolloutLister = append(f.rolloutLister, rollout) f.objects = append(f.objects, rollout) @@ -987,7 +987,7 @@ func TestCanaryRolloutWithInvalidCanaryServiceName(t *testing.T) { canarySvc := newService("invalid-canary", 80, make(map[string]string)) rollout := newCanaryRollout("foo", 0, nil, nil, nil, intstr.FromInt(1), intstr.FromInt(0)) rs := newReplicaSetWithStatus(rollout, 0, 0) - rollout.Spec.Strategy.CanaryStrategy.CanaryService = canarySvc.Name + rollout.Spec.Strategy.Canary.CanaryService = canarySvc.Name f.rolloutLister = append(f.rolloutLister, rollout) f.objects = append(f.objects, rollout) diff --git a/rollout/controller.go b/rollout/controller.go index 792eea36c3..054219f48f 100644 --- a/rollout/controller.go +++ b/rollout/controller.go @@ -279,10 +279,10 @@ func (c *RolloutController) syncHandler(key string) error { return c.syncReplicasOnly(r, rsList, isScalingEvent) } - if rollout.Spec.Strategy.BlueGreenStrategy != nil { + if rollout.Spec.Strategy.BlueGreen != nil { return c.rolloutBlueGreen(r, rsList) } - if rollout.Spec.Strategy.CanaryStrategy != nil { + if rollout.Spec.Strategy.Canary != nil { return c.rolloutCanary(r, rsList) } return fmt.Errorf("no rollout strategy selected") diff --git a/rollout/controller_test.go b/rollout/controller_test.go index d1c7f0463c..71bdbed676 100644 --- a/rollout/controller_test.go +++ b/rollout/controller_test.go @@ -167,8 +167,8 @@ func newProgressingCondition(reason string, resourceObj runtime.Object) (v1alpha } if reason == conditions.RolloutAnalysisRunFailedReason { atName := "" - if resource.Spec.Strategy.CanaryStrategy.Steps != nil && resource.Status.CurrentStepIndex != nil { - atName = resource.Spec.Strategy.CanaryStrategy.Steps[*resource.Status.CurrentStepIndex].Analysis.TemplateName + if resource.Spec.Strategy.Canary.Steps != nil && resource.Status.CurrentStepIndex != nil { + atName = resource.Spec.Strategy.Canary.Steps[*resource.Status.CurrentStepIndex].Analysis.TemplateName } //TODO(dthomson) Add support for parellel analysisRuns too arName := fmt.Sprintf("%s-%s-%s-%s", resource.Name, atName, resource.Status.CurrentPodHash, MockGeneratedNameSuffix) @@ -1110,7 +1110,7 @@ func TestComputeHashChangeTolerationBlueGreen(t *testing.T) { // this should only update observedGeneration and nothing else // NOTE: This test will fail on every k8s library upgrade. // To fix it, update expectedPatch to match the new hash. - expectedPatch := `{"status":{"observedGeneration":"85db9bf496"}}` + expectedPatch := `{"status":{"observedGeneration":"7bfd577d8"}}` patch := f.getPatchedRollout(patchIndex) assert.Equal(t, expectedPatch, patch) } @@ -1154,7 +1154,7 @@ func TestComputeHashChangeTolerationCanary(t *testing.T) { // this should only update observedGeneration and nothing else // NOTE: This test will fail on every k8s library upgrade. // To fix it, update expectedPatch to match the new hash. - expectedPatch := `{"status":{"observedGeneration":"546d577bb6"}}` + expectedPatch := `{"status":{"observedGeneration":"866857855d"}}` patch := f.getPatchedRollout(patchIndex) assert.Equal(t, expectedPatch, patch) } diff --git a/rollout/experiment_test.go b/rollout/experiment_test.go index 2632d35a6e..1ca10097c4 100644 --- a/rollout/experiment_test.go +++ b/rollout/experiment_test.go @@ -341,25 +341,25 @@ func TestGetExperimentFromTemplate(t *testing.T) { assert.Nil(t, err) assert.Equal(t, rs1.Spec.Template, stable.Spec.Templates[0].Template) - r2.Spec.Strategy.CanaryStrategy.Steps[0].Experiment.Templates[0].SpecRef = v1alpha1.CanarySpecRef + r2.Spec.Strategy.Canary.Steps[0].Experiment.Templates[0].SpecRef = v1alpha1.CanarySpecRef canary, err := GetExperimentFromTemplate(r2, rs1, rs2) assert.Nil(t, err) assert.Equal(t, rs2.Spec.Template, canary.Spec.Templates[0].Template) - r2.Spec.Strategy.CanaryStrategy.Steps[0].Experiment.Templates[0].Metadata.Annotations = map[string]string{"abc": "def"} - r2.Spec.Strategy.CanaryStrategy.Steps[0].Experiment.Templates[0].Metadata.Labels = map[string]string{"123": "456"} + r2.Spec.Strategy.Canary.Steps[0].Experiment.Templates[0].Metadata.Annotations = map[string]string{"abc": "def"} + r2.Spec.Strategy.Canary.Steps[0].Experiment.Templates[0].Metadata.Labels = map[string]string{"123": "456"} modifiedLabelAndAnnonations, err := GetExperimentFromTemplate(r2, rs1, rs2) assert.Nil(t, err) assert.Equal(t, modifiedLabelAndAnnonations.Spec.Templates[0].Template.ObjectMeta.Annotations["abc"], "def") assert.Equal(t, modifiedLabelAndAnnonations.Spec.Templates[0].Template.ObjectMeta.Labels["123"], "456") - r2.Spec.Strategy.CanaryStrategy.Steps[0].Experiment.Templates[0].SpecRef = v1alpha1.ReplicaSetSpecRef("test") + r2.Spec.Strategy.Canary.Steps[0].Experiment.Templates[0].SpecRef = v1alpha1.ReplicaSetSpecRef("test") invalidRef, err := GetExperimentFromTemplate(r2, rs1, rs2) assert.Nil(t, invalidRef) assert.NotNil(t, err) assert.Error(t, err, "Invalid template step SpecRef: must be canary or stable") - r2.Spec.Strategy.CanaryStrategy.Steps[0].Experiment = nil + r2.Spec.Strategy.Canary.Steps[0].Experiment = nil noStep, err := GetExperimentFromTemplate(r2, rs1, rs2) assert.Nil(t, noStep) assert.Nil(t, err) diff --git a/rollout/pause.go b/rollout/pause.go index 8d057c1463..14b1bd0261 100644 --- a/rollout/pause.go +++ b/rollout/pause.go @@ -50,7 +50,7 @@ func calculatePauseStatus(roCtx rolloutContext, addPause bool) (*metav1.Time, bo if !paused { pauseStartTime = nil } - if rollout.Spec.Strategy.BlueGreenStrategy != nil && defaults.GetAutoPromotionEnabledOrDefault(rollout) { + if rollout.Spec.Strategy.BlueGreen != nil && defaults.GetAutoPromotionEnabledOrDefault(rollout) { return nil, false } @@ -72,14 +72,14 @@ func calculatePauseStatus(roCtx rolloutContext, addPause bool) (*metav1.Time, bo } } - if rollout.Spec.Strategy.BlueGreenStrategy != nil { + if rollout.Spec.Strategy.BlueGreen != nil { bgCtx := roCtx.(*blueGreenContext) if reconcileBlueGreenTemplateChange(bgCtx) { return nil, false } - if paused && pauseStartTime != nil && rollout.Spec.Strategy.BlueGreenStrategy.AutoPromotionSeconds != nil { + if paused && pauseStartTime != nil && rollout.Spec.Strategy.BlueGreen.AutoPromotionSeconds != nil { now := metav1.Now() - autoPromoteActiveServiceDelaySeconds := *rollout.Spec.Strategy.BlueGreenStrategy.AutoPromotionSeconds + autoPromoteActiveServiceDelaySeconds := *rollout.Spec.Strategy.BlueGreen.AutoPromotionSeconds switchDeadline := pauseStartTime.Add(time.Duration(autoPromoteActiveServiceDelaySeconds) * time.Second) if now.After(switchDeadline) { return nil, false diff --git a/rollout/replicaset.go b/rollout/replicaset.go index d33cf81d26..e3fdb2ce64 100644 --- a/rollout/replicaset.go +++ b/rollout/replicaset.go @@ -73,7 +73,7 @@ func (c *RolloutController) reconcileNewReplicaSet(roCtx rolloutContext) (bool, rollout := roCtx.Rollout() newRS := roCtx.NewRS() allRSs := roCtx.AllRSs() - if rollout.Spec.Strategy.BlueGreenStrategy != nil { + if rollout.Spec.Strategy.BlueGreen != nil { rolloutReplicas := defaults.GetRolloutReplicasOrDefault(rollout) if *(newRS.Spec.Replicas) == rolloutReplicas { // Scaling not required. @@ -113,7 +113,7 @@ func (c *RolloutController) reconcileOldReplicaSets(oldRSs []*appsv1.ReplicaSet, // Scale down old replica sets scaledDownCount := int32(0) - if rollout.Spec.Strategy.BlueGreenStrategy != nil { + if rollout.Spec.Strategy.BlueGreen != nil { scaledDownCount, err = c.scaleDownOldReplicaSetsForBlueGreen(oldRSs, rollout) if err != nil { return false, nil diff --git a/rollout/service.go b/rollout/service.go index 5ccedb6828..1d4550e044 100644 --- a/rollout/service.go +++ b/rollout/service.go @@ -139,16 +139,16 @@ func (c *RolloutController) getPreviewAndActiveServices(r *v1alpha1.Rollout) (*c var previewSvc *corev1.Service var activeSvc *corev1.Service var err error - if r.Spec.Strategy.BlueGreenStrategy.PreviewService != "" { - previewSvc, err = c.getReferencedService(r, r.Spec.Strategy.BlueGreenStrategy.PreviewService) + if r.Spec.Strategy.BlueGreen.PreviewService != "" { + previewSvc, err = c.getReferencedService(r, r.Spec.Strategy.BlueGreen.PreviewService) if err != nil { return nil, nil, err } } - if r.Spec.Strategy.BlueGreenStrategy.ActiveService == "" { + if r.Spec.Strategy.BlueGreen.ActiveService == "" { return nil, nil, fmt.Errorf("Invalid Spec: Rollout missing field ActiveService") } - activeSvc, err = c.getReferencedService(r, r.Spec.Strategy.BlueGreenStrategy.ActiveService) + activeSvc, err = c.getReferencedService(r, r.Spec.Strategy.BlueGreen.ActiveService) if err != nil { return nil, nil, err } @@ -158,11 +158,11 @@ func (c *RolloutController) getPreviewAndActiveServices(r *v1alpha1.Rollout) (*c func (c *RolloutController) reconcileCanaryService(roCtx *canaryContext) error { r := roCtx.Rollout() newRS := roCtx.NewRS() - if r.Spec.Strategy.CanaryStrategy == nil || r.Spec.Strategy.CanaryStrategy.CanaryService == "" { + if r.Spec.Strategy.Canary == nil || r.Spec.Strategy.Canary.CanaryService == "" { return nil } - svc, err := c.getReferencedService(r, r.Spec.Strategy.CanaryStrategy.CanaryService) + svc, err := c.getReferencedService(r, r.Spec.Strategy.Canary.CanaryService) if err != nil { return err } diff --git a/rollout/service_test.go b/rollout/service_test.go index 23042135a8..a6aa0c8f26 100644 --- a/rollout/service_test.go +++ b/rollout/service_test.go @@ -164,7 +164,7 @@ func TestGetPreviewAndActiveServices(t *testing.T) { }, Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + BlueGreen: &v1alpha1.BlueGreenStrategy{ PreviewService: "preview", ActiveService: "active", }, @@ -180,14 +180,14 @@ func TestGetPreviewAndActiveServices(t *testing.T) { }) t.Run("Preview not found", func(t *testing.T) { noPreviewSvcRollout := rollout.DeepCopy() - noPreviewSvcRollout.Spec.Strategy.BlueGreenStrategy.PreviewService = "not-preview" + noPreviewSvcRollout.Spec.Strategy.BlueGreen.PreviewService = "not-preview" _, _, err := c.getPreviewAndActiveServices(noPreviewSvcRollout) assert.NotNil(t, err) assert.True(t, errors.IsNotFound(err)) }) t.Run("Active not found", func(t *testing.T) { noActiveSvcRollout := rollout.DeepCopy() - noActiveSvcRollout.Spec.Strategy.BlueGreenStrategy.ActiveService = "not-active" + noActiveSvcRollout.Spec.Strategy.BlueGreen.ActiveService = "not-active" _, _, err := c.getPreviewAndActiveServices(noActiveSvcRollout) assert.NotNil(t, err) assert.True(t, errors.IsNotFound(err)) @@ -195,7 +195,7 @@ func TestGetPreviewAndActiveServices(t *testing.T) { t.Run("Invalid Spec: No Active Svc", func(t *testing.T) { noActiveSvcRollout := rollout.DeepCopy() - noActiveSvcRollout.Spec.Strategy.BlueGreenStrategy.ActiveService = "" + noActiveSvcRollout.Spec.Strategy.BlueGreen.ActiveService = "" _, _, err := c.getPreviewAndActiveServices(noActiveSvcRollout) assert.NotNil(t, err) assert.EqualError(t, err, "Invalid Spec: Rollout missing field ActiveService") diff --git a/rollout/sync.go b/rollout/sync.go index 437d092448..c939163a36 100644 --- a/rollout/sync.go +++ b/rollout/sync.go @@ -214,7 +214,7 @@ func (c *RolloutController) syncReplicasOnly(r *v1alpha1.Rollout, rsList []*apps return err } // NOTE: it is possible for newRS to be nil (e.g. when template and replicas changed at same time) - if r.Spec.Strategy.BlueGreenStrategy != nil { + if r.Spec.Strategy.BlueGreen != nil { roCtx := newBlueGreenCtx(r, newRS, oldRSs) previewSvc, activeSvc, err := c.getPreviewAndActiveServices(r) if err != nil { @@ -229,7 +229,7 @@ func (c *RolloutController) syncReplicasOnly(r *v1alpha1.Rollout, rsList []*apps } // The controller wants to use the rolloutCanary method to reconcile the rolllout if the rollout is not paused. // If there are no scaling events, the rollout should only sync its status - if r.Spec.Strategy.CanaryStrategy != nil { + if r.Spec.Strategy.Canary != nil { exList, err := c.getExperimentsForRollout(r) if err != nil { return err @@ -518,10 +518,10 @@ func (c *RolloutController) calculateRolloutConditions(roCtx rolloutContext, new } activeRS, _ := replicasetutil.GetReplicaSetByTemplateHash(allRSs, newStatus.BlueGreen.ActiveSelector) - if r.Spec.Strategy.BlueGreenStrategy != nil && activeRS != nil && annotations.IsSaturated(r, activeRS) { + if r.Spec.Strategy.BlueGreen != nil && activeRS != nil && annotations.IsSaturated(r, activeRS) { availability := conditions.NewRolloutCondition(v1alpha1.RolloutAvailable, corev1.ConditionTrue, conditions.AvailableReason, conditions.AvailableMessage) conditions.SetRolloutCondition(&newStatus, *availability) - } else if r.Spec.Strategy.CanaryStrategy != nil && replicasetutil.GetAvailableReplicaCountForReplicaSets(allRSs) >= defaults.GetRolloutReplicasOrDefault(r) { + } else if r.Spec.Strategy.Canary != nil && replicasetutil.GetAvailableReplicaCountForReplicaSets(allRSs) >= defaults.GetRolloutReplicasOrDefault(r) { availability := conditions.NewRolloutCondition(v1alpha1.RolloutAvailable, corev1.ConditionTrue, conditions.AvailableReason, conditions.AvailableMessage) conditions.SetRolloutCondition(&newStatus, *availability) } else { diff --git a/rollout/sync_test.go b/rollout/sync_test.go index a9dd4a0aa2..137a6f31cf 100644 --- a/rollout/sync_test.go +++ b/rollout/sync_test.go @@ -20,7 +20,7 @@ import ( func newRolloutWithStatus(name string, replicas int, revisionHistoryLimit *int32, selector map[string]string) *v1alpha1.Rollout { rollout := newRollout(name, replicas, revisionHistoryLimit, selector) - rollout.Spec.Strategy.BlueGreenStrategy = &v1alpha1.BlueGreenStrategy{} + rollout.Spec.Strategy.BlueGreen = &v1alpha1.BlueGreenStrategy{} return rollout } diff --git a/service/service_test.go b/service/service_test.go index f1c7e5bb24..db2b2af30b 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -111,7 +111,7 @@ func TestSyncServiceReferencedByRollout(t *testing.T) { }, Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + BlueGreen: &v1alpha1.BlueGreenStrategy{ ActiveService: "test-service", PreviewService: "test-service-preview", }, diff --git a/utils/conditions/conditions.go b/utils/conditions/conditions.go index 3215a9dce4..302249246e 100644 --- a/utils/conditions/conditions.go +++ b/utils/conditions/conditions.go @@ -189,13 +189,13 @@ func RolloutProgressing(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutSt oldStatus := rollout.Status strategySpecificProgress := false - if rollout.Spec.Strategy.BlueGreenStrategy != nil { + if rollout.Spec.Strategy.BlueGreen != nil { activeSelectorChange := rollout.Status.BlueGreen.ActiveSelector != newStatus.BlueGreen.ActiveSelector previewSelectorChange := rollout.Status.BlueGreen.PreviewSelector != newStatus.BlueGreen.PreviewSelector strategySpecificProgress = activeSelectorChange || previewSelectorChange } - if rollout.Spec.Strategy.CanaryStrategy != nil { + if rollout.Spec.Strategy.Canary != nil { stableRSChange := newStatus.Canary.StableRS != oldStatus.Canary.StableRS incrementStepIndex := false if newStatus.CurrentStepIndex != nil && oldStatus.CurrentStepIndex != nil { @@ -220,16 +220,16 @@ func RolloutProgressing(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutSt // are updated, available, and receiving traffic from the active service, and no old pods are running. func RolloutComplete(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutStatus) bool { completedStrategy := true - if rollout.Spec.Strategy.BlueGreenStrategy != nil { + if rollout.Spec.Strategy.BlueGreen != nil { activeSelectorComplete := newStatus.BlueGreen.ActiveSelector == newStatus.CurrentPodHash previewSelectorComplete := true - if rollout.Spec.Strategy.BlueGreenStrategy.PreviewService != "" { + if rollout.Spec.Strategy.BlueGreen.PreviewService != "" { previewSelectorComplete = newStatus.BlueGreen.PreviewSelector == "" } completedStrategy = activeSelectorComplete && previewSelectorComplete } - if rollout.Spec.Strategy.CanaryStrategy != nil { - stepCount := len(rollout.Spec.Strategy.CanaryStrategy.Steps) + if rollout.Spec.Strategy.Canary != nil { + stepCount := len(rollout.Spec.Strategy.Canary.Steps) executedAllSteps := true if stepCount > 0 && newStatus.CurrentStepIndex != nil { executedAllSteps = int32(stepCount) == *newStatus.CurrentStepIndex @@ -249,11 +249,11 @@ func RolloutComplete(rollout *v1alpha1.Rollout, newStatus *v1alpha1.RolloutStatu // ComputeStepHash returns a hash value calculated from the Rollout's steps. The hash will // be safe encoded to avoid bad words. func ComputeStepHash(rollout *v1alpha1.Rollout) string { - if rollout.Spec.Strategy.BlueGreenStrategy != nil || rollout.Spec.Strategy.CanaryStrategy == nil { + if rollout.Spec.Strategy.BlueGreen != nil || rollout.Spec.Strategy.Canary == nil { return "" } rolloutStepHasher := fnv.New32a() - stepsBytes, err := json.Marshal(rollout.Spec.Strategy.CanaryStrategy.Steps) + stepsBytes, err := json.Marshal(rollout.Spec.Strategy.Canary.Steps) if err != nil { panic(err) } @@ -292,12 +292,12 @@ func VerifyRolloutSpec(rollout *v1alpha1.Rollout, prevCond *v1alpha1.RolloutCond return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, RolloutSelectAllMessage) } - if rollout.Spec.Strategy.CanaryStrategy == nil && rollout.Spec.Strategy.BlueGreenStrategy == nil { - message := fmt.Sprintf(MissingFieldMessage, ".Spec.Strategy.CanaryStrategy or .Spec.Strategy.BlueGreen") + if rollout.Spec.Strategy.Canary == nil && rollout.Spec.Strategy.BlueGreen == nil { + message := fmt.Sprintf(MissingFieldMessage, ".Spec.Strategy.Canary or .Spec.Strategy.BlueGreen") return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, message) } - if rollout.Spec.Strategy.CanaryStrategy != nil && rollout.Spec.Strategy.BlueGreenStrategy != nil { + if rollout.Spec.Strategy.Canary != nil && rollout.Spec.Strategy.BlueGreen != nil { return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, InvalidStrategyMessage) } @@ -305,25 +305,25 @@ func VerifyRolloutSpec(rollout *v1alpha1.Rollout, prevCond *v1alpha1.RolloutCond return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, RolloutMinReadyLongerThanDeadlineMessage) } - if rollout.Spec.Strategy.BlueGreenStrategy != nil { - if rollout.Spec.Strategy.BlueGreenStrategy.ActiveService == "" { - message := fmt.Sprintf(MissingFieldMessage, ".Spec.Strategy.BlueGreenStrategy.ActiveService") + if rollout.Spec.Strategy.BlueGreen != nil { + if rollout.Spec.Strategy.BlueGreen.ActiveService == "" { + message := fmt.Sprintf(MissingFieldMessage, ".Spec.Strategy.BlueGreen.ActiveService") return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, message) } - if rollout.Spec.Strategy.BlueGreenStrategy.ActiveService == rollout.Spec.Strategy.BlueGreenStrategy.PreviewService { + if rollout.Spec.Strategy.BlueGreen.ActiveService == rollout.Spec.Strategy.BlueGreen.PreviewService { return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, DuplicatedServicesMessage) } revisionHistoryLimit := defaults.GetRevisionHistoryLimitOrDefault(rollout) - if rollout.Spec.Strategy.BlueGreenStrategy.ScaleDownDelayRevisionLimit != nil && revisionHistoryLimit < *rollout.Spec.Strategy.BlueGreenStrategy.ScaleDownDelayRevisionLimit { + if rollout.Spec.Strategy.BlueGreen.ScaleDownDelayRevisionLimit != nil && revisionHistoryLimit < *rollout.Spec.Strategy.BlueGreen.ScaleDownDelayRevisionLimit { return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, ScaleDownLimitLargerThanRevisionLimit) } } - if rollout.Spec.Strategy.CanaryStrategy != nil { + if rollout.Spec.Strategy.Canary != nil { if invalidMaxSurgeMaxUnavailable(rollout) { return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, InvalidMaxSurgeMaxUnavailable) } - for _, step := range rollout.Spec.Strategy.CanaryStrategy.Steps { + for _, step := range rollout.Spec.Strategy.Canary.Steps { if hasMultipleStepsType(step) { return newInvalidSpecRolloutCondition(prevCond, InvalidSpecReason, InvalidStepMessage) } diff --git a/utils/conditions/rollouts_test.go b/utils/conditions/rollouts_test.go index f276f5860e..946171527c 100644 --- a/utils/conditions/rollouts_test.go +++ b/utils/conditions/rollouts_test.go @@ -234,7 +234,7 @@ func TestVerifyRolloutSpecBlueGreen(t *testing.T) { MatchLabels: map[string]string{"key": "value"}, }, Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + BlueGreen: &v1alpha1.BlueGreenStrategy{ PreviewService: "preview", ActiveService: "active", }, @@ -244,21 +244,21 @@ func TestVerifyRolloutSpecBlueGreen(t *testing.T) { assert.Nil(t, VerifyRolloutSpec(validRollout, nil)) noActiveSvc := validRollout.DeepCopy() - noActiveSvc.Spec.Strategy.BlueGreenStrategy.ActiveService = "" + noActiveSvc.Spec.Strategy.BlueGreen.ActiveService = "" noActiveSvcCond := VerifyRolloutSpec(noActiveSvc, nil) assert.NotNil(t, noActiveSvcCond) - assert.Equal(t, fmt.Sprintf(MissingFieldMessage, ".Spec.Strategy.BlueGreenStrategy.ActiveService"), noActiveSvcCond.Message) + assert.Equal(t, fmt.Sprintf(MissingFieldMessage, ".Spec.Strategy.BlueGreen.ActiveService"), noActiveSvcCond.Message) assert.Equal(t, InvalidSpecReason, noActiveSvcCond.Reason) sameSvcs := validRollout.DeepCopy() - sameSvcs.Spec.Strategy.BlueGreenStrategy.ActiveService = "preview" + sameSvcs.Spec.Strategy.BlueGreen.ActiveService = "preview" sameSvcsCond := VerifyRolloutSpec(sameSvcs, nil) assert.NotNil(t, sameSvcsCond) assert.Equal(t, DuplicatedServicesMessage, sameSvcsCond.Message) assert.Equal(t, InvalidSpecReason, sameSvcsCond.Reason) scaleLimitLargerThanRevision := validRollout.DeepCopy() - scaleLimitLargerThanRevision.Spec.Strategy.BlueGreenStrategy.ScaleDownDelayRevisionLimit = pointer.Int32Ptr(100) + scaleLimitLargerThanRevision.Spec.Strategy.BlueGreen.ScaleDownDelayRevisionLimit = pointer.Int32Ptr(100) scaleLimitLargerThanRevisionCond := VerifyRolloutSpec(scaleLimitLargerThanRevision, nil) assert.NotNil(t, scaleLimitLargerThanRevisionCond) assert.Equal(t, ScaleDownLimitLargerThanRevisionLimit, scaleLimitLargerThanRevisionCond.Message) @@ -272,8 +272,8 @@ func TestVerifyRolloutSpecBaseCases(t *testing.T) { MatchLabels: map[string]string{"key": "value"}, }, Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{}, - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + Canary: &v1alpha1.CanaryStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{ ActiveService: "active", }, }, @@ -285,7 +285,7 @@ func TestVerifyRolloutSpecBaseCases(t *testing.T) { assert.Equal(t, InvalidStrategyMessage, cond.Message) validRollout := ro.DeepCopy() - validRollout.Spec.Strategy.CanaryStrategy = nil + validRollout.Spec.Strategy.Canary = nil validRolloutCond := VerifyRolloutSpec(validRollout, nil) assert.Nil(t, validRolloutCond) @@ -393,7 +393,7 @@ func TestVerifyRolloutSpecCanary(t *testing.T) { MatchLabels: map[string]string{"key": "value"}, }, Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ MaxUnavailable: test.maxUnavailable, MaxSurge: test.maxSurge, Steps: test.steps, @@ -418,7 +418,7 @@ func TestInvalidMaxSurgeMaxUnavailable(t *testing.T) { return &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ MaxSurge: &maxSurge, MaxUnavailable: &maxUnavailable, }, @@ -473,7 +473,7 @@ func TestRolloutProgressing(t *testing.T) { return &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{}, }, }, Status: blueGreenStatus(current, updated, ready, available, activeSelector, previewSelector), @@ -483,7 +483,7 @@ func TestRolloutProgressing(t *testing.T) { return &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{}, + Canary: &v1alpha1.CanaryStrategy{}, }, }, Status: canaryStatus(current, updated, ready, available, stableRS, index, stepHash), @@ -592,7 +592,7 @@ func TestRolloutComplete(t *testing.T) { blueGreenRollout := func(desired, current, updated, available int32, correctObservedGeneration bool, activeSelector, previewSelector string) *v1alpha1.Rollout { r := rollout(desired, current, updated, available, correctObservedGeneration) r.Spec.Strategy = v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + BlueGreen: &v1alpha1.BlueGreenStrategy{ PreviewService: "preview", ActiveService: "active", }, @@ -612,7 +612,7 @@ func TestRolloutComplete(t *testing.T) { steps = append(steps, v1alpha1.CanaryStep{SetWeight: pointer.Int32Ptr(30)}) } r.Spec.Strategy = v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ Steps: steps, }, } @@ -787,7 +787,7 @@ func TestComputeStepHash(t *testing.T) { ro := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ Steps: []v1alpha1.CanaryStep{ { Pause: &v1alpha1.RolloutPause{}, @@ -799,7 +799,7 @@ func TestComputeStepHash(t *testing.T) { } baseline := ComputeStepHash(ro) roWithDiffSteps := ro.DeepCopy() - roWithDiffSteps.Spec.Strategy.CanaryStrategy.Steps = []v1alpha1.CanaryStep{ + roWithDiffSteps.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{ { Pause: &v1alpha1.RolloutPause{}, }, @@ -817,13 +817,13 @@ func TestComputeStepHash(t *testing.T) { assert.Equal(t, "6b9b86fbd5", roWithSameStepsHash) roNoSteps := ro.DeepCopy() - roNoSteps.Spec.Strategy.CanaryStrategy.Steps = nil + roNoSteps.Spec.Strategy.Canary.Steps = nil roNoStepsHash := ComputeStepHash(roNoSteps) assert.Equal(t, "5ffbfbbd64", roNoStepsHash) roBlueGreen := ro.DeepCopy() - roBlueGreen.Spec.Strategy.CanaryStrategy = nil - roBlueGreen.Spec.Strategy.BlueGreenStrategy = &v1alpha1.BlueGreenStrategy{} + roBlueGreen.Spec.Strategy.Canary = nil + roBlueGreen.Spec.Strategy.BlueGreen = &v1alpha1.BlueGreenStrategy{} roBlueGreenHash := ComputeStepHash(roBlueGreen) assert.Equal(t, "", roBlueGreenHash) diff --git a/utils/defaults/defaults.go b/utils/defaults/defaults.go index 45194f2d37..54870614dc 100644 --- a/utils/defaults/defaults.go +++ b/utils/defaults/defaults.go @@ -48,26 +48,26 @@ func GetRevisionHistoryLimitOrDefault(rollout *v1alpha1.Rollout) int32 { } func GetMaxSurgeOrDefault(rollout *v1alpha1.Rollout) *intstr.IntOrString { - if rollout.Spec.Strategy.CanaryStrategy != nil && rollout.Spec.Strategy.CanaryStrategy.MaxSurge != nil { - return rollout.Spec.Strategy.CanaryStrategy.MaxSurge + if rollout.Spec.Strategy.Canary != nil && rollout.Spec.Strategy.Canary.MaxSurge != nil { + return rollout.Spec.Strategy.Canary.MaxSurge } defaultValue := intstr.FromString(DefaultMaxSurge) return &defaultValue } func GetMaxUnavailableOrDefault(rollout *v1alpha1.Rollout) *intstr.IntOrString { - if rollout.Spec.Strategy.CanaryStrategy != nil && rollout.Spec.Strategy.CanaryStrategy.MaxUnavailable != nil { - return rollout.Spec.Strategy.CanaryStrategy.MaxUnavailable + if rollout.Spec.Strategy.Canary != nil && rollout.Spec.Strategy.Canary.MaxUnavailable != nil { + return rollout.Spec.Strategy.Canary.MaxUnavailable } defaultValue := intstr.FromInt(DefaultMaxUnavailable) return &defaultValue } func GetStrategyType(rollout *v1alpha1.Rollout) string { - if rollout.Spec.Strategy.BlueGreenStrategy != nil { + if rollout.Spec.Strategy.BlueGreen != nil { return "blueGreen" } - if rollout.Spec.Strategy.CanaryStrategy != nil { + if rollout.Spec.Strategy.Canary != nil { return "canary" } return "No Strategy listed" @@ -88,23 +88,23 @@ func GetExperimentProgressDeadlineSecondsOrDefault(e *v1alpha1.Experiment) int32 } func GetScaleDownDelaySecondsOrDefault(rollout *v1alpha1.Rollout) int32 { - if rollout.Spec.Strategy.BlueGreenStrategy == nil { + if rollout.Spec.Strategy.BlueGreen == nil { return DefaultScaleDownDelaySeconds } - if rollout.Spec.Strategy.BlueGreenStrategy.ScaleDownDelaySeconds == nil { + if rollout.Spec.Strategy.BlueGreen.ScaleDownDelaySeconds == nil { return DefaultScaleDownDelaySeconds } - return *rollout.Spec.Strategy.BlueGreenStrategy.ScaleDownDelaySeconds + return *rollout.Spec.Strategy.BlueGreen.ScaleDownDelaySeconds } func GetAutoPromotionEnabledOrDefault(rollout *v1alpha1.Rollout) bool { - if rollout.Spec.Strategy.BlueGreenStrategy == nil { + if rollout.Spec.Strategy.BlueGreen == nil { return DefaultAutoPromotionEnabled } - if rollout.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled == nil { + if rollout.Spec.Strategy.BlueGreen.AutoPromotionEnabled == nil { return DefaultAutoPromotionEnabled } - return *rollout.Spec.Strategy.BlueGreenStrategy.AutoPromotionEnabled -} \ No newline at end of file + return *rollout.Spec.Strategy.BlueGreen.AutoPromotionEnabled +} diff --git a/utils/defaults/defaults_test.go b/utils/defaults/defaults_test.go index 72381a43ae..89660ea0ea 100644 --- a/utils/defaults/defaults_test.go +++ b/utils/defaults/defaults_test.go @@ -51,7 +51,7 @@ func TestGetMaxSurgeOrDefault(t *testing.T) { rolloutNonDefaultValue := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ MaxSurge: &maxSurge, }, }, @@ -68,7 +68,7 @@ func TestGetMaxUnavailableOrDefault(t *testing.T) { rolloutNonDefaultValue := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ MaxUnavailable: &maxUnavailable, }, }, @@ -84,7 +84,7 @@ func TestGetStrategyType(t *testing.T) { bgRollout := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{}, }, }, } @@ -93,7 +93,7 @@ func TestGetStrategyType(t *testing.T) { canaryRollout := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{}, + Canary: &v1alpha1.CanaryStrategy{}, }, }, } @@ -125,7 +125,7 @@ func TestGetScaleDownDelaySecondsOrDefault(t *testing.T) { rolloutNonDefaultValue := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + BlueGreen: &v1alpha1.BlueGreenStrategy{ ScaleDownDelaySeconds: &scaleDownDelaySeconds, }, }, @@ -138,7 +138,7 @@ func TestGetScaleDownDelaySecondsOrDefault(t *testing.T) { rolloutNoScaleDownDelaySeconds := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{}, }, }, } @@ -150,7 +150,7 @@ func TestGetAutoPromotionEnabledOrDefault(t *testing.T) { rolloutNonDefaultValue := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + BlueGreen: &v1alpha1.BlueGreenStrategy{ AutoPromotionEnabled: &autoPromote, }, }, @@ -163,7 +163,7 @@ func TestGetAutoPromotionEnabledOrDefault(t *testing.T) { rolloutNoAutoPromotionEnabled := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{}, }, }, } diff --git a/utils/experiment/experiment_test.go b/utils/experiment/experiment_test.go index cfd33b6dca..e44d817636 100644 --- a/utils/experiment/experiment_test.go +++ b/utils/experiment/experiment_test.go @@ -151,7 +151,7 @@ func TestExperimentGeneratedNameFromRollout(t *testing.T) { }, Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ Steps: []v1alpha1.CanaryStep{{ Experiment: &v1alpha1.RolloutExperimentStep{}, }}, diff --git a/utils/replicaset/bluegreen_test.go b/utils/replicaset/bluegreen_test.go index 21a0c1672d..c4228b7538 100644 --- a/utils/replicaset/bluegreen_test.go +++ b/utils/replicaset/bluegreen_test.go @@ -39,7 +39,7 @@ func TestReadyForPause(t *testing.T) { rollout := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{}, }, }, } diff --git a/utils/replicaset/canary.go b/utils/replicaset/canary.go index f762fb3594..ba3561f9a1 100644 --- a/utils/replicaset/canary.go +++ b/utils/replicaset/canary.go @@ -223,17 +223,17 @@ func extraReplicaAdded(replicas int32, setWeight int32) bool { // GetCurrentCanaryStep returns the current canary step. If there are no steps or the rollout // has already executed the last step, the func returns nil func GetCurrentCanaryStep(rollout *v1alpha1.Rollout) (*v1alpha1.CanaryStep, *int32) { - if len(rollout.Spec.Strategy.CanaryStrategy.Steps) == 0 { + if len(rollout.Spec.Strategy.Canary.Steps) == 0 { return nil, nil } currentStepIndex := int32(0) if rollout.Status.CurrentStepIndex != nil { currentStepIndex = *rollout.Status.CurrentStepIndex } - if len(rollout.Spec.Strategy.CanaryStrategy.Steps) <= int(currentStepIndex) { + if len(rollout.Spec.Strategy.Canary.Steps) <= int(currentStepIndex) { return nil, ¤tStepIndex } - return &rollout.Spec.Strategy.CanaryStrategy.Steps[currentStepIndex], ¤tStepIndex + return &rollout.Spec.Strategy.Canary.Steps[currentStepIndex], ¤tStepIndex } // GetCurrentSetWeight grabs the current setWeight used by the rollout by iterating backwards from the current step @@ -246,7 +246,7 @@ func GetCurrentSetWeight(rollout *v1alpha1.Rollout) int32 { } for i := *currentStepIndex; i >= 0; i-- { - step := rollout.Spec.Strategy.CanaryStrategy.Steps[i] + step := rollout.Spec.Strategy.Canary.Steps[i] if step.SetWeight != nil { return *step.SetWeight } @@ -284,7 +284,7 @@ func GetCurrentExperimentStep(r *v1alpha1.Rollout) *v1alpha1.RolloutExperimentSt } for i := *currentStepIndex; i >= 0; i-- { - step := r.Spec.Strategy.CanaryStrategy.Steps[i] + step := r.Spec.Strategy.Canary.Steps[i] if step.Experiment != nil { return step.Experiment } diff --git a/utils/replicaset/canary_test.go b/utils/replicaset/canary_test.go index 4e59d5d22f..3a0524eadf 100644 --- a/utils/replicaset/canary_test.go +++ b/utils/replicaset/canary_test.go @@ -17,7 +17,7 @@ func newRollout(specReplicas, setWeight int32, maxSurge, maxUnavailable intstr.I Spec: v1alpha1.RolloutSpec{ Replicas: &specReplicas, Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ MaxUnavailable: &maxUnavailable, MaxSurge: &maxSurge, Steps: []v1alpha1.CanaryStep{{ @@ -390,11 +390,11 @@ func TestCalculateReplicaCountsForCanaryStableRSdEdgeCases(t *testing.T) { func TestGetCurrentCanaryStep(t *testing.T) { rollout := newRollout(10, 10, intstr.FromInt(0), intstr.FromInt(1), "", "") - rollout.Spec.Strategy.CanaryStrategy.Steps = nil + rollout.Spec.Strategy.Canary.Steps = nil noCurrentSteps, _ := GetCurrentCanaryStep(rollout) assert.Nil(t, noCurrentSteps) - rollout.Spec.Strategy.CanaryStrategy.Steps = []v1alpha1.CanaryStep{{ + rollout.Spec.Strategy.Canary.Steps = []v1alpha1.CanaryStep{{ Pause: &v1alpha1.RolloutPause{}, }} rollout.Status.CurrentStepIndex = func(i int32) *int32 { return &i }(0) @@ -426,7 +426,7 @@ func TestGetCurrentExperiment(t *testing.T) { rollout := &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ Steps: []v1alpha1.CanaryStep{ { Experiment: &v1alpha1.RolloutExperimentStep{ @@ -454,7 +454,7 @@ func TestGetCurrentExperiment(t *testing.T) { assert.Nil(t, GetCurrentExperimentStep(rollout)) - rollout.Spec.Strategy.CanaryStrategy.Steps[0] = v1alpha1.CanaryStep{SetWeight: pointer.Int32Ptr(10)} + rollout.Spec.Strategy.Canary.Steps[0] = v1alpha1.CanaryStep{SetWeight: pointer.Int32Ptr(10)} rollout.Status.CurrentStepIndex = pointer.Int32Ptr(1) assert.Nil(t, GetCurrentExperimentStep(rollout)) diff --git a/utils/replicaset/replicaset.go b/utils/replicaset/replicaset.go index 5b103aea72..6378611aa1 100644 --- a/utils/replicaset/replicaset.go +++ b/utils/replicaset/replicaset.go @@ -76,24 +76,24 @@ func FindOldReplicaSets(rollout *v1alpha1.Rollout, rsList []*appsv1.ReplicaSet) // 1) The new RS is saturated: newRS's replicas == deployment's replicas // 2) Max number of pods allowed is reached: deployment's replicas + maxSurge == all RSs' replicas func NewRSNewReplicas(rollout *v1alpha1.Rollout, allRSs []*appsv1.ReplicaSet, newRS *appsv1.ReplicaSet) (int32, error) { - if rollout.Spec.Strategy.BlueGreenStrategy != nil { - if rollout.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount != nil { + if rollout.Spec.Strategy.BlueGreen != nil { + if rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount != nil { activeRS, _ := GetReplicaSetByTemplateHash(allRSs, rollout.Status.BlueGreen.ActiveSelector) if activeRS == nil || activeRS.Name == newRS.Name { return defaults.GetRolloutReplicasOrDefault(rollout), nil } if newRS.Labels[v1alpha1.DefaultRolloutUniqueLabelKey] != rollout.Status.CurrentPodHash { - return *rollout.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount, nil + return *rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount, nil } if !rollout.Spec.Paused && rollout.Status.BlueGreen.ScaleUpPreviewCheckPoint { return defaults.GetRolloutReplicasOrDefault(rollout), nil } - return *rollout.Spec.Strategy.BlueGreenStrategy.PreviewReplicaCount, nil + return *rollout.Spec.Strategy.BlueGreen.PreviewReplicaCount, nil } return defaults.GetRolloutReplicasOrDefault(rollout), nil } - if rollout.Spec.Strategy.CanaryStrategy != nil { + if rollout.Spec.Strategy.Canary != nil { stableRS, olderRSs := GetStableRS(rollout, newRS, allRSs) newRSReplicaCount, _ := CalculateReplicaCountsForCanary(rollout, newRS, stableRS, olderRSs) return newRSReplicaCount, nil @@ -229,7 +229,7 @@ func resolveFenceposts(maxSurge, maxUnavailable *intstrutil.IntOrString, desired // MaxUnavailable returns the maximum unavailable pods a rolling deployment can take. func MaxUnavailable(rollout *v1alpha1.Rollout) int32 { rolloutReplicas := defaults.GetRolloutReplicasOrDefault(rollout) - if rollout.Spec.Strategy.CanaryStrategy == nil || rolloutReplicas == 0 { + if rollout.Spec.Strategy.Canary == nil || rolloutReplicas == 0 { return int32(0) } @@ -244,7 +244,7 @@ func MaxUnavailable(rollout *v1alpha1.Rollout) int32 { // MaxSurge returns the maximum surge pods a rolling deployment can take. func MaxSurge(rollout *v1alpha1.Rollout) int32 { rolloutReplicas := defaults.GetRolloutReplicasOrDefault(rollout) - if rollout.Spec.Strategy.CanaryStrategy == nil { + if rollout.Spec.Strategy.Canary == nil { return int32(0) } // Error caught by validation @@ -299,7 +299,7 @@ func PodTemplateOrStepsChanged(rollout *v1alpha1.Rollout, newRS *appsv1.ReplicaS // ResetCurrentStepIndex resets the index back to zero unless there are no steps func ResetCurrentStepIndex(rollout *v1alpha1.Rollout) *int32 { - if len(rollout.Spec.Strategy.CanaryStrategy.Steps) > 0 { + if len(rollout.Spec.Strategy.Canary.Steps) > 0 { return pointer.Int32Ptr(0) } return nil diff --git a/utils/replicaset/replicaset_test.go b/utils/replicaset/replicaset_test.go index cee618211b..9a7b081fa0 100644 --- a/utils/replicaset/replicaset_test.go +++ b/utils/replicaset/replicaset_test.go @@ -187,12 +187,12 @@ func TestGetReplicaCountForReplicaSets(t *testing.T) { func TestNewRSNewReplicas(t *testing.T) { ro := generateRollout("test") - ro.Spec.Strategy.BlueGreenStrategy = &v1alpha1.BlueGreenStrategy{} + ro.Spec.Strategy.BlueGreen = &v1alpha1.BlueGreenStrategy{} blueGreenNewRSCount, err := NewRSNewReplicas(&ro, nil, nil) assert.Nil(t, err) assert.Equal(t, blueGreenNewRSCount, *ro.Spec.Replicas) - ro.Spec.Strategy.BlueGreenStrategy = nil + ro.Spec.Strategy.BlueGreen = nil _, err = NewRSNewReplicas(&ro, nil, nil) assert.Error(t, err, "no rollout strategy provided") } @@ -256,7 +256,7 @@ func TestNewRSNewReplicasWitPreviewReplicaCount(t *testing.T) { Spec: v1alpha1.RolloutSpec{ Replicas: &replicaCount, Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + BlueGreen: &v1alpha1.BlueGreenStrategy{ PreviewReplicaCount: &previewReplicaCount, }, }, @@ -502,7 +502,7 @@ func TestMaxSurge(t *testing.T) { Spec: v1alpha1.RolloutSpec{ Replicas: func(i int32) *int32 { return &i }(replicas), Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ MaxUnavailable: func(i int) *intstr.IntOrString { x := intstr.FromInt(i); return &x }(int(1)), MaxSurge: &maxSurge, }, @@ -525,7 +525,7 @@ func TestMaxSurge(t *testing.T) { rollout: &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{}, }, }, }, @@ -551,7 +551,7 @@ func TestMaxUnavailable(t *testing.T) { Spec: v1alpha1.RolloutSpec{ Replicas: func(i int32) *int32 { return &i }(replicas), Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ MaxSurge: func(i int) *intstr.IntOrString { x := intstr.FromInt(i); return &x }(int(1)), MaxUnavailable: &maxUnavailable, }, @@ -589,7 +589,7 @@ func TestMaxUnavailable(t *testing.T) { rollout: &v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{}, + BlueGreen: &v1alpha1.BlueGreenStrategy{}, }, }, }, @@ -642,7 +642,7 @@ func TestCheckStepHashChange(t *testing.T) { func TestResetCurrentStepIndex(t *testing.T) { ro := generateRollout("ngnix") - ro.Spec.Strategy.CanaryStrategy = &v1alpha1.CanaryStrategy{ + ro.Spec.Strategy.Canary = &v1alpha1.CanaryStrategy{ Steps: []v1alpha1.CanaryStep{ { SetWeight: pointer.Int32Ptr(1), @@ -652,7 +652,7 @@ func TestResetCurrentStepIndex(t *testing.T) { newStepIndex := ResetCurrentStepIndex(&ro) assert.Equal(t, pointer.Int32Ptr(0), newStepIndex) - ro.Spec.Strategy.CanaryStrategy.Steps = nil + ro.Spec.Strategy.Canary.Steps = nil newStepIndex = ResetCurrentStepIndex(&ro) assert.Nil(t, newStepIndex) diff --git a/utils/service/service.go b/utils/service/service.go index c9cb7c7558..7227165f5f 100644 --- a/utils/service/service.go +++ b/utils/service/service.go @@ -22,16 +22,16 @@ func GetRolloutSelectorLabel(svc *corev1.Service) (string, bool) { // GetRolloutServiceKeys returns services keys (namespace/serviceName) which are referenced by specified rollout func GetRolloutServiceKeys(rollout *v1alpha1.Rollout) []string { servicesSet := make(map[string]bool) - if rollout.Spec.Strategy.BlueGreenStrategy != nil { - if rollout.Spec.Strategy.BlueGreenStrategy.ActiveService != "" { - servicesSet[fmt.Sprintf("%s/%s", rollout.Namespace, rollout.Spec.Strategy.BlueGreenStrategy.ActiveService)] = true + if rollout.Spec.Strategy.BlueGreen != nil { + if rollout.Spec.Strategy.BlueGreen.ActiveService != "" { + servicesSet[fmt.Sprintf("%s/%s", rollout.Namespace, rollout.Spec.Strategy.BlueGreen.ActiveService)] = true } - if rollout.Spec.Strategy.BlueGreenStrategy.PreviewService != "" { - servicesSet[fmt.Sprintf("%s/%s", rollout.Namespace, rollout.Spec.Strategy.BlueGreenStrategy.PreviewService)] = true + if rollout.Spec.Strategy.BlueGreen.PreviewService != "" { + servicesSet[fmt.Sprintf("%s/%s", rollout.Namespace, rollout.Spec.Strategy.BlueGreen.PreviewService)] = true } - } else if rollout.Spec.Strategy.CanaryStrategy != nil { - if rollout.Spec.Strategy.CanaryStrategy.CanaryService != "" { - servicesSet[fmt.Sprintf("%s/%s", rollout.Namespace, rollout.Spec.Strategy.CanaryStrategy.CanaryService)] = true + } else if rollout.Spec.Strategy.Canary != nil { + if rollout.Spec.Strategy.Canary.CanaryService != "" { + servicesSet[fmt.Sprintf("%s/%s", rollout.Namespace, rollout.Spec.Strategy.Canary.CanaryService)] = true } } var services []string diff --git a/utils/service/service_test.go b/utils/service/service_test.go index e2c75e76ee..50622e86eb 100644 --- a/utils/service/service_test.go +++ b/utils/service/service_test.go @@ -38,7 +38,7 @@ func TestGetRolloutServiceKeysForCanary(t *testing.T) { keys := GetRolloutServiceKeys(&v1alpha1.Rollout{ Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{}, + Canary: &v1alpha1.CanaryStrategy{}, }, }, }) @@ -52,7 +52,7 @@ func TestGetRolloutServiceKeysForCanaryWithCanaryService(t *testing.T) { }, Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - CanaryStrategy: &v1alpha1.CanaryStrategy{ + Canary: &v1alpha1.CanaryStrategy{ CanaryService: "canary-service", }, }, @@ -68,7 +68,7 @@ func TestGetRolloutServiceKeysForBlueGreen(t *testing.T) { }, Spec: v1alpha1.RolloutSpec{ Strategy: v1alpha1.RolloutStrategy{ - BlueGreenStrategy: &v1alpha1.BlueGreenStrategy{ + BlueGreen: &v1alpha1.BlueGreenStrategy{ PreviewService: "preview-service", ActiveService: "active-service", },