From 43eaf3c9f40f0bb824fa031bf120b45decbb58aa 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 ef8d053628..fd8ab46848 100644 --- a/rollout/bluegreen.go +++ b/rollout/bluegreen.go @@ -162,22 +162,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) + } } }