Skip to content

Commit 7c59634

Browse files
committed
OCPBUGS-55211: use regular user to create httproute
1. use regular user to create httproute as well as pod/service 2. remove the step of cleaning up httproute 3. skip the tests when gateway is required only
1 parent bff0360 commit 7c59634

File tree

2 files changed

+67
-68
lines changed

2 files changed

+67
-68
lines changed

test/extended/router/gatewayapicontroller.go

Lines changed: 56 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ import (
2323
"k8s.io/apimachinery/pkg/util/wait"
2424
"k8s.io/apiserver/pkg/storage/names"
2525
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
26-
gatewayapiclientset "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
2726
)
2827

2928
var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feature:Router][apigroup:gateway.networking.k8s.io]", g.Ordered, g.Serial, func() {
3029
defer g.GinkgoRecover()
3130
var (
32-
oc = exutil.NewCLIWithPodSecurityLevel("gatewayapi-controller", admissionapi.LevelBaseline)
33-
csvName string
34-
err error
35-
gateways []string
36-
httproutes []string
31+
oc = exutil.NewCLIWithPodSecurityLevel("gatewayapi-controller", admissionapi.LevelBaseline)
32+
csvName string
33+
err error
34+
gateways []string
3735
)
3836
const (
3937
// The expected OSSM subscription name.
@@ -50,44 +48,20 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
5048
deploymentOSSMName = "servicemesh-operator3"
5149
)
5250
g.BeforeAll(func() {
53-
infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{})
54-
o.Expect(err).NotTo(o.HaveOccurred())
55-
o.Expect(infra).NotTo(o.BeNil())
56-
57-
platformType := infra.Status.Platform
58-
if infra.Status.PlatformStatus != nil {
59-
platformType = infra.Status.PlatformStatus.Type
60-
}
61-
switch platformType {
62-
case configv1.AWSPlatformType, configv1.AzurePlatformType, configv1.GCPPlatformType, configv1.IBMCloudPlatformType:
63-
// supported
64-
default:
65-
g.Skip(fmt.Sprintf("Skipping on non cloud platform type %q", platformType))
66-
}
67-
68-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
6951
// create the default gatewayClass
7052
gatewayClass := buildGatewayClass(gatewayClassName, gatewayClassControllerName)
71-
_, err = gwapiClient.GatewayV1().GatewayClasses().Create(context.TODO(), gatewayClass, metav1.CreateOptions{})
53+
_, err = oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Create(context.TODO(), gatewayClass, metav1.CreateOptions{})
7254
if err != nil && !apierrors.IsAlreadyExists(err) {
7355
e2e.Failf("Failed to create GatewayClass %q", gatewayClassName)
7456
}
75-
7657
})
7758

7859
g.AfterAll(func() {
79-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
80-
namespace := oc.Namespace()
8160
g.By("Cleaning up the GatewayAPI Objects")
8261
for _, name := range gateways {
83-
err = gwapiClient.GatewayV1().Gateways("openshift-ingress").Delete(context.Background(), name, metav1.DeleteOptions{})
62+
err = oc.AdminGatewayApiClient().GatewayV1().Gateways("openshift-ingress").Delete(context.Background(), name, metav1.DeleteOptions{})
8463
o.Expect(err).NotTo(o.HaveOccurred(), "Gateway %s could not be deleted", name)
8564
}
86-
87-
for _, name := range httproutes {
88-
err = gwapiClient.GatewayV1().HTTPRoutes(namespace).Delete(context.Background(), "test-httproute", metav1.DeleteOptions{})
89-
o.Expect(err).NotTo(o.HaveOccurred(), "HttpRoute %s could not be deleted", name)
90-
}
9165
})
9266

