@@ -23,17 +23,15 @@ import (
23
23
"k8s.io/apimachinery/pkg/util/wait"
24
24
"k8s.io/apiserver/pkg/storage/names"
25
25
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
26
- gatewayapiclientset "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
27
26
)
28
27
29
28
var _ = g .Describe ("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feature:Router][apigroup:gateway.networking.k8s.io]" , g .Ordered , g .Serial , func () {
30
29
defer g .GinkgoRecover ()
31
30
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
37
35
)
38
36
const (
39
37
// The expected OSSM subscription name.
@@ -50,44 +48,20 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
50
48
deploymentOSSMName = "servicemesh-operator3"
51
49
)
52
50
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 ())
69
51
// create the default gatewayClass
70
52
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 {})
72
54
if err != nil && ! apierrors .IsAlreadyExists (err ) {
73
55
e2e .Failf ("Failed to create GatewayClass %q" , gatewayClassName )
74
56
}
75
-
76
57
})
77
58
78
59
g .AfterAll (func () {
79
- gwapiClient := gatewayapiclientset .NewForConfigOrDie (oc .AdminConfig ())
80
- namespace := oc .Namespace ()
81
60
g .By ("Cleaning up the GatewayAPI Objects" )
82
61
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 {})
84
63
o .Expect (err ).NotTo (o .HaveOccurred (), "Gateway %s could not be deleted" , name )
85
64
}
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
- }
91
65
})
92
66
93
67
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
158
132
159
133
})
160
134
g .It ("Ensure custom gatewayclass can be accepted" , func () {
161
- gwapiClient := gatewayapiclientset .NewForConfigOrDie (oc .AdminConfig ())
162
135
customGatewayClassName := "custom-gatewayclass"
163
136
164
137
g .By ("Create Custom GatewayClass" )
165
138
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 {})
167
140
if err != nil {
168
141
e2e .Logf ("Gateway Class \" custom-gatewayclass\" already exists, or has failed to be created, checking its status" )
169
142
}
170
143
errCheck := checkGatewayClass (oc , customGatewayClassName )
171
144
o .Expect (errCheck ).NotTo (o .HaveOccurred (), "GatewayClass %q was not installed and accepted" , gwc .Name )
172
145
173
146
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 {})
175
148
o .Expect (err ).NotTo (o .HaveOccurred ())
176
149
177
- _ , err = gwapiClient .GatewayV1 ().GatewayClasses ().Get (context .Background (), customGatewayClassName , metav1.GetOptions {})
150
+ _ , err = oc . AdminGatewayApiClient () .GatewayV1 ().GatewayClasses ().Get (context .Background (), customGatewayClassName , metav1.GetOptions {})
178
151
o .Expect (err ).To (o .HaveOccurred (), "The custom gatewayClass \" custom-gatewayclass\" has been sucessfully deleted" )
179
152
180
153
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
186
159
})
187
160
188
161
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
+
189
165
var lbAddress string
190
166
g .By ("Ensure default GatewayClass is accepted" )
191
167
errCheck := checkGatewayClass (oc , gatewayClassName )
@@ -213,8 +189,7 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
213
189
}
214
190
e2e .Logf ("The load balancer External-IP is: %v" , lbAddress )
215
191
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 {})
218
193
e2e .Logf ("The gateway hostname address is %v " , gwlist .Status .Addresses [0 ].Value )
219
194
o .Expect (haerr ).NotTo (o .HaveOccurred ())
220
195
o .Expect (lbAddress ).To (o .Equal (gwlist .Status .Addresses [0 ].Value ))
@@ -231,31 +206,48 @@ var _ = g.Describe("[sig-network-edge][OCPFeatureGate:GatewayAPIController][Feat
231
206
})
232
207
233
208
g .It ("Ensure HTTPRoute object is created" , func () {
209
+ // skip since gateway needs LB service
210
+ skipGatewayIfNonCloudPlatform (oc )
211
+
234
212
g .By ("Ensure default GatewayClass is accepted" )
235
213
errCheck := checkGatewayClass (oc , gatewayClassName )
236
214
o .Expect (errCheck ).NotTo (o .HaveOccurred (), "GatewayClass %q was not installed and accepted" , gatewayClassName )
237
215
238
216
g .By ("Getting the default domain" )
239
217
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" )
241
219
customDomain := strings .Replace (defaultIngressDomain , "apps." , "gw-custom." , 1 )
242
220
243
221
g .By ("Create a custom Gateway for the HTTPRoute" )
244
222
gw := names .SimpleNameGenerator .GenerateName ("gateway-" )
245
223
gateways = append (gateways , gw )
246
224
_ , 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" )
248
226
249
227
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
252
229
createHttpRoute (oc , gw , "test-httproute" , defaultRoutename , "echo-pod-" + gw )
253
230
254
231
g .By ("Checking the http route using the default gateway is accepted" )
255
232
assertHttpRouteSuccessful (oc , gw , "test-httproute" )
256
233
})
257
234
})
258
235
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
+
259
251
func waitForIstioHealthy (oc * exutil.CLI ) {
260
252
resource := types.NamespacedName {Namespace : "openshift-ingress" , Name : "openshift-gateway" }
261
253
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) {
272
264
}
273
265
274
266
func checkGatewayClass (oc * exutil.CLI , name string ) error {
275
- gwapiClient := gatewayapiclientset .NewForConfigOrDie (oc .AdminConfig ())
276
-
277
267
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 {})
279
269
if err != nil {
280
- e2e .Logf ("failed to get gatewayclass %s, retrying..." , name )
270
+ e2e .Logf ("Failed to get gatewayclass %s, retrying..." , name )
281
271
return false , nil
282
272
}
283
273
for _ , condition := range gwc .Status .Conditions {
@@ -307,14 +297,13 @@ func buildGatewayClass(name, controllerName string) *gatewayapiv1.GatewayClass {
307
297
308
298
// createAndCheckGateway build and creates the Gateway.
309
299
func createAndCheckGateway (oc * exutil.CLI , gwname , gwclassname , domain string ) (* gatewayapiv1.Gateway , error ) {
310
- gwapiClient := gatewayapiclientset .NewForConfigOrDie (oc .AdminConfig ())
311
300
ingressNameSpace := "openshift-ingress"
312
301
313
302
// Build the gateway object
314
303
gatewaybuild := buildGateway (gwname , ingressNameSpace , gwclassname , "All" , domain )
315
304
316
305
// 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 {})
318
307
if errGwObj != nil {
319
308
return nil , errGwObj
320
309
}
@@ -324,12 +313,12 @@ func createAndCheckGateway(oc *exutil.CLI, gwname, gwclassname, domain string) (
324
313
}
325
314
326
315
func checkGatewayStatus (oc * exutil.CLI , gwname , ingressNameSpace string ) (* gatewayapiv1.Gateway , error ) {
327
- gwapiClient := gatewayapiclientset . NewForConfigOrDie ( oc . AdminConfig ())
316
+ var err error
328
317
gateway := & gatewayapiv1.Gateway {}
329
318
330
319
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 {
333
322
e2e .Logf ("Failed to get gateway object, retrying..." )
334
323
return false , nil
335
324
}
@@ -342,20 +331,20 @@ func checkGatewayStatus(oc *exutil.CLI, gwname, ingressNameSpace string) (*gatew
342
331
}
343
332
}
344
333
}
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 )
346
335
return false , nil
347
336
})
348
337
349
338
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 )
351
340
}
352
341
e2e .Logf ("Gateway %q successfully programmed!" , gateway .Name )
353
342
return gateway , nil
354
343
}
355
344
356
345
// buildGateway initializes the Gateway and returns its address.
357
346
func buildGateway (name , namespace , gcname , fromNs , domain string ) * gatewayapiv1.Gateway {
358
- hostname := gatewayapiv1 .Hostname ("*." + "gwapi." + domain )
347
+ hostname := gatewayapiv1 .Hostname ("*." + domain )
359
348
fromNamespace := gatewayapiv1 .FromNamespaces (fromNs )
360
349
// Tell the gateway listener to allow routes from the namespace/s in the fromNamespaces variable, which could be "All".
361
350
allowedRoutes := gatewayapiv1.AllowedRoutes {Namespaces : & gatewayapiv1.RouteNamespaces {From : & fromNamespace }}
@@ -373,34 +362,34 @@ func buildGateway(name, namespace, gcname, fromNs, domain string) *gatewayapiv1.
373
362
// createHttpRoute checks if the HTTPRoute can be created.
374
363
// If it can't an error is returned.
375
364
func createHttpRoute (oc * exutil.CLI , gwName , routeName , hostname , backendRefname string ) (* gatewayapiv1.HTTPRoute , error ) {
376
- gwapiClient := gatewayapiclientset .NewForConfigOrDie (oc .AdminConfig ())
377
365
namespace := oc .Namespace ()
378
366
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 {})
380
368
if errGwStatus != nil || gateway == nil {
381
369
e2e .Failf ("Unable to create httpRoute, no gateway available during route assertion %v" , errGwStatus )
382
370
}
383
371
384
372
// 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.
386
374
// buildEchoPod builds a pod that listens on port 8080.
375
+ // Use regular user to create pod, service and httproute.
387
376
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 {})
389
378
o .Expect (echoPodErr ).NotTo (o .HaveOccurred ())
390
379
391
380
// buildEchoService builds a service that targets port 8080.
392
381
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 {})
394
383
o .Expect (echoServiceErr ).NotTo (o .HaveOccurred ())
395
384
396
385
// Create the HTTPRoute
397
386
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 {})
399
388
o .Expect (err ).NotTo (o .HaveOccurred ())
400
389
401
390
// Confirm the HTTPRoute is up
402
391
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 {})
404
393
o .Expect (err ).NotTo (o .HaveOccurred ())
405
394
for _ , condition := range checkHttpRoute .Status .Parents [0 ].Conditions {
406
395
if condition .Type == string (gatewayapiv1 .RouteConditionAccepted ) {
@@ -514,28 +503,27 @@ func assertHttpRouteSuccessful(oc *exutil.CLI, gwName, name string) (*gatewayapi
514
503
namespace := oc .Namespace ()
515
504
checkHttpRoute := & gatewayapiv1.HTTPRoute {}
516
505
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 {})
519
507
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 )
521
509
}
522
510
523
511
// Wait up to 4 minutes for parent(s) to update.
524
512
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 {})
526
514
o .Expect (err ).NotTo (o .HaveOccurred ())
527
515
528
516
numParents := len (checkHttpRoute .Status .Parents )
529
517
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 )
531
519
return false , nil
532
520
}
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 )
534
522
return true , nil
535
523
})
536
524
if err != nil {
537
525
return nil , err
538
526
}
539
- e2e .Logf ("httpRoute %s/%s successful" , namespace , name )
527
+ e2e .Logf ("HTTPRoute %s/%s successful" , namespace , name )
540
528
return checkHttpRoute , nil
541
529
}
0 commit comments