Skip to content

Commit 7c65aec

Browse files
committed
NE-2097: e2e - Add assertOSSMOperatorWithConfig helper
This commit introduces the `assertOSSMOperatorWithConfig` helper function, which extends the existing `assertOSSMOperator` by allowing parameterization of polling interval, timeout, and expected OSSM version (new check).
1 parent c774f08 commit 7c65aec

File tree

1 file changed

+27
-21
lines changed

1 file changed

+27
-21
lines changed

test/e2e/util_gatewayapi_test.go

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -495,39 +495,45 @@ func deleteExistingSubscription(t *testing.T, namespace, subName string) error {
495495

496496
}
497497

498-
// assertOSSMOperator checks if the OSSM Istio operator gets successfully installed
499-
// and returns an error if not.
498+
// assertOSSMOperator checks if the OSSM operator gets successfully installed
499+
// and returns an error if not. It uses configurable parameters such as the expected OSSM version, polling interval, and timeout.
500500
func assertOSSMOperator(t *testing.T) error {
501+
return assertOSSMOperatorWithConfig(t, "", 1*time.Second, 30*time.Second)
502+
}
503+
504+
// assertOSSMOperatorWithConfig checks if the OSSM operator gets successfully installed
505+
// and returns an error if not. It uses configurable parameters such as
506+
// the expected OSSM version, polling interval, and timeout.
507+
func assertOSSMOperatorWithConfig(t *testing.T, ossmVersion string, interval, timeout time.Duration) error {
501508
t.Helper()
502509
dep := &appsv1.Deployment{}
503510
ns := types.NamespacedName{Namespace: openshiftOperatorsNamespace, Name: openshiftIstioOperatorDeploymentName}
504511

505-
// Get the Istio operator deployment.
506-
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 30*time.Second, false, func(context context.Context) (bool, error) {
512+
// Get the OSSM operator deployment.
513+
if err := wait.PollUntilContextTimeout(context.Background(), interval, timeout, false, func(context context.Context) (bool, error) {
507514
if err := kclient.Get(context, ns, dep); err != nil {
508515
t.Logf("failed to get deployment %v, retrying...", ns)
509516
return false, nil
510517
}
518+
if len(ossmVersion) > 0 {
519+
if csv, found := dep.Labels["olm.owner"]; found {
520+
if csv == ossmVersion {
521+
t.Logf("found OSSM deployment %q with expected version %q", ns, ossmVersion)
522+
} else {
523+
t.Logf("OSSM deployment %q expected to have version %q but got %q, retrying...", ns, ossmVersion, csv)
524+
return false, nil
525+
}
526+
}
527+
}
528+
if dep.Status.AvailableReplicas < *dep.Spec.Replicas {
529+
t.Logf("OSSM deployment %q expected to have %d available replica(s) but got %d, retrying...", ns, *dep.Spec.Replicas, dep.Status.AvailableReplicas)
530+
return false, nil
531+
}
532+
t.Logf("found OSSM operator deployment %q with %d available replica(s)", ns, dep.Status.AvailableReplicas)
511533
return true, nil
512-
})
513-
if err != nil {
534+
}); err != nil {
514535
return fmt.Errorf("error finding deployment %v: %v", ns, err)
515536
}
516-
517-
// Get the istio-operator pod.
518-
podlist, err := getPods(t, kclient, dep)
519-
if err != nil {
520-
return fmt.Errorf("error finding pod for deployment %v: %v", ns, err)
521-
}
522-
if len(podlist.Items) > 1 {
523-
return fmt.Errorf("too many pods for deployment %v: %d", ns, len(podlist.Items))
524-
}
525-
pod := podlist.Items[0]
526-
if pod.Status.Phase != corev1.PodRunning {
527-
return fmt.Errorf("OSSM operator failure: pod %s is not running, it is %v", pod.Name, pod.Status.Phase)
528-
}
529-
530-
t.Logf("found OSSM operator pod %s/%s to be %s", pod.Namespace, pod.Name, pod.Status.Phase)
531537
return nil
532538
}
533539

0 commit comments

Comments
 (0)