9367
g.It("Ensure OSSM and OLM related resources are created after creating GatewayClass", func() {
@@ -158,23 +132,22 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
158132

159133
})
160134
g.It("Ensure custom gatewayclass can be accepted", func() {
161-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
162135
customGatewayClassName := "custom-gatewayclass"
163136

164137
g.By("Create Custom GatewayClass")
165138
gatewayClass := buildGatewayClass(customGatewayClassName, gatewayClassControllerName)
166-
gwc, err := gwapiClient.GatewayV1().GatewayClasses().Create(context.TODO(), gatewayClass, metav1.CreateOptions{})
139+
gwc, err := oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Create(context.TODO(), gatewayClass, metav1.CreateOptions{})
167140
if err != nil {
168141
e2e.Logf("Gateway Class \"custom-gatewayclass\" already exists, or has failed to be created, checking its status")
169142
}
170143
errCheck := checkGatewayClass(oc, customGatewayClassName)
171144
o.Expect(errCheck).NotTo(o.HaveOccurred(), "GatewayClass %q was not installed and accepted", gwc.Name)
172145

173146
g.By("Deleting Custom GatewayClass and confirming that it is no longer there")
174-
err = gwapiClient.GatewayV1().GatewayClasses().Delete(context.Background(), customGatewayClassName, metav1.DeleteOptions{})
147+
err = oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Delete(context.Background(), customGatewayClassName, metav1.DeleteOptions{})
175148
o.Expect(err).NotTo(o.HaveOccurred())
176149

177-
_, err = gwapiClient.GatewayV1().GatewayClasses().Get(context.Background(), customGatewayClassName, metav1.GetOptions{})
150+
_, err = oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Get(context.Background(), customGatewayClassName, metav1.GetOptions{})
178151
o.Expect(err).To(o.HaveOccurred(), "The custom gatewayClass \"custom-gatewayclass\" has been sucessfully deleted")
179152

180153
g.By("check if default gatewayClass is accepted and ISTIO CR and pod are still available")
@@ -186,6 +159,9 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
186159
})
187160

188161
g.It("Ensure LB, service, and dnsRecord are created for a Gateway object", func() {
162+
// skip since gateway needs LB service
163+
skipGatewayIfNonCloudPlatform(oc)
164+
189165
var lbAddress string
190166
g.By("Ensure default GatewayClass is accepted")
191167
errCheck := checkGatewayClass(oc, gatewayClassName)
@@ -213,8 +189,7 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
213189
}
214190
e2e.Logf("The load balancer External-IP is: %v", lbAddress)
215191

216-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
217-
gwlist, haerr := gwapiClient.GatewayV1().Gateways("openshift-ingress").Get(context.Background(), gw, metav1.GetOptions{})
192+
gwlist, haerr := oc.AdminGatewayApiClient().GatewayV1().Gateways("openshift-ingress").Get(context.Background(), gw, metav1.GetOptions{})
218193
e2e.Logf("The gateway hostname address is %v ", gwlist.Status.Addresses[0].Value)
219194
o.Expect(haerr).NotTo(o.HaveOccurred())
220195
o.Expect(lbAddress).To(o.Equal(gwlist.Status.Addresses[0].Value))
@@ -231,31 +206,48 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
231206
})
232207

233208
g.It("Ensure HTTPRoute object is created", func() {
209+
// skip since gateway needs LB service
210+
skipGatewayIfNonCloudPlatform(oc)
211+
234212
g.By("Ensure default GatewayClass is accepted")
235213
errCheck := checkGatewayClass(oc, gatewayClassName)
236214
o.Expect(errCheck).NotTo(o.HaveOccurred(), "GatewayClass %q was not installed and accepted", gatewayClassName)
237215

238216
g.By("Getting the default domain")
239217
defaultIngressDomain, err := getDefaultIngressClusterDomainName(oc, time.Minute)
240-
o.Expect(err).NotTo(o.HaveOccurred(), "failed to find default domain name")
218+
o.Expect(err).NotTo(o.HaveOccurred(), "Failed to find default domain name")
241219
customDomain := strings.Replace(defaultIngressDomain, "apps.", "gw-custom.", 1)
242220

243221
g.By("Create a custom Gateway for the HTTPRoute")
244222
gw := names.SimpleNameGenerator.GenerateName("gateway-")
245223
gateways = append(gateways, gw)
246224
_, gwerr := createAndCheckGateway(oc, gw, gatewayClassName, customDomain)
247-
o.Expect(gwerr).NotTo(o.HaveOccurred(), "failed to create Gateway")
225+
o.Expect(gwerr).NotTo(o.HaveOccurred(), "Failed to create Gateway")
248226

249227
g.By("Create the http route using the custom gateway")
250-
httproutes = append(httproutes, "test-httproute")
251-
defaultRoutename := "test-hostname.gwapi." + customDomain
228+
defaultRoutename := "test-hostname." + customDomain
252229
createHttpRoute(oc, gw, "test-httproute", defaultRoutename, "echo-pod-"+gw)
253230

254231
g.By("Checking the http route using the default gateway is accepted")
255232
assertHttpRouteSuccessful(oc, gw, "test-httproute")
256233
})
257234
})
258235

236+
func skipGatewayIfNonCloudPlatform(oc *exutil.CLI) {
237+
infra, err := oc.AdminConfigClient().ConfigV1().Infrastructures().Get(context.Background(), "cluster", metav1.GetOptions{})
238+
o.Expect(err).NotTo(o.HaveOccurred())
239+
o.Expect(infra).NotTo(o.BeNil())
240+
241+
platformType := infra.Status.PlatformStatus.Type
242+
o.Expect(platformType).NotTo(o.BeNil())
243+
switch platformType {
244+
case configv1.AWSPlatformType, configv1.AzurePlatformType, configv1.GCPPlatformType, configv1.IBMCloudPlatformType:
245+
// supported
246+
default:
247+
g.Skip(fmt.Sprintf("Skipping on non cloud platform type %q", platformType))
248+
}
249+
}
250+
259251
func waitForIstioHealthy(oc *exutil.CLI) {
260252
resource := types.NamespacedName{Namespace: "openshift-ingress", Name: "openshift-gateway"}
261253
err := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 10*time.Minute, false, func(context context.Context) (bool, error) {
@@ -272,12 +264,10 @@ func waitForIstioHealthy(oc *exutil.CLI) {
272264
}
273265

274266
func checkGatewayClass(oc *exutil.CLI, name string) error {
275-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
276-
277267
waitErr := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 10*time.Minute, false, func(context context.Context) (bool, error) {
278-
gwc, err := gwapiClient.GatewayV1().GatewayClasses().Get(context, name, metav1.GetOptions{})
268+
gwc, err := oc.AdminGatewayApiClient().GatewayV1().GatewayClasses().Get(context, name, metav1.GetOptions{})
279269
if err != nil {
280-
e2e.Logf("failed to get gatewayclass %s, retrying...", name)
270+
e2e.Logf("Failed to get gatewayclass %s, retrying...", name)
281271
return false, nil
282272
}
283273
for _, condition := range gwc.Status.Conditions {
@@ -307,14 +297,13 @@ func buildGatewayClass(name, controllerName string) *gatewayapiv1.GatewayClass {
307297

308298
// createAndCheckGateway build and creates the Gateway.
309299
func createAndCheckGateway(oc *exutil.CLI, gwname, gwclassname, domain string) (*gatewayapiv1.Gateway, error) {
310-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
311300
ingressNameSpace := "openshift-ingress"
312301

313302
// Build the gateway object
314303
gatewaybuild := buildGateway(gwname, ingressNameSpace, gwclassname, "All", domain)
315304

316305
// Create the gateway object
317-
_, errGwObj := gwapiClient.GatewayV1().Gateways(ingressNameSpace).Create(context.TODO(), gatewaybuild, metav1.CreateOptions{})
306+
_, errGwObj := oc.AdminGatewayApiClient().GatewayV1().Gateways(ingressNameSpace).Create(context.TODO(), gatewaybuild, metav1.CreateOptions{})
318307
if errGwObj != nil {
319308
return nil, errGwObj
320309
}
@@ -324,12 +313,12 @@ func createAndCheckGateway(oc *exutil.CLI, gwname, gwclassname, domain string) (
324313
}
325314

326315
func checkGatewayStatus(oc *exutil.CLI, gwname, ingressNameSpace string) (*gatewayapiv1.Gateway, error) {
327-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
316+
var err error
328317
gateway := &gatewayapiv1.Gateway{}
329318

330319
waitErr := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 10*time.Minute, false, func(context context.Context) (bool, error) {
331-
gateway, errGwStatus := gwapiClient.GatewayV1().Gateways(ingressNameSpace).Get(context, gwname, metav1.GetOptions{})
332-
if errGwStatus != nil {
320+
gateway, err = oc.AdminGatewayApiClient().GatewayV1().Gateways(ingressNameSpace).Get(context, gwname, metav1.GetOptions{})
321+
if err != nil {
333322
e2e.Logf("Failed to get gateway object, retrying...")
334323
return false, nil
335324
}
@@ -342,20 +331,20 @@ func checkGatewayStatus(oc *exutil.CLI, gwname, ingressNameSpace string) (*gatew
342331
}
343332
}
344333
}
345-
e2e.Logf("Found gateway but the controller is still not programmed, retrying...")
334+
e2e.Logf("Found gateway %q but the controller is still not programmed, retrying...", gateway.Name)
346335
return false, nil
347336
})
348337

349338
if waitErr != nil {
350-
return nil, fmt.Errorf("timed out waiting for gateway %q to become programmed: %w", gateway.Name, waitErr)
339+
return nil, fmt.Errorf("Timed out waiting for gateway %q to become programmed: %w", gateway.Name, waitErr)
351340
}
352341
e2e.Logf("Gateway %q successfully programmed!", gateway.Name)
353342
return gateway, nil
354343
}
355344

356345
// buildGateway initializes the Gateway and returns its address.
357346
func buildGateway(name, namespace, gcname, fromNs, domain string) *gatewayapiv1.Gateway {
358-
hostname := gatewayapiv1.Hostname("*." + "gwapi." + domain)
347+
hostname := gatewayapiv1.Hostname("*." + domain)
359348
fromNamespace := gatewayapiv1.FromNamespaces(fromNs)
360349
// Tell the gateway listener to allow routes from the namespace/s in the fromNamespaces variable, which could be "All".
361350
allowedRoutes := gatewayapiv1.AllowedRoutes{Namespaces: &gatewayapiv1.RouteNamespaces{From: &fromNamespace}}
@@ -373,34 +362,34 @@ func buildGateway(name, namespace, gcname, fromNs, domain string) *gatewayapiv1.
373362
// createHttpRoute checks if the HTTPRoute can be created.
374363
// If it can't an error is returned.
375364
func createHttpRoute(oc *exutil.CLI, gwName, routeName, hostname, backendRefname string) (*gatewayapiv1.HTTPRoute, error) {
376-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
377365
namespace := oc.Namespace()
378366
ingressNameSpace := "openshift-ingress"
379-
gateway, errGwStatus := gwapiClient.GatewayV1().Gateways(ingressNameSpace).Get(context.TODO(), gwName, metav1.GetOptions{})
367+
gateway, errGwStatus := oc.AdminGatewayApiClient().GatewayV1().Gateways(ingressNameSpace).Get(context.TODO(), gwName, metav1.GetOptions{})
380368
if errGwStatus != nil || gateway == nil {
381369
e2e.Failf("Unable to create httpRoute, no gateway available during route assertion %v", errGwStatus)
382370
}
383371

384372
// Create the backend (service and pod) needed for the route to have resolvedRefs=true.
385-
// The http route, service, and pod are cleaned up when the namespace is automatically deleted.
373+
// The httproute, service, and pod are cleaned up when the namespace is automatically deleted.
386374
// buildEchoPod builds a pod that listens on port 8080.
375+
// Use regular user to create pod, service and httproute.
387376
echoPod := buildEchoPod(backendRefname, namespace)
388-
_, echoPodErr := oc.AdminKubeClient().CoreV1().Pods(namespace).Create(context.TODO(), echoPod, metav1.CreateOptions{})
377+
_, echoPodErr := oc.KubeClient().CoreV1().Pods(namespace).Create(context.TODO(), echoPod, metav1.CreateOptions{})
389378
o.Expect(echoPodErr).NotTo(o.HaveOccurred())
390379

391380
// buildEchoService builds a service that targets port 8080.
392381
echoService := buildEchoService(echoPod.Name, namespace, echoPod.ObjectMeta.Labels)
393-
_, echoServiceErr := oc.AdminKubeClient().CoreV1().Services(namespace).Create(context.Background(), echoService, metav1.CreateOptions{})
382+
_, echoServiceErr := oc.KubeClient().CoreV1().Services(namespace).Create(context.Background(), echoService, metav1.CreateOptions{})
394383
o.Expect(echoServiceErr).NotTo(o.HaveOccurred())
395384

396385
// Create the HTTPRoute
397386
buildHTTPRoute := buildHTTPRoute(routeName, namespace, gateway.Name, ingressNameSpace, hostname, backendRefname)
398-
httpRoute, err := gwapiClient.GatewayV1().HTTPRoutes(namespace).Create(context.Background(), buildHTTPRoute, metav1.CreateOptions{})
387+
httpRoute, err := oc.GatewayApiClient().GatewayV1().HTTPRoutes(namespace).Create(context.Background(), buildHTTPRoute, metav1.CreateOptions{})
399388
o.Expect(err).NotTo(o.HaveOccurred())
400389

401390
// Confirm the HTTPRoute is up
402391
waitErr := wait.PollUntilContextTimeout(context.Background(), 1*time.Second, 4*time.Minute, false, func(context context.Context) (bool, error) {
403-
checkHttpRoute, err := gwapiClient.GatewayV1().HTTPRoutes(namespace).Get(context, httpRoute.Name, metav1.GetOptions{})
392+
checkHttpRoute, err := oc.GatewayApiClient().GatewayV1().HTTPRoutes(namespace).Get(context, httpRoute.Name, metav1.GetOptions{})
404393
o.Expect(err).NotTo(o.HaveOccurred())
405394
for _, condition := range checkHttpRoute.Status.Parents[0].Conditions {
406395
if condition.Type == string(gatewayapiv1.RouteConditionAccepted) {
@@ -514,28 +503,27 @@ func assertHttpRouteSuccessful(oc *exutil.CLI, gwName, name string) (*gatewayapi
514503
namespace := oc.Namespace()
515504
checkHttpRoute := &gatewayapiv1.HTTPRoute{}
516505
ingressNameSpace := "openshift-ingress"
517-
gwapiClient := gatewayapiclientset.NewForConfigOrDie(oc.AdminConfig())
518-
gateway, errGwStatus := gwapiClient.GatewayV1().Gateways(ingressNameSpace).Get(context.TODO(), gwName, metav1.GetOptions{})
506+
gateway, errGwStatus := oc.AdminGatewayApiClient().GatewayV1().Gateways(ingressNameSpace).Get(context.TODO(), gwName, metav1.GetOptions{})
519507
if errGwStatus != nil || gateway == nil {
520-
e2e.Failf("Unable to assert httpRoute, no gateway available, error %v", errGwStatus)
508+
e2e.Failf("Unable to assert httproute, no gateway available, error %v", errGwStatus)
521509
}
522510

523511
// Wait up to 4 minutes for parent(s) to update.
524512
err := wait.PollUntilContextTimeout(context.Background(), 2*time.Second, 4*time.Minute, false, func(context context.Context) (bool, error) {
525-
checkHttpRoute, err := gwapiClient.GatewayV1().HTTPRoutes(namespace).Get(context, name, metav1.GetOptions{})
513+
checkHttpRoute, err := oc.GatewayApiClient().GatewayV1().HTTPRoutes(namespace).Get(context, name, metav1.GetOptions{})
526514
o.Expect(err).NotTo(o.HaveOccurred())
527515

528516
numParents := len(checkHttpRoute.Status.Parents)
529517
if numParents == 0 {
530-
e2e.Logf("httpRoute %s/%s has no parent conditions, retrying...", namespace, name)
518+
e2e.Logf("HTTPRoute %s/%s has no parent conditions, retrying...", namespace, name)
531519
return false, nil
532520
}
533-
e2e.Logf("found httproute %s/%s with %d parent/s", namespace, name, numParents)
521+
e2e.Logf("Found httproute %s/%s with %d parent/s", namespace, name, numParents)
534522
return true, nil
535523
})
536524
if err != nil {
537525
return nil, err
538526
}
539-
e2e.Logf("httpRoute %s/%s successful", namespace, name)
527+
e2e.Logf("HTTPRoute %s/%s successful", namespace, name)
540528
return checkHttpRoute, nil
541529
}

test/extended/util/client.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import (
7676
userv1client "github.com/openshift/client-go/user/clientset/versioned"
7777
"github.com/openshift/library-go/test/library/metrics"
7878
apiextensionsclient "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset"
79+
gatewayapiv1client "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
7980
)
8081

8182
// CLI provides function to call the OpenShift CLI and Kubernetes and OpenShift
@@ -674,6 +675,11 @@ func (c *CLI) BuildClient() buildv1client.Interface {
674675
return buildv1client.NewForConfigOrDie(c.UserConfig())
675676
}
676677

678+
// GatewayApiClient provides a GatewayAPI client for the current namespace user.
679+
func (c *CLI) GatewayApiClient() gatewayapiv1client.Interface {
680+
return gatewayapiv1client.NewForConfigOrDie(c.UserConfig())
681+
}
682+
677683
func (c *CLI) ImageClient() imagev1client.Interface {
678684
return imagev1client.NewForConfigOrDie(c.UserConfig())
679685
}
@@ -717,6 +723,11 @@ func (c *CLI) AdminConfigClient() configv1client.Interface {
717723
)
718724
}
719725

726+
// AdminGatewayApiClient provides a GatewayAPI client for the cluster admin user.
727+
func (c *CLI) AdminGatewayApiClient() gatewayapiv1client.Interface {
728+
return gatewayapiv1client.NewForConfigOrDie(c.AdminConfig())
729+
}
730+
720731
func (c *CLI) AdminImageClient() imagev1client.Interface {
721732
return imagev1client.NewForConfigOrDie(c.AdminConfig())
722733
}

0 commit comments

Comments
 (0)