Skip to content

Commit

Permalink
Rename waitForDeploymentCompleteWithCleanup to waitForDeploymentCompl…
Browse files Browse the repository at this point in the history
…eteWithOldPodTermination

Also:
- Rename pods to podList
- When checking for old pod termination, only count the currently ready
  pods, instead of all pods
  • Loading branch information
rfredette authored and openshift-cherrypick-robot committed Jul 20, 2023
1 parent a7128d4 commit 73912c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
2 changes: 1 addition & 1 deletion test/e2e/client_tls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ func TestClientTLS(t *testing.T) {
if err := waitForDeploymentEnvVar(t, kclient, deployment, 1*time.Minute, "ROUTER_MUTUAL_TLS_AUTH", "required"); err != nil {
t.Fatalf("expected updated deployment to have ROUTER_MUTUAL_TLS_AUTH=required: %v", err)
}
if err := waitForDeploymentCompleteWithCleanup(t, kclient, deploymentName, 3*time.Minute); err != nil {
if err := waitForDeploymentCompleteWithOldPodTermination(t, kclient, deploymentName, 3*time.Minute); err != nil {
t.Fatalf("timed out waiting for old router generation to be cleaned up: %v", err)
}

Expand Down
27 changes: 19 additions & 8 deletions test/e2e/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3581,31 +3581,42 @@ func waitForDeploymentEnvVar(t *testing.T, cl client.Client, deployment *appsv1.

// waitForDeploymentCompleteWithCleanup waits for a deployment to complete its rollout, then waits for the old
// generation's pods to finish terminating.
func waitForDeploymentCompleteWithCleanup(t *testing.T, cl client.Client, deploymentName types.NamespacedName, timeout time.Duration) error {
func waitForDeploymentCompleteWithOldPodTermination(t *testing.T, cl client.Client, deploymentName types.NamespacedName, timeout time.Duration) error {
t.Helper()
deployment := &appsv1.Deployment{}
if err := cl.Get(context.TODO(), deploymentName, deployment); err != nil {
return fmt.Errorf("failed to get deployment %s: %w", deploymentName.Name, err)
}

if deployment.Generation != deployment.Status.ObservedGeneration {
if err := waitForDeploymentComplete(t, cl, deployment, timeout); err != nil {
return fmt.Errorf("timed out waiting for deployment %s to complete rollout: %w", deploymentName.Name, err)
}
if err := waitForDeploymentComplete(t, cl, deployment, timeout); err != nil {
return fmt.Errorf("timed out waiting for deployment %s to complete rollout: %w", deploymentName.Name, err)
}

selector, err := metav1.LabelSelectorAsSelector(deployment.Spec.Selector)
if err != nil {
return fmt.Errorf("deployment %s has invalid spec.selector: %w", deploymentName.Name, err)
}

expectedReplicas := 1
if deployment.Spec.Replicas != nil && int(*deployment.Spec.Replicas) != 0 {
expectedReplicas = int(*deployment.Spec.Replicas)
}

return wait.PollImmediate(2*time.Second, timeout, func() (bool, error) {
pods := &corev1.PodList{}
if err := cl.List(context.TODO(), pods, client.MatchingLabelsSelector{Selector: selector}); err != nil {
podList := &corev1.PodList{}
if err := cl.List(context.TODO(), podList, client.MatchingLabelsSelector{Selector: selector}); err != nil {
t.Logf("failed to list pods for deployment %q: %v", deploymentName.Name, err)
return false, nil
}
return len(pods.Items) == int(*deployment.Spec.Replicas), nil
readyPods := 0
for _, pod := range podList.Items {
for _, condition := range pod.Status.Conditions {
if condition.Type == corev1.PodReady && condition.Status == corev1.ConditionTrue {
readyPods++
}
}
}
return readyPods == expectedReplicas, nil
})
}

Expand Down

0 comments on commit 73912c8

Please sign in to comment.