Skip to content

Commit

Permalink
improve log output when waiting for Deployment rollouts
Browse files Browse the repository at this point in the history
  • Loading branch information
xrstf committed Dec 14, 2024
1 parent 9c981b6 commit 543ebf9
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions test/integration/test/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ func rolloutDeployment(t *testing.T, ctx context.Context, client ctrlruntimeclie
}

timeout := 30 * time.Second
var lastErr string
if err := wait.PollUntilContextTimeout(ctx, time.Second, timeout, false, func(ctx context.Context) (bool, error) {
var current appsv1.Deployment
if err := client.Get(ctx, ctrlruntimeclient.ObjectKeyFromObject(&depl), &current); err != nil {
Expand All @@ -148,13 +149,26 @@ func rolloutDeployment(t *testing.T, ctx context.Context, client ctrlruntimeclie
return false, errors.New("Deployment has no replicas defined")
}

ready := true &&
current.Status.AvailableReplicas == *replicas &&
current.Status.ReadyReplicas == *replicas &&
current.Status.UpdatedReplicas == *replicas &&
current.Status.UnavailableReplicas == 0
var errMsg string
if remaining := *replicas - current.Status.UpdatedReplicas; remaining != 0 {
errMsg = fmt.Sprintf("not all replicas updated (%d remaining)", remaining)
} else if remaining := *replicas - current.Status.AvailableReplicas; remaining != 0 {
errMsg = fmt.Sprintf("not all replicas available (%d remaining)", remaining)
} else if remaining := *replicas - current.Status.ReadyReplicas; remaining != 0 {
errMsg = fmt.Sprintf("not all replicas ready (%d remaining)", remaining)
} else if current.Status.UnavailableReplicas != 0 {
errMsg = fmt.Sprintf("%d unavailable replicas remaining", current.Status.UnavailableReplicas)
}

if errMsg != "" {
if errMsg != lastErr {
t.Logf("Still waiting: %s.", errMsg)
}
}

lastErr = errMsg

return ready, nil
return errMsg == "", nil
}); err != nil {
return fmt.Errorf("Deployment did not fully roll out after %v: %w", timeout, err)
}
Expand Down

0 comments on commit 543ebf9

Please sign in to comment.