Skip to content

Commit eae9450

Browse files
Merge pull request #1200 from alebedev87/ne-1953-vap-experimental-group
NE-1953: Add experimental Gateway API group to Validating Admission Policy
2 parents 924279a + 5c30510 commit eae9450

File tree

3 files changed

+54
-9
lines changed

3 files changed

+54
-9
lines changed

manifests/01-validating-admission-policy.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
# Consider only request to Gateway API CRDs.
2121
- name: "check-only-gateway-api-crds"
2222
# When the operation is DELETE, the "object" variable is null.
23-
expression: "(request.operation == 'DELETE' ? oldObject : object).spec.group == 'gateway.networking.k8s.io'"
23+
expression: "(request.operation == 'DELETE' ? oldObject : object).spec.group == 'gateway.networking.k8s.io' || (request.operation == 'DELETE' ? oldObject : object).spec.group == 'gateway.networking.x-k8s.io'"
2424
# Validations are evaluated in the the order of their declaration.
2525
validations:
2626
# Verify that the request was sent by the ingress operator's service account.

test/e2e/gateway_api_test.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
5256
var 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.
100111
func 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
119129
func 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.
157165
func 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.
180186
func 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.
301325
func ensureGatewayObjectCreation(ns *corev1.Namespace) error {
302326
var domain string

test/e2e/util_gatewayapi_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,21 @@ func createGatewayClass(name, controllerName string) (*gatewayapiv1.GatewayClass
271271
return gatewayClass, nil
272272
}
273273

274+
// createCRD creates the CRD with the given name or retrieves it if already exists.
275+
func createCRD(name string) (*apiextensionsv1.CustomResourceDefinition, error) {
276+
crd := buildGWAPICRDFromName(name)
277+
if err := kclient.Create(context.Background(), crd); err != nil {
278+
if kerrors.IsAlreadyExists(err) {
279+
if err := kclient.Get(context.Background(), types.NamespacedName{Name: name}, crd); err != nil {
280+
return nil, fmt.Errorf("failed to get crd %q: %w", name, err)
281+
}
282+
return crd, nil
283+
}
284+
return nil, fmt.Errorf("failed to create crd %q: %w", name, err)
285+
}
286+
return crd, nil
287+
}
288+
274289
// buildGatewayClass initializes the GatewayClass and returns its address.
275290
func buildGatewayClass(name, controllerName string) *gatewayapiv1.GatewayClass {
276291
return &gatewayapiv1.GatewayClass{
@@ -348,6 +363,12 @@ func buildGWAPICRDFromName(name string) *apiextensionsv1.CustomResourceDefinitio
348363
case "referencegrants":
349364
kind = "ReferenceGrant"
350365
versions = []map[string]bool{{"v1beta1": true}}
366+
case "listenersets":
367+
kind = "ListenerSet"
368+
versions = []map[string]bool{{"v1alpha1": true}}
369+
case "grpcroutes":
370+
kind = "GRPCRoute"
371+
versions = []map[string]bool{{"v1": true}}
351372
}
352373

353374
crd := &apiextensionsv1.CustomResourceDefinition{

0 commit comments

Comments
 (0)