56
56
privateSvcIP = "5.6.7.8"
57
57
publicSvc = network .GetServiceHostname (publicName , testNamespace )
58
58
privateSvc = network .GetServiceHostname (privateName , testNamespace )
59
+
60
+ gatewayRef = gatewayapi.ParentReference {
61
+ Group : (* gatewayapi .Group )(pointer .String ("gateway.networking.k8s.io" )),
62
+ Kind : (* gatewayapi .Kind )(pointer .String ("Gateway" )),
63
+ Namespace : (* gatewayapi .Namespace )(pointer .String ("istio-system" )),
64
+ Name : gatewayapi .ObjectName ("istio-gateway" ),
65
+ }
59
66
)
60
67
61
68
var (
@@ -149,19 +156,19 @@ func TestReconcile(t *testing.T) {
149
156
Name : "skip ingress marked for deletion" ,
150
157
Key : "ns/name" ,
151
158
Objects : []runtime.Object {
152
- ing (withBasicSpec , withGatewayAPIclass , func (i * v1alpha1.Ingress ) {
159
+ ing (withBasicSpec , withGatewayAPIClass , func (i * v1alpha1.Ingress ) {
153
160
i .SetDeletionTimestamp (& metav1.Time {Time : time .Now ()})
154
161
}),
155
162
},
156
163
}, {
157
164
Name : "first reconcile basic ingress" ,
158
165
Key : "ns/name" ,
159
166
Objects : append ([]runtime.Object {
160
- ing (withBasicSpec , withGatewayAPIclass ),
167
+ ing (withBasicSpec , withGatewayAPIClass ),
161
168
}, servicesAndEndpoints ... ),
162
- WantCreates : []runtime.Object {httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ))},
169
+ WantCreates : []runtime.Object {httpRoute (t , ing (withBasicSpec , withGatewayAPIClass ))},
163
170
WantStatusUpdates : []clientgotesting.UpdateActionImpl {{
164
- Object : ing (withBasicSpec , withGatewayAPIclass , func (i * v1alpha1.Ingress ) {
171
+ Object : ing (withBasicSpec , withGatewayAPIClass , func (i * v1alpha1.Ingress ) {
165
172
// These are the things we expect to change in status.
166
173
i .Status .InitializeConditions ()
167
174
i .Status .MarkLoadBalancerReady (
@@ -188,8 +195,8 @@ func TestReconcile(t *testing.T) {
188
195
Name : "reconcile ready ingress" ,
189
196
Key : "ns/name" ,
190
197
Objects : append ([]runtime.Object {
191
- ing (withBasicSpec , withGatewayAPIclass , makeItReady , withFinalizer ),
192
- httpRoute (t , ing (withBasicSpec , withGatewayAPIclass )),
198
+ ing (withBasicSpec , withGatewayAPIClass , makeItReady , withFinalizer ),
199
+ httpRoute (t , ing (withBasicSpec , withGatewayAPIClass )),
193
200
}, servicesAndEndpoints ... ),
194
201
// no extra update
195
202
}}
@@ -223,11 +230,11 @@ func TestReconcileProberNotReady(t *testing.T) {
223
230
Name : "first reconcile basic ingress wth prober" ,
224
231
Key : "ns/name" ,
225
232
Objects : append ([]runtime.Object {
226
- ing (withBasicSpec , withGatewayAPIclass ),
233
+ ing (withBasicSpec , withGatewayAPIClass ),
227
234
}, servicesAndEndpoints ... ),
228
- WantCreates : []runtime.Object {httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ))},
235
+ WantCreates : []runtime.Object {httpRoute (t , ing (withBasicSpec , withGatewayAPIClass ))},
229
236
WantStatusUpdates : []clientgotesting.UpdateActionImpl {{
230
- Object : ing (withBasicSpec , withGatewayAPIclass , func (i * v1alpha1.Ingress ) {
237
+ Object : ing (withBasicSpec , withGatewayAPIClass , func (i * v1alpha1.Ingress ) {
231
238
i .Status .InitializeConditions ()
232
239
i .Status .MarkLoadBalancerNotReady ()
233
240
}),
@@ -389,6 +396,47 @@ func TestReconcileTLS(t *testing.T) {
389
396
Eventf (corev1 .EventTypeWarning , "GatewayMissing" , `Unable to update Gateway istio-system/istio-gateway` ),
390
397
Eventf (corev1 .EventTypeWarning , "InternalError" , `Gateway istio-system/istio-gateway does not exist: gateway.gateway.networking.k8s.io "istio-gateway" not found` ),
391
398
},
399
+ }, {
400
+ Name : "TLS ingress with httpOption redirected" ,
401
+ Key : "ns/name" ,
402
+ Objects : append ([]runtime.Object {
403
+ ing (withBasicSpec , withGatewayAPIClass , withHTTPOptionRedirected , withTLS (secretName )),
404
+ secret (secretName , nsName ),
405
+ gw (defaultListener ),
406
+ }, servicesAndEndpoints ... ),
407
+ WantCreates : []runtime.Object {
408
+ httpRoute (t , ing (withBasicSpec , withGatewayAPIClass , withHTTPOptionRedirected , withTLS (secretName )), withSectionName ("kni-" )),
409
+ httpRedirectRoute (t , ing (withBasicSpec , withGatewayAPIClass , withHTTPOptionRedirected , withTLS (secretName )), withSectionName ("http" )),
410
+ rp (secret (secretName , nsName )),
411
+ },
412
+ WantUpdates : []clientgotesting.UpdateActionImpl {{
413
+ Object : gw (defaultListener , tlsListener ("secure.example.com" , nsName , secretName )),
414
+ }},
415
+ WantStatusUpdates : []clientgotesting.UpdateActionImpl {{
416
+ Object : ing (withBasicSpec , withGatewayAPIClass , withHTTPOptionRedirected , withTLS (secretName ), func (i * v1alpha1.Ingress ) {
417
+ // These are the things we expect to change in status.
418
+ i .Status .InitializeConditions ()
419
+ i .Status .MarkLoadBalancerReady (
420
+ []v1alpha1.LoadBalancerIngressStatus {{
421
+ DomainInternal : publicSvc ,
422
+ }},
423
+ []v1alpha1.LoadBalancerIngressStatus {{
424
+ DomainInternal : privateSvc ,
425
+ }})
426
+ }),
427
+ }},
428
+ WantPatches : []clientgotesting.PatchActionImpl {{
429
+ ActionImpl : clientgotesting.ActionImpl {
430
+ Namespace : "ns" ,
431
+ },
432
+ Name : "name" ,
433
+ Patch : []byte (`{"metadata":{"finalizers":["ingresses.networking.internal.knative.dev"],"resourceVersion":""}}` ),
434
+ }},
435
+ WantEvents : []string {
436
+ Eventf (corev1 .EventTypeNormal , "FinalizerUpdate" , `Updated "name" finalizers` ),
437
+ Eventf (corev1 .EventTypeNormal , "Created" , "Created HTTPRoute \" example.com\" " ),
438
+ Eventf (corev1 .EventTypeNormal , "Created" , "Created HTTPRoute \" example.com-redirect\" " ),
439
+ },
392
440
}}
393
441
394
442
table .Test (t , GatewayFactory (func (ctx context.Context , listers * Listers , cmw configmap.Watcher , tr * TableRow ) controller.Reconciler {
@@ -433,11 +481,11 @@ func TestReconcileProbeError(t *testing.T) {
433
481
Key : "ns/name" ,
434
482
WantErr : true ,
435
483
Objects : append ([]runtime.Object {
436
- ing (withBasicSpec , withGatewayAPIclass ),
484
+ ing (withBasicSpec , withGatewayAPIClass ),
437
485
}, servicesAndEndpoints ... ),
438
- WantCreates : []runtime.Object {httpRoute (t , ing (withBasicSpec , withGatewayAPIclass ))},
486
+ WantCreates : []runtime.Object {httpRoute (t , ing (withBasicSpec , withGatewayAPIClass ))},
439
487
WantStatusUpdates : []clientgotesting.UpdateActionImpl {{
440
- Object : ing (withBasicSpec , withGatewayAPIclass , func (i * v1alpha1.Ingress ) {
488
+ Object : ing (withBasicSpec , withGatewayAPIClass , func (i * v1alpha1.Ingress ) {
441
489
i .Status .InitializeConditions ()
442
490
i .Status .MarkIngressNotReady (notReconciledReason , notReconciledMessage )
443
491
}),
@@ -493,20 +541,31 @@ func makeItReady(i *v1alpha1.Ingress) {
493
541
func httpRoute (t * testing.T , i * v1alpha1.Ingress , opts ... HTTPRouteOption ) runtime.Object {
494
542
t .Helper ()
495
543
ingress .InsertProbe (i )
496
- ctx := ( & testConfigStore { config : defaultConfig }). ToContext ( context . Background ())
497
- httpRoute , _ := resources .MakeHTTPRoute (ctx , i , & i .Spec .Rules [0 ])
544
+
545
+ httpRoute , _ := resources .MakeHTTPRoute (i , & i .Spec .Rules [0 ], gatewayRef )
498
546
for _ , opt := range opts {
499
547
opt (httpRoute )
500
548
}
501
549
return httpRoute
502
550
}
503
551
552
+ func httpRedirectRoute (t * testing.T , i * v1alpha1.Ingress , opts ... HTTPRouteOption ) runtime.Object {
553
+ t .Helper ()
554
+ ingress .InsertProbe (i )
555
+
556
+ httpRedirectRoute , _ := resources .MakeRedirectHTTPRoute (i , & i .Spec .Rules [0 ], gatewayRef )
557
+ for _ , opt := range opts {
558
+ opt (httpRedirectRoute )
559
+ }
560
+ return httpRedirectRoute
561
+ }
562
+
504
563
type HTTPRouteOption func (h * gatewayapi.HTTPRoute )
505
564
506
- func withGatewayAPIclass ( i * v1alpha1. Ingress ) {
507
- withAnnotation ( map [ string ] string {
508
- networking . IngressClassAnnotationKey : gatewayAPIIngressClassName ,
509
- })( i )
565
+ func withSectionName ( sectionName string ) HTTPRouteOption {
566
+ return func ( h * gatewayapi. HTTPRoute ) {
567
+ h . Spec . CommonRouteSpec . ParentRefs [ 0 ]. SectionName = ( * gatewayapi . SectionName )( pointer . String ( sectionName ))
568
+ }
510
569
}
511
570
512
571
type fakeStatusManager struct {
@@ -566,7 +625,7 @@ func defaultListener(g *gatewayapi.Gateway) {
566
625
func tlsListener (hostname , nsName , secretName string ) GatewayOption {
567
626
return func (g * gatewayapi.Gateway ) {
568
627
g .Spec .Listeners = append (g .Spec .Listeners , gatewayapi.Listener {
569
- Name : gatewayapi . SectionName ( "kni-" ) ,
628
+ Name : "kni-" ,
570
629
Hostname : (* gatewayapi .Hostname )(& hostname ),
571
630
Port : 443 ,
572
631
Protocol : "HTTPS" ,
@@ -644,8 +703,8 @@ func rp(to *corev1.Secret) *gatewayapialpha.ReferenceGrant {
644
703
Namespace : gatewayapialpha .Namespace (testNamespace ),
645
704
}},
646
705
To : []gatewayapialpha.ReferenceGrantTo {{
647
- Group : gatewayapialpha . Group ( "" ) ,
648
- Kind : gatewayapialpha . Kind ( "Secret" ) ,
706
+ Group : "" ,
707
+ Kind : "Secret" ,
649
708
Name : (* gatewayapialpha .ObjectName )(& to .Name ),
650
709
}},
651
710
},
@@ -658,12 +717,14 @@ var (
658
717
Gateway : & config.Gateway {
659
718
Gateways : map [v1alpha1.IngressVisibility ]config.GatewayConfig {
660
719
v1alpha1 .IngressVisibilityExternalIP : {
661
- Service : & types.NamespacedName {Namespace : "istio-system" , Name : "istio-gateway" },
662
- Gateway : & types.NamespacedName {Namespace : "istio-system" , Name : "istio-gateway" },
720
+ Service : & types.NamespacedName {Namespace : "istio-system" , Name : "istio-gateway" },
721
+ Gateway : & types.NamespacedName {Namespace : "istio-system" , Name : "istio-gateway" },
722
+ HTTPListenerName : "http" ,
663
723
},
664
724
v1alpha1 .IngressVisibilityClusterLocal : {
665
- Service : & types.NamespacedName {Namespace : "istio-system" , Name : "knative-local-gateway" },
666
- Gateway : & types.NamespacedName {Namespace : "istio-system" , Name : "knative-local-gateway" },
725
+ Service : & types.NamespacedName {Namespace : "istio-system" , Name : "knative-local-gateway" },
726
+ Gateway : & types.NamespacedName {Namespace : "istio-system" , Name : "knative-local-gateway" },
727
+ HTTPListenerName : "http" ,
667
728
},
668
729
},
669
730
},
0 commit comments