From 543ebf9a35e42f2d86880f696e3a53670bfbd0bf Mon Sep 17 00:00:00 2001 From: xrstf Date: Sat, 14 Dec 2024 16:02:29 +0100 Subject: [PATCH] improve log output when waiting for Deployment rollouts --- test/integration/test/setup.go | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/test/integration/test/setup.go b/test/integration/test/setup.go index 4667437ef..f73189b04 100644 --- a/test/integration/test/setup.go +++ b/test/integration/test/setup.go @@ -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), ¤t); err != nil { @@ -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) }