From 28303e1c6ed22f467cb775e9be6b4d054f922899 Mon Sep 17 00:00:00 2001 From: yunbo Date: Wed, 29 May 2024 16:09:16 +0800 Subject: [PATCH] safte index check Signed-off-by: yunbo --- pkg/controller/rollout/rollout_progressing.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pkg/controller/rollout/rollout_progressing.go b/pkg/controller/rollout/rollout_progressing.go index 50f825b4..c57bc752 100644 --- a/pkg/controller/rollout/rollout_progressing.go +++ b/pkg/controller/rollout/rollout_progressing.go @@ -518,7 +518,17 @@ func setRolloutSucceededCondition(status *v1beta1.RolloutStatus, condStatus core } func newTrafficRoutingContext(c *RolloutContext) *trafficrouting.TrafficRoutingContext { - currentStep := c.Rollout.Spec.Strategy.GetSteps()[c.NewStatus.GetSubStatus().CurrentStepIndex-1] + currentIndex := c.NewStatus.GetSubStatus().CurrentStepIndex - 1 + var currentStep v1beta1.CanaryStep + //TODO - need better designed logic + if currentIndex < 0 || int(currentIndex) >= len(c.Rollout.Spec.Strategy.GetSteps()) { + klog.Warningf("Rollout(%s/%s) encounters a special case when constructing newTrafficRoutingContext", c.Rollout.Namespace, c.Rollout.Name) + // usually this only happens when deleting the rollout or rolling back + // in this situation, it's no matter which step the current is + currentStep = c.Rollout.Spec.Strategy.GetSteps()[0] + } else { + currentStep = c.Rollout.Spec.Strategy.GetSteps()[currentIndex] + } var revisionLabelKey string if c.Workload != nil { revisionLabelKey = c.Workload.RevisionLabelKey