@@ -47,6 +47,10 @@ var crdNames = []string{
4747 "referencegrants.gateway.networking.k8s.io" ,
4848}
4949
50+ var xcrdNames = []string {
51+ "listenersets.gateway.networking.x-k8s.io" ,
52+ }
53+
5054// Global variables for testing.
5155// The default route name to be constructed.
5256var defaultRoutename = ""
@@ -83,6 +87,13 @@ func TestGatewayAPI(t *testing.T) {
8387 // TODO: Uninstall OSSM after test is completed.
8488 })
8589
90+ // Create test experimental CRDs for the subsequent subtests.
91+ // Specifically, `testGatewayAPIResourcesProtection`, which tests VAP protection
92+ // for the experimental Gateway API group, needs to check the update verb.
93+ // Since an API `Get` is called before the update, the CRD must exist in the cluster,
94+ // just like standard Gateway API CRDs.
95+ ensureExperimentalCRDs (t )
96+
8697 t .Run ("testGatewayAPIResources" , testGatewayAPIResources )
8798 if gatewayAPIControllerEnabled {
8899 t .Run ("testGatewayAPIObjects" , testGatewayAPIObjects )
@@ -98,7 +109,6 @@ func TestGatewayAPI(t *testing.T) {
98109// CRDs are created.
99110// It also deletes and ensure the CRDs are recreated.
100111func testGatewayAPIResources (t * testing.T ) {
101- t .Helper ()
102112 // Make sure all the *.gateway.networking.k8s.io CRDs are available since the FeatureGate is enabled.
103113 ensureCRDs (t )
104114
@@ -117,8 +127,6 @@ func testGatewayAPIResources(t *testing.T) {
117127// - the SMCP is created successfully (OSSM 2.x).
118128// - deletes SMCP and subscription and tests if it gets recreated
119129func testGatewayAPIIstioInstallation (t * testing.T ) {
120- t .Helper ()
121-
122130 if err := assertSubscription (t , openshiftOperatorsNamespace , expectedSubscriptionName ); err != nil {
123131 t .Fatalf ("failed to find expected Subscription %s: %v" , expectedSubscriptionName , err )
124132 }
@@ -155,8 +163,6 @@ func testGatewayAPIIstioInstallation(t *testing.T) {
155163
156164// testGatewayAPIObjects tests that Gateway API objects can be created successfully.
157165func testGatewayAPIObjects (t * testing.T ) {
158- t .Helper ()
159-
160166 // Create a test namespace that cleans itself up and sets up its own service account and role binding.
161167 ns := createNamespace (t , names .SimpleNameGenerator .GenerateName ("test-e2e-gwapi-" ))
162168
@@ -178,8 +184,6 @@ func testGatewayAPIObjects(t *testing.T) {
178184// denies admission requests attempting to modify Gateway API CRDs on behalf of a user
179185// who is not the ingress operator's service account.
180186func testGatewayAPIResourcesProtection (t * testing.T ) {
181- t .Helper ()
182-
183187 // Get kube client which impersonates ingress operator's service account.
184188 kubeConfig , err := config .GetConfig ()
185189 if err != nil {
@@ -195,7 +199,7 @@ func testGatewayAPIResourcesProtection(t *testing.T) {
195199
196200 // Create test CRDs.
197201 var testCRDs []* apiextensionsv1.CustomResourceDefinition
198- for _ , name := range crdNames {
202+ for _ , name := range append ( crdNames , xcrdNames ... ) {
199203 testCRDs = append (testCRDs , buildGWAPICRDFromName (name ))
200204 }
201205
@@ -297,6 +301,26 @@ func deleteCRDs(t *testing.T) {
297301 }
298302}
299303
304+ // ensureExperimentalCRDs creates experimental Gateway API custom resource definitions.
305+ // This function temporarily disables the ingress operator's VAP to allow CRD creation.
306+ // The VAP is re-enabled before the function returns.
307+ func ensureExperimentalCRDs (t * testing.T ) {
308+ vm := newVAPManager (t , gwapiCRDVAPName )
309+ if err , recoverFn := vm .disable (); err != nil {
310+ defer recoverFn ()
311+ t .Fatalf ("failed to disable vap: %v" , err )
312+ }
313+ defer vm .enable ()
314+
315+ for _ , crdName := range xcrdNames {
316+ if _ , err := createCRD (crdName ); err != nil {
317+ t .Fatalf ("failed to create experimental crd %q: %v" , crdName , err )
318+ } else {
319+ t .Logf ("created experimental crd %q" , crdName )
320+ }
321+ }
322+ }
323+
300324// ensureGatewayObjectCreation tests that gateway class, gateway, and http route objects can be created.
301325func ensureGatewayObjectCreation (ns * corev1.Namespace ) error {
302326 var domain string
0 commit comments