Skip to content

Commit 8799e18

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 19ae0a4 commit 8799e18

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

test/e2e/gateway_api_test.go

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

9999
t.Run("testGatewayAPIResources", testGatewayAPIResources)
100100
if gatewayAPIControllerEnabled {
101+
t.Run("testGatewayAPIIstioInstallation", testGatewayAPIIstioInstallation)
101102
t.Run("testGatewayAPIObjects", testGatewayAPIObjects)
102103
t.Run("testGatewayAPIManualDeployment", testGatewayAPIManualDeployment)
103-
t.Run("testGatewayAPIIstioInstallation", testGatewayAPIIstioInstallation)
104104
} else {
105105
t.Log("Gateway API Controller not enabled, skipping controller tests")
106106
}
@@ -138,6 +138,12 @@ func testGatewayAPIResources(t *testing.T) {
138138
// - If the Istio and Subscription CRs are deleted, they are recreated
139139
// automatically.
140140
func testGatewayAPIIstioInstallation(t *testing.T) {
141+
gatewayClassName := "openshift-default"
142+
t.Logf("Ensure gateway class %s exists...", gatewayClassName)
143+
_, err := createGatewayClass(gatewayClassName, operatorcontroller.OpenShiftGatewayClassControllerName)
144+
if err != nil {
145+
t.Fatalf("feature gate was enabled, but gateway class object could not be created: %v", err)
146+
}
141147
t.Log("Checking for the Subscription...")
142148
if err := assertSubscription(t, openshiftOperatorsNamespace, expectedSubscriptionName); err != nil {
143149
t.Fatalf("failed to find expected Subscription %s: %v", expectedSubscriptionName, err)
@@ -146,6 +152,9 @@ func testGatewayAPIIstioInstallation(t *testing.T) {
146152
if err := assertCatalogSource(t, expectedCatalogSourceNamespace, expectedCatalogSourceName); err != nil {
147153
t.Fatalf("failed to find expected CatalogSource %s: %v", expectedCatalogSourceName, err)
148154
}
155+
if err := assertClusterServiceVersionSucceeded(t); err != nil {
156+
t.Fatalf("failed to find cluster service version: %v", err)
157+
}
149158
t.Log("Checking for the OSSM operator deployment and pods...")
150159
if err := assertOSSMOperator(t); err != nil {
151160
t.Fatalf("failed to find expected Istio operator: %v", err)

test/e2e/util_gatewayapi_test.go

Lines changed: 66 additions & 11 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, retrying...", ns, err)
474+
return false, nil
475+
}
476+
if len(podlist.Items) > 1 {
477+
t.Logf("too many pods for deployment %v: %d, retrying...", 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, retrying...", 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)
@@ -771,6 +782,50 @@ func assertCatalogSource(t *testing.T, namespace, csName string) error {
771782
return err
772783
}
773784

785+
func assertClusterServiceVersionSucceeded(t *testing.T) error {
786+
t.Helper()
787+
expectedVersion, err := expectedOSSMVersion(t)
788+
if err != nil {
789+
return fmt.Errorf("Could not determine expected OSSM version: %w", err)
790+
}
791+
err = wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 2*time.Minute, false, func(context context.Context) (bool, error) {
792+
t.Log("getting cluster service version...")
793+
csv := &operatorsv1alpha1.ClusterServiceVersion{}
794+
if err := kclient.Get(context, types.NamespacedName{Namespace: controller.OpenshiftOperatorNamespace, Name: expectedVersion}, csv); err != nil {
795+
t.Logf("failed to get cluster service version %s/%s: %v", controller.OpenshiftOperatorNamespace, expectedVersion, err)
796+
if kerrors.IsNotFound(err) {
797+
return false, nil
798+
}
799+
return false, err
800+
}
801+
if csv.Status.Phase != operatorsv1alpha1.CSVPhaseSucceeded {
802+
t.Logf("found cluster service version %s, but phase is %s, expected Succeeded", csv.Name, csv.Status.Phase)
803+
return false, nil
804+
}
805+
t.Logf("found cluster service version %s, and phase is Succeeded", csv.Name)
806+
return true, nil
807+
})
808+
return err
809+
}
810+
811+
func expectedOSSMVersion(t *testing.T) (string, error) {
812+
t.Helper()
813+
deployment, err := getDeployment(t, kclient, types.NamespacedName{Namespace: controller.DefaultOperatorNamespace, Name: "ingress-operator"}, timeout)
814+
if err != nil {
815+
return "", err
816+
}
817+
for _, container := range deployment.Spec.Template.Spec.Containers {
818+
if container.Name == "ingress-operator" {
819+
for _, envvar := range container.Env {
820+
if envvar.Name == "GATEWAY_API_OPERATOR_VERSION" {
821+
return envvar.Value, nil
822+
}
823+
}
824+
}
825+
}
826+
return "servicemeshoperator3.v3.0.0", nil
827+
}
828+
774829
// assertIstio checks if the Istio exists in a ready state,
775830
// and returns an error if not.
776831
func assertIstio(t *testing.T) error {
@@ -846,7 +901,7 @@ func assertDNSRecord(t *testing.T, recordName types.NamespacedName) error {
846901
t.Helper()
847902
dnsRecord := &v1.DNSRecord{}
848903

849-
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 1*time.Minute, false, func(context context.Context) (bool, error) {
904+
err := wait.PollUntilContextTimeout(context.Background(), 5*time.Second, 2*time.Minute, false, func(context context.Context) (bool, error) {
850905
if err := kclient.Get(context, recordName, dnsRecord); err != nil {
851906
t.Logf("Failed to get DNSRecord %v: %v; retrying...", recordName, err)
852907
return false, nil

0 commit comments

Comments
 (0)