Skip to content

Commit addcf0c

Browse files
Merge pull request #29597 from lihongan/gatewayapi
NE-1968: add e2e tests for FeatureGate GatewayAPI
2 parents 44873fa + 5c5d543 commit addcf0c

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed

test/extended/router/gatewayapi.go

+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
package router
2+
3+
import (
4+
"context"
5+
"strings"
6+
7+
g "github.com/onsi/ginkgo/v2"
8+
o "github.com/onsi/gomega"
9+
10+
exutil "github.com/openshift/origin/test/extended/util"
11+
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
12+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
13+
e2e "k8s.io/kubernetes/test/e2e/framework"
14+
admissionapi "k8s.io/pod-security-admission/api"
15+
)
16+
17+
var _ = g.Describe("[sig-network][OCPFeatureGate:GatewayAPI][Feature:Router][apigroup:gateway.networking.k8s.io]", func() {
18+
defer g.GinkgoRecover()
19+
var (
20+
oc = exutil.NewCLIWithPodSecurityLevel("gateway-api", admissionapi.LevelBaseline)
21+
crdNames = []string{
22+
"gatewayclasses.gateway.networking.k8s.io",
23+
"gateways.gateway.networking.k8s.io",
24+
"httproutes.gateway.networking.k8s.io",
25+
"grpcroutes.gateway.networking.k8s.io",
26+
"referencegrants.gateway.networking.k8s.io",
27+
}
28+
errorMessage = "ValidatingAdmissionPolicy 'openshift-ingress-operator-gatewayapi-crd-admission' with binding 'openshift-ingress-operator-gatewayapi-crd-admission' denied request: Gateway API Custom Resource Definitions are managed by the Ingress Operator and may not be modified"
29+
)
30+
31+
g.Describe("Verify Gateway API CRDs", func() {
32+
g.It("and ensure required CRDs should already be installed", func() {
33+
g.By("Get and check the installed CRDs")
34+
for i := range crdNames {
35+
crd, err := oc.AdminApiextensionsClient().ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), crdNames[i], metav1.GetOptions{})
36+
o.Expect(err).NotTo(o.HaveOccurred())
37+
e2e.Logf("Found the Gateway API CRD named: %v", crd.Name)
38+
}
39+
})
40+
41+
g.It("and ensure existing CRDs can not be deleted", func() {
42+
g.By("Try to delete the CRDs and fail")
43+
for i := range crdNames {
44+
err := oc.AdminApiextensionsClient().ApiextensionsV1().CustomResourceDefinitions().Delete(context.Background(), crdNames[i], metav1.DeleteOptions{})
45+
o.Expect(err).To(o.HaveOccurred())
46+
o.Expect(err.Error()).To(o.ContainSubstring(errorMessage))
47+
}
48+
})
49+
50+
g.It("and ensure existing CRDs can not be updated", func() {
51+
g.By("Get the CRDs firstly, add spec.names.shortNames then update CRD")
52+
for i := range crdNames {
53+
crd, err := oc.AdminApiextensionsClient().ApiextensionsV1().CustomResourceDefinitions().Get(context.Background(), crdNames[i], metav1.GetOptions{})
54+
o.Expect(err).NotTo(o.HaveOccurred())
55+
// some CRDs have a shortName but some not, just trying to add one for all
56+
crd.Spec.Names.ShortNames = append(crd.Spec.Names.ShortNames, "fakename")
57+
_, err = oc.AdminApiextensionsClient().ApiextensionsV1().CustomResourceDefinitions().Update(context.Background(), crd, metav1.UpdateOptions{})
58+
o.Expect(err).To(o.HaveOccurred())
59+
o.Expect(err.Error()).To(o.ContainSubstring(errorMessage))
60+
}
61+
})
62+
63+
g.It("and ensure CRD of standard group can not be created", func() {
64+
fakeCRDName := "fakeroutes.gateway.networking.k8s.io"
65+
g.By("Try to create CRD of standard group and fail")
66+
fakeCRD := buildGWAPICRDFromName(fakeCRDName)
67+
_, err := oc.AdminApiextensionsClient().ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), fakeCRD, metav1.CreateOptions{})
68+
o.Expect(err).To(o.HaveOccurred())
69+
o.Expect(err.Error()).To(o.ContainSubstring(errorMessage))
70+
})
71+
72+
g.It("and ensure CRD of experimental group is not installed", func() {
73+
g.By("Ensure no CRD of experimental group is installed")
74+
crdList, err := oc.AdminApiextensionsClient().ApiextensionsV1().CustomResourceDefinitions().List(context.Background(), metav1.ListOptions{})
75+
o.Expect(err).NotTo(o.HaveOccurred())
76+
for _, crd := range crdList.Items {
77+
if crd.Spec.Group == "gateway.networking.x-k8s.io" {
78+
e2e.Failf("Found unexpected CRD named: %v", crd.Name)
79+
}
80+
}
81+
})
82+
83+
g.It("and ensure CRD of experimental group can not be created", func() {
84+
expCRDName := "xlistenersets.gateway.networking.x-k8s.io"
85+
g.By("Try to create CRD of experimental group and fail")
86+
expCRD := buildGWAPICRDFromName(expCRDName)
87+
_, err := oc.AdminApiextensionsClient().ApiextensionsV1().CustomResourceDefinitions().Create(context.Background(), expCRD, metav1.CreateOptions{})
88+
o.Expect(err).To(o.HaveOccurred())
89+
o.Expect(err.Error()).To(o.ContainSubstring(errorMessage))
90+
})
91+
})
92+
})
93+
94+
// buildGWAPICRDFromName initializes the fake GatewayAPI CRD deducing most of its required fields from the given name.
95+
func buildGWAPICRDFromName(name string) *apiextensionsv1.CustomResourceDefinition {
96+
var (
97+
plural = strings.Split(name, ".")[0]
98+
group, _ = strings.CutPrefix(name, plural+".")
99+
// removing trailing "s"
100+
singular = plural[0 : len(plural)-1]
101+
kind = strings.Title(singular)
102+
)
103+
104+
return &apiextensionsv1.CustomResourceDefinition{
105+
ObjectMeta: metav1.ObjectMeta{
106+
Name: plural + "." + group,
107+
Annotations: map[string]string{
108+
"api-approved.kubernetes.io": "https://github.com/kubernetes-sigs/gateway-api/pull/2466",
109+
},
110+
},
111+
Spec: apiextensionsv1.CustomResourceDefinitionSpec{
112+
Group: group,
113+
Names: apiextensionsv1.CustomResourceDefinitionNames{
114+
Singular: singular,
115+
Plural: plural,
116+
Kind: kind,
117+
},
118+
Scope: apiextensionsv1.ClusterScoped,
119+
Versions: []apiextensionsv1.CustomResourceDefinitionVersion{
120+
{
121+
Name: "v1",
122+
Storage: true,
123+
Served: true,
124+
Schema: &apiextensionsv1.CustomResourceValidation{
125+
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
126+
Type: "object",
127+
},
128+
},
129+
},
130+
{
131+
Name: "v1beta1",
132+
Storage: false,
133+
Served: true,
134+
Schema: &apiextensionsv1.CustomResourceValidation{
135+
OpenAPIV3Schema: &apiextensionsv1.JSONSchemaProps{
136+
Type: "object",
137+
},
138+
},
139+
},
140+
},
141+
},
142+
}
143+
}

test/extended/util/annotate/generated/zz_generated.annotations.go

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/extended/util/client.go

+5
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ import (
7575
templatev1client "github.com/openshift/client-go/template/clientset/versioned"
7676
userv1client "github.com/openshift/client-go/user/clientset/versioned"
7777
"github.com/openshift/library-go/test/library/metrics"
78+
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
7879
)
7980

8081
// CLI provides function to call the OpenShift CLI and Kubernetes and OpenShift
@@ -693,6 +694,10 @@ func (c *CLI) TemplateClient() templatev1client.Interface {
693694
return templatev1client.NewForConfigOrDie(c.UserConfig())
694695
}
695696

697+
func (c *CLI) AdminApiextensionsClient() apiextensionsclient.Interface {
698+
return apiextensionsclient.NewForConfigOrDie(c.AdminConfig())
699+
}
700+
696701
func (c *CLI) AdminAppsClient() appsv1client.Interface {
697702
return appsv1client.NewForConfigOrDie(c.AdminConfig())
698703
}

zz_generated.manifests/test-reporting.yaml

+14
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ spec:
6565
tests:
6666
- testName: '[sig-arch][OCPFeatureGate:Example] should only run FeatureGated test
6767
when enabled'
68+
- featureGate: GatewayAPI
69+
tests:
70+
- testName: '[sig-network][OCPFeatureGate:GatewayAPI][Feature:Router][apigroup:gateway.networking.k8s.io]
71+
Verify Gateway API CRDs and ensure CRD of experimental group can not be created'
72+
- testName: '[sig-network][OCPFeatureGate:GatewayAPI][Feature:Router][apigroup:gateway.networking.k8s.io]
73+
Verify Gateway API CRDs and ensure CRD of experimental group is not installed'
74+
- testName: '[sig-network][OCPFeatureGate:GatewayAPI][Feature:Router][apigroup:gateway.networking.k8s.io]
75+
Verify Gateway API CRDs and ensure CRD of standard group can not be created'
76+
- testName: '[sig-network][OCPFeatureGate:GatewayAPI][Feature:Router][apigroup:gateway.networking.k8s.io]
77+
Verify Gateway API CRDs and ensure existing CRDs can not be deleted'
78+
- testName: '[sig-network][OCPFeatureGate:GatewayAPI][Feature:Router][apigroup:gateway.networking.k8s.io]
79+
Verify Gateway API CRDs and ensure existing CRDs can not be updated'
80+
- testName: '[sig-network][OCPFeatureGate:GatewayAPI][Feature:Router][apigroup:gateway.networking.k8s.io]
81+
Verify Gateway API CRDs and ensure required CRDs should already be installed'
6882
- featureGate: HardwareSpeed
6983
tests:
7084
- testName: '[sig-etcd][OCPFeatureGate:HardwareSpeed][Serial] etcd is able to

0 commit comments

Comments
 (0)