Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor pollDeploymentRolloutStatus #2846

Merged
merged 1 commit into from
Sep 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions pkg/skaffold/deploy/status_check.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}
}
Expand Down
8 changes: 1 addition & 7 deletions pkg/skaffold/deploy/status_check_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down