diff --git a/pkg/skaffold/deploy/status_check.go b/pkg/skaffold/deploy/status_check.go index 9d23cc4be09..37f1f6990e3 100644 --- a/pkg/skaffold/deploy/status_check.go +++ b/pkg/skaffold/deploy/status_check.go @@ -65,7 +65,8 @@ func StatusCheck(ctx context.Context, defaultLabeller *DefaultLabeller, runCtx * wg.Add(1) go func(dName string, deadlineDuration time.Duration) { defer wg.Done() - pollDeploymentRolloutStatus(ctx, kubeCtl, dName, deadlineDuration, syncMap) + err := pollDeploymentRolloutStatus(ctx, kubeCtl, dName, deadlineDuration) + syncMap.Store(dName, err) }(dName, deadlineDuration) } @@ -97,7 +98,7 @@ func getDeployments(client kubernetes.Interface, ns string, l *DefaultLabeller, return depMap, nil } -func pollDeploymentRolloutStatus(ctx context.Context, k *kubectl.CLI, dName string, deadline time.Duration, syncMap *sync.Map) { +func pollDeploymentRolloutStatus(ctx context.Context, k *kubectl.CLI, dName string, deadline time.Duration) error { pollDuration := time.Duration(defaultPollPeriodInMilliseconds) * time.Millisecond // Add poll duration to account for one last attempt after progressDeadlineSeconds. timeoutContext, cancel := context.WithTimeout(ctx, deadline+pollDuration) @@ -106,17 +107,11 @@ func pollDeploymentRolloutStatus(ctx context.Context, k *kubectl.CLI, dName stri for { select { case <-timeoutContext.Done(): - syncMap.Store(dName, errors.Wrap(timeoutContext.Err(), fmt.Sprintf("deployment rollout status could not be fetched within %v", deadline))) - return + return errors.Wrap(timeoutContext.Err(), fmt.Sprintf("deployment rollout status could not be fetched within %v", deadline)) case <-time.After(pollDuration): status, err := executeRolloutStatus(timeoutContext, k, dName) - if err != nil { - syncMap.Store(dName, err) - return - } - if strings.Contains(status, "successfully rolled out") { - syncMap.Store(dName, nil) - return + if err != nil || strings.Contains(status, "successfully rolled out") { + return err } } } diff --git a/pkg/skaffold/deploy/status_check_test.go b/pkg/skaffold/deploy/status_check_test.go index 353cb19c24a..1d57ba64133 100644 --- a/pkg/skaffold/deploy/status_check_test.go +++ b/pkg/skaffold/deploy/status_check_test.go @@ -225,14 +225,8 @@ func TestPollDeploymentRolloutStatus(t *testing.T) { testutil.Run(t, test.description, func(t *testutil.T) { t.Override(&defaultPollPeriodInMilliseconds, 10) t.Override(&util.DefaultExecCommand, test.commands) - - actual := &sync.Map{} cli := &kubectl.CLI{KubeContext: testKubeContext, Namespace: "test"} - pollDeploymentRolloutStatus(context.Background(), cli, "dep", time.Duration(test.duration)*time.Millisecond, actual) - if _, ok := actual.Load("dep"); !ok { - t.Error("expected result for deployment dep. But found none") - } - err := getSkaffoldDeployStatus(actual) + err := pollDeploymentRolloutStatus(context.Background(), cli, "dep", time.Duration(test.duration)*time.Millisecond) t.CheckError(test.shouldErr, err) }) }