Skip to content

Commit ede8707

Browse files
committed
Verify istio installation before verifying gw-api objects in e2e tests
Also, check that an appropriate service mesh cluster service version has been installed as part of verifying istio installation. This is part of the fix for OCPBUGS-53424
1 parent 104a36e commit ede8707

File tree

2 files changed

+72
-11
lines changed

2 files changed

+72
-11
lines changed

test/e2e/gateway_api_test.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ func TestGatewayAPI(t *testing.T) {
9595

9696
t.Run("testGatewayAPIResources", testGatewayAPIResources)
9797
if gatewayAPIControllerEnabled {
98-
t.Run("testGatewayAPIObjects", testGatewayAPIObjects)
9998
t.Run("testGatewayAPIIstioInstallation", testGatewayAPIIstioInstallation)
99+
t.Run("testGatewayAPIObjects", testGatewayAPIObjects)
100100
} else {
101101
t.Log("Gateway API Controller not enabled, skipping testGatewayAPIObjects and testGatewayAPIIstioInstallation")
102102
}
@@ -134,6 +134,12 @@ func testGatewayAPIResources(t *testing.T) {
134134
// - If the Istio and Subscription CRs are deleted, they are recreated
135135
// automatically.
136136
func testGatewayAPIIstioInstallation(t *testing.T) {
137+
gatewayClassName := "openshift-test"
138+
t.Logf("Ensure gateway class %s exists...", gatewayClassName)
139+
_, err := createGatewayClass(gatewayClassName, operatorcontroller.OpenShiftGatewayClassControllerName)
140+
if err != nil {
141+
t.Fatalf("feature gate was enabled, but gateway class object could not be created: %v", err)
142+
}
137143
t.Log("Checking for the Subscription...")
138144
if err := assertSubscription(t, openshiftOperatorsNamespace, expectedSubscriptionName); err != nil {
139145
t.Fatalf("failed to find expected Subscription %s: %v", expectedSubscriptionName, err)
@@ -142,6 +148,9 @@ func testGatewayAPIIstioInstallation(t *testing.T) {
142148
if err := assertCatalogSource(t, expectedCatalogSourceNamespace, expectedCatalogSourceName); err != nil {
143149
t.Fatalf("failed to find expected CatalogSource %s: %v", expectedCatalogSourceName, err)
144150
}
151+
if err := assertClusterServiceVersionSucceeded(t); err != nil {
152+
t.Fatalf("failed to find cluster service version: %v", err)
153+
}
145154
t.Log("Checking for the OSSM operator deployment and pods...")
146155
if err := assertOSSMOperator(t); err != nil {
147156
t.Fatalf("failed to find expected Istio operator: %v", err)

test/e2e/util_gatewayapi_test.go

Lines changed: 62 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717

1818
sailv1 "github.com/istio-ecosystem/sail-operator/api/v1"
1919
v1 "github.com/openshift/api/operatoringress/v1"
20+
"github.com/openshift/cluster-ingress-operator/pkg/operator/controller"
2021
operatorcontroller "github.com/openshift/cluster-ingress-operator/pkg/operator/controller"
2122
util "github.com/openshift/cluster-ingress-operator/pkg/util"
2223
operatorsv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
@@ -461,20 +462,30 @@ func assertOSSMOperator(t *testing.T) error {
461462
return true, nil
462463
})
463464
if err != nil {
464-
return fmt.Errorf("error finding deployment %v: %v", ns, err)
465+
return fmt.Errorf("error finding deployment %v: %w", ns, err)
465466
}
466467

468+
pod := corev1.Pod{}
467469
// Get the istio-operator pod.
468-
podlist, err := getPods(t, kclient, dep)
470+
err = wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 30*time.Second, false, func(context context.Context) (bool, error) {
471+
podlist, err := getPods(t, kclient, dep)
472+
if err != nil {
473+
t.Logf("error finding pod for deployment %v: %v", ns, err)
474+
return false, nil
475+
}
476+
if len(podlist.Items) > 1 {
477+
t.Logf("too many pods for deployment %v: %d", ns, len(podlist.Items))
478+
return false, nil
479+
}
480+
pod = podlist.Items[0]
481+
if pod.Status.Phase != corev1.PodRunning {
482+
t.Logf("OSSM operator failure: pod %s is not running, it is %v", pod.Name, pod.Status.Phase)
483+
return false, nil
484+
}
485+
return true, nil
486+
})
469487
if err != nil {
470-
return fmt.Errorf("error finding pod for deployment %v: %v", ns, err)
471-
}
472-
if len(podlist.Items) > 1 {
473-
return fmt.Errorf("too many pods for deployment %v: %d", ns, len(podlist.Items))
474-
}
475-
pod := podlist.Items[0]
476-
if pod.Status.Phase != corev1.PodRunning {
477-
return fmt.Errorf("OSSM operator failure: pod %s is not running, it is %v", pod.Name, pod.Status.Phase)
488+
return fmt.Errorf("error finding OSSM operator pod %v: %w", ns, err)
478489
}
479490

480491
t.Logf("found OSSM operator pod %s/%s to be %s", pod.Namespace, pod.Name, pod.Status.Phase)
@@ -766,6 +777,47 @@ func assertCatalogSource(t *testing.T, namespace, csName string) error {
766777
return err
767778
}
768779

780+
func assertClusterServiceVersionSucceeded(t *testing.T) error {
781+
t.Helper()
782+
expectedVersion, err := expectedOSSMVersion(t)
783+
if err != nil {
784+
return fmt.Errorf("Could not determine expected OSSM version: %w", err)
785+
}
786+
err = wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 60*time.Second, false, func(context context.Context) (bool, error) {
787+
t.Log("getting cluster service version...")
788+
csv := &operatorsv1alpha1.ClusterServiceVersion{}
789+
if err := kclient.Get(context, types.NamespacedName{Namespace: controller.OpenshiftOperatorNamespace, Name: expectedVersion}, csv); err != nil {
790+
t.Logf("failed to get cluster service version %s/%s: %v", controller.OpenshiftOperatorNamespace, expectedVersion, err)
791+
return false, err
792+
}
793+
if csv.Status.Phase != operatorsv1alpha1.CSVPhaseSucceeded {
794+
t.Logf("found cluster service version %s, but phase is %s, expected Succeeded", csv.Name, csv.Status.Phase)
795+
return false, nil
796+
}
797+
t.Logf("found cluster service version %s, and phase is Succeeded", csv.Name)
798+
return true, nil
799+
})
800+
return err
801+
}
802+
803+
func expectedOSSMVersion(t *testing.T) (string, error) {
804+
t.Helper()
805+
deployment, err := getDeployment(t, kclient, types.NamespacedName{Namespace: controller.DefaultOperatorNamespace, Name: "ingress-operator"}, timeout)
806+
if err != nil {
807+
return "", err
808+
}
809+
for _, container := range deployment.Spec.Template.Spec.Containers {
810+
if container.Name == "ingress-operator" {
811+
for _, envvar := range container.Env {
812+
if envvar.Name == "GATEWAY_API_OPERATOR_VERSION" {
813+
return envvar.Value, nil
814+
}
815+
}
816+
}
817+
}
818+
return "servicemeshoperator3.v3.0.0", nil
819+
}
820+
769821
// assertIstio checks if the Istio exists in a ready state,
770822
// and returns an error if not.
771823
func assertIstio(t *testing.T) error {

0 commit comments

Comments
 (0)