From 4622ae4a54d8e783f98ca03ef87be885ade849f4 Mon Sep 17 00:00:00 2001 From: Jesse Suen Date: Thu, 29 Jul 2021 14:44:41 -0700 Subject: [PATCH] fix: nil pointer dereference when reconciling paused blue-green rollout (#1378) Signed-off-by: Jesse Suen --- rollout/bluegreen.go | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/rollout/bluegreen.go b/rollout/bluegreen.go index 4fb7b2beba..2e2143d560 100644 --- a/rollout/bluegreen.go +++ b/rollout/bluegreen.go @@ -163,22 +163,24 @@ func (c *rolloutContext) reconcileBlueGreenPause(activeSvc, previewSvc *corev1.S return } pauseCond := getPauseCondition(c.rollout, v1alpha1.PauseReasonBlueGreenPause) - if pauseCond == nil && !c.rollout.Status.ControllerPause { - if pauseCond == nil { - c.log.Info("pausing") - } - c.pauseContext.AddPauseCondition(v1alpha1.PauseReasonBlueGreenPause) - return - } - - if !c.pauseContext.CompletedBlueGreenPause() { - c.log.Info("pause incomplete") - if c.rollout.Spec.Strategy.BlueGreen.AutoPromotionSeconds > 0 { - c.checkEnqueueRolloutDuringWait(pauseCond.StartTime, c.rollout.Spec.Strategy.BlueGreen.AutoPromotionSeconds) + if pauseCond != nil { + // We are currently paused. Check if we completed our pause duration + if !c.pauseContext.CompletedBlueGreenPause() { + c.log.Info("pause incomplete") + if c.rollout.Spec.Strategy.BlueGreen.AutoPromotionSeconds > 0 { + c.checkEnqueueRolloutDuringWait(pauseCond.StartTime, c.rollout.Spec.Strategy.BlueGreen.AutoPromotionSeconds) + } + } else { + c.log.Infof("pause completed") + c.pauseContext.RemovePauseCondition(v1alpha1.PauseReasonBlueGreenPause) } } else { - c.log.Infof("pause completed") - c.pauseContext.RemovePauseCondition(v1alpha1.PauseReasonBlueGreenPause) + // no pause condition exists. If Status.ControllerPause is true, the user manually resumed + // the rollout. e.g. `kubectl argo rollouts promote ROLLOUT` + if !c.rollout.Status.ControllerPause { + c.log.Info("pausing") + c.pauseContext.AddPauseCondition(v1alpha1.PauseReasonBlueGreenPause) + } } }