Skip to content

Commit cb21626

Browse files
committed
Rebase update
1 parent a8a050e commit cb21626

File tree

6 files changed

+60
-100
lines changed

6 files changed

+60
-100
lines changed

docs/test-version.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@ The following Gateway API version and Ingress were tested as part of the release
1515

1616
| Ingress | Tested version | Unavailable features |
1717
| ------- | ----------------------- | ------------------------------ |
18-
| Istio | v1.20.3 | retry,httpoption,update |
19-
| Contour | v1.28.1 | httpoption,update |
18+
| Istio | v1.20.3 | retry,update |
19+
| Contour | v1.28.1 | update |

pkg/reconciler/ingress/ingress.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ func (c *Reconciler) reconcileIngress(ctx context.Context, ing *v1alpha1.Ingress
103103
}
104104

105105
// For now, we only generate the redirected HTTPRoute for external visibility,
106-
// because currently we do not support HTTPs on cluster-local domains.
106+
// because currently we do not (yet) support HTTPs on cluster-local domains.
107107
var redirectHTTPRoute *gatewayapi.HTTPRoute
108108
if ing.Spec.HTTPOption == v1alpha1.HTTPOptionRedirected && rule.Visibility == v1alpha1.IngressVisibilityExternalIP {
109109
redirectHTTPRoute, err = c.reconcileRedirectHTTPRoute(ctx, ing, &rule)

pkg/reconciler/ingress/ingress_test.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -399,20 +399,20 @@ func TestReconcileTLS(t *testing.T) {
399399
Name: "TLS ingress with httpOption redirected",
400400
Key: "ns/name",
401401
Objects: append([]runtime.Object{
402-
ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(secretName)),
402+
ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS()),
403403
secret(secretName, nsName),
404404
gw(defaultListener),
405405
}, servicesAndEndpoints...),
406406
WantCreates: []runtime.Object{
407-
httpRoute(t, ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(secretName)), withSectionName("kni-")),
408-
httpRedirectRoute(t, ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(secretName)), withSectionName("http")),
407+
httpRoute(t, ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS()), withSectionName("kni-")),
408+
httpRedirectRoute(t, ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS()), withSectionName("http")),
409409
rp(secret(secretName, nsName)),
410410
},
411411
WantUpdates: []clientgotesting.UpdateActionImpl{{
412-
Object: gw(defaultListener, tlsListener("secure.example.com", nsName, secretName)),
412+
Object: gw(defaultListener, tlsListener("example.com", nsName, secretName)),
413413
}},
414414
WantStatusUpdates: []clientgotesting.UpdateActionImpl{{
415-
Object: ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(secretName), func(i *v1alpha1.Ingress) {
415+
Object: ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(), func(i *v1alpha1.Ingress) {
416416
// These are the things we expect to change in status.
417417
i.Status.InitializeConditions()
418418
i.Status.MarkLoadBalancerReady(
@@ -540,8 +540,7 @@ func makeItReady(i *v1alpha1.Ingress) {
540540
func httpRoute(t *testing.T, i *v1alpha1.Ingress, opts ...HTTPRouteOption) runtime.Object {
541541
t.Helper()
542542
ingress.InsertProbe(i)
543-
ctx := (&testConfigStore{config: defaultConfig}).ToContext(context.Background())
544-
httpRoute, _ := resources.MakeHTTPRoute(ctx, i, &i.Spec.Rules[0], gatewayRef)
543+
httpRoute, _ := resources.MakeHTTPRoute(i, &i.Spec.Rules[0], gatewayRef)
545544
for _, opt := range opts {
546545
opt(httpRoute)
547546
}
@@ -708,8 +707,8 @@ func rp(to *corev1.Secret) *gatewayapi.ReferenceGrant {
708707
Namespace: gatewayapi.Namespace(testNamespace),
709708
}},
710709
To: []gatewayapi.ReferenceGrantTo{{
711-
Group: gatewayapi.Group(""),
712-
Kind: gatewayapi.Kind("Secret"),
710+
Group: "",
711+
Kind: "Secret",
713712
Name: (*gatewayapi.ObjectName)(&to.Name),
714713
}},
715714
},

pkg/reconciler/ingress/reconcile_resources.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
apierrs "k8s.io/apimachinery/pkg/api/errors"
2626
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2727
"k8s.io/apimachinery/pkg/types"
28+
"k8s.io/utils/pointer"
2829
"k8s.io/utils/ptr"
2930
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
3031
gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1"
@@ -42,7 +43,6 @@ func (c *Reconciler) reconcileWorkloadRoute(
4243
ctx context.Context, ing *netv1alpha1.Ingress,
4344
rule *netv1alpha1.IngressRule,
4445
) (*gatewayapi.HTTPRoute, error) {
45-
4646
gatewayConfig := config.FromContext(ctx).Gateway.Gateways[rule.Visibility]
4747
gatewayRef := gatewayapi.ParentReference{
4848
Group: (*gatewayapi.Group)(&gatewayapi.GroupVersion.Group),
@@ -102,26 +102,25 @@ func (c *Reconciler) reconcileHTTPRoute(ctx context.Context,
102102

103103
recorder := controller.GetEventRecorder(ctx)
104104

105-
httproute, err := c.httprouteLister.HTTPRoutes(ing.Namespace).Get(desired.Name)
105+
httpRoute, err := c.httprouteLister.HTTPRoutes(ing.Namespace).Get(desired.Name)
106106
if apierrs.IsNotFound(err) {
107-
108-
httproute, err = c.gwapiclient.GatewayV1beta1().HTTPRoutes(desired.Namespace).Create(ctx, desired, metav1.CreateOptions{})
107+
httpRoute, err = c.gwapiclient.GatewayV1beta1().HTTPRoutes(desired.Namespace).Create(ctx, desired, metav1.CreateOptions{})
109108
if err != nil {
110109
recorder.Eventf(ing, corev1.EventTypeWarning, "CreationFailed", "Failed to create HTTPRoute: %v", err)
111110
return nil, fmt.Errorf("failed to create HTTPRoute: %w", err)
112111
}
113112

114-
recorder.Eventf(ing, corev1.EventTypeNormal, "Created", "Created HTTPRoute %q", httproute.GetName())
115-
return httproute, nil
113+
recorder.Eventf(ing, corev1.EventTypeNormal, "Created", "Created HTTPRoute %q", httpRoute.GetName())
114+
return httpRoute, nil
116115
} else if err != nil {
117116
return nil, err
118117
} else {
119-
if !equality.Semantic.DeepEqual(httproute.Spec, desired.Spec) ||
120-
!equality.Semantic.DeepEqual(httproute.Annotations, desired.Annotations) ||
121-
!equality.Semantic.DeepEqual(httproute.Labels, desired.Labels) {
118+
if !equality.Semantic.DeepEqual(httpRoute.Spec, desired.Spec) ||
119+
!equality.Semantic.DeepEqual(httpRoute.Annotations, desired.Annotations) ||
120+
!equality.Semantic.DeepEqual(httpRoute.Labels, desired.Labels) {
122121

123122
// Don't modify the informers copy.
124-
origin := httproute.DeepCopy()
123+
origin := httpRoute.DeepCopy()
125124
origin.Spec = desired.Spec
126125
origin.Annotations = desired.Annotations
127126
origin.Labels = desired.Labels
@@ -136,7 +135,7 @@ func (c *Reconciler) reconcileHTTPRoute(ctx context.Context,
136135
}
137136
}
138137

139-
return httproute, err
138+
return httpRoute, err
140139
}
141140

142141
func (c *Reconciler) reconcileTLS(

pkg/reconciler/ingress/resources/httproute.go

Lines changed: 9 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"net/http"
2121
"sort"
2222

23+
"k8s.io/utils/pointer"
2324
"knative.dev/pkg/kmap"
2425

2526
corev1 "k8s.io/api/core/v1"
@@ -75,16 +76,6 @@ func makeHTTPRouteSpec(
7576

7677
rules := makeHTTPRouteRule(rule)
7778

78-
gatewayConfig := config.FromContext(ctx).Gateway
79-
namespacedNameGateway := gatewayConfig.Gateways[rule.Visibility].Gateway
80-
81-
gatewayRef := gatewayapi.ParentReference{
82-
Group: (*gatewayapi.Group)(&gatewayapi.GroupVersion.Group),
83-
Kind: (*gatewayapi.Kind)(ptr.To("Gateway")),
84-
Namespace: ptr.To(gatewayapi.Namespace(namespacedNameGateway.Namespace)),
85-
Name: gatewayapi.ObjectName(namespacedNameGateway.Name),
86-
}
87-
8879
return gatewayapi.HTTPRouteSpec{
8980
Hostnames: hostnames,
9081
Rules: rules,
@@ -163,14 +154,6 @@ func makeHTTPRouteRule(rule *netv1alpha1.IngressRule) []gatewayapi.HTTPRouteRule
163154
backendRefs = append(backendRefs, backendRef)
164155
}
165156

166-
pathPrefix := "/"
167-
if path.Path != "" {
168-
pathPrefix = path.Path
169-
}
170-
pathMatch := gatewayapi.HTTPPathMatch{
171-
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
172-
Value: ptr.To(pathPrefix),
173-
}
174157
matches := matchesFromRulePath(path)
175158
rule := gatewayapi.HTTPRouteRule{
176159
BackendRefs: backendRefs,
@@ -236,11 +219,11 @@ func makeRedirectHTTPRouteRule(rule *netv1alpha1.IngressRule) []gatewayapi.HTTPR
236219
for _, path := range rule.HTTP.Paths {
237220
preFilters := []gatewayapi.HTTPRouteFilter{
238221
{
239-
Type: gatewayapi.HTTPRouteFilterRequestRedirect,
222+
Type: gatewayapiv1.HTTPRouteFilterRequestRedirect,
240223
RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{
241-
Scheme: ptr("https"),
242-
Port: portNumPtr(443),
243-
StatusCode: ptr(http.StatusMovedPermanently),
224+
Scheme: ptr.To("https"),
225+
Port: ptr.To(gatewayapi.PortNumber(443)),
226+
StatusCode: ptr.To(http.StatusMovedPermanently),
244227
},
245228
}}
246229

@@ -260,24 +243,15 @@ func matchesFromRulePath(path netv1alpha1.HTTPIngressPath) []gatewayapi.HTTPRout
260243
pathPrefix = path.Path
261244
}
262245
pathMatch := gatewayapi.HTTPPathMatch{
263-
Type: ptr(gatewayapi.PathMatchPathPrefix),
246+
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
264247
Value: pointer.String(pathPrefix),
265248
}
266249

267-
var headerMatchList []gatewayapi.HTTPHeaderMatch
268-
for k, v := range path.Headers {
269-
headerMatch := gatewayapi.HTTPHeaderMatch{
270-
Type: ptr.To(gatewayapiv1.HeaderMatchExact),
271-
Name: gatewayapiv1.HTTPHeaderName(k),
272-
Value: v.Exact,
273-
}
274-
headerMatchList = append(headerMatchList, headerMatch)
275-
}
276-
headerMatchList := []gatewayapi.HTTPHeaderMatch{}
250+
var headerMatchList []gatewayapi.HTTPHeaderMatch
277251
for k, v := range path.Headers {
278252
headerMatch := gatewayapi.HTTPHeaderMatch{
279-
Type: ptr(gatewayapi.HeaderMatchExact),
280-
Name: gatewayapi.HTTPHeaderName(k),
253+
Type: ptr.To(gatewayapiv1.HeaderMatchExact),
254+
Name: gatewayapiv1.HTTPHeaderName(k),
281255
Value: v.Exact,
282256
}
283257
headerMatchList = append(headerMatchList, headerMatch)

pkg/reconciler/ingress/resources/httproute_test.go

Lines changed: 30 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,18 @@ import (
2323
"github.com/google/go-cmp/cmp"
2424
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2525
"k8s.io/apimachinery/pkg/util/intstr"
26-
"k8s.io/utils/ptr"
27-
"knative.dev/net-gateway-api/pkg/reconciler/ingress/config"
2826
"k8s.io/utils/pointer"
27+
"k8s.io/utils/ptr"
2928
"knative.dev/networking/pkg/apis/networking"
3029
"knative.dev/networking/pkg/apis/networking/v1alpha1"
3130
"knative.dev/pkg/kmeta"
32-
"knative.dev/pkg/reconciler"
3331
gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1"
3432
gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1"
3533
)
3634

3735
const (
38-
testNamespace = "test-ns"
39-
testIngressName = "test-ingress"
40-
testGatewayClass = "test-class"
36+
testNamespace = "test-ns"
37+
testIngressName = "test-ingress"
4138
)
4239

4340
var (
@@ -57,9 +54,9 @@ var (
5754
gatewayRef = gatewayapi.ParentReference{
5855
Group: (*gatewayapi.Group)(pointer.String("gateway.networking.k8s.io")),
5956
Kind: (*gatewayapi.Kind)(pointer.String("Gateway")),
60-
Namespace: ptr[gatewayapi.Namespace]("test-ns"),
57+
Namespace: ptr.To[gatewayapi.Namespace]("test-ns"),
6158
Name: gatewayapi.ObjectName("foo"),
62-
SectionName: ptr[gatewayapi.SectionName]("http"),
59+
SectionName: ptr.To[gatewayapi.SectionName]("http"),
6360
}
6461
)
6562

@@ -218,7 +215,6 @@ func TestMakeHTTPRoute(t *testing.T) {
218215
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
219216
Value: ptr.To("/"),
220217
},
221-
Headers: HTTPHeaderMatchList{},
222218
},
223219
},
224220
}},
@@ -298,7 +294,6 @@ func TestMakeHTTPRoute(t *testing.T) {
298294
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
299295
Value: ptr.To("/"),
300296
},
301-
Headers: HTTPHeaderMatchList{},
302297
}},
303298
}},
304299
CommonRouteSpec: gatewayapi.CommonRouteSpec{
@@ -476,12 +471,7 @@ func TestMakeHTTPRoute(t *testing.T) {
476471
}}},
477472
},
478473
CommonRouteSpec: gatewayapi.CommonRouteSpec{
479-
ParentRefs: []gatewayapi.ParentReference{{
480-
Group: (*gatewayapi.Group)(ptr.To("gateway.networking.k8s.io")),
481-
Kind: (*gatewayapi.Kind)(ptr.To("Gateway")),
482-
Namespace: ptr.To[gatewayapi.Namespace]("test-ns"),
483-
Name: gatewayapi.ObjectName("foo"),
484-
}},
474+
ParentRefs: []gatewayapi.ParentReference{gatewayRef},
485475
},
486476
},
487477
}},
@@ -566,20 +556,19 @@ func TestMakeRedirectHTTPRoute(t *testing.T) {
566556
Hostnames: []gatewayapi.Hostname{externalHost},
567557
Rules: []gatewayapi.HTTPRouteRule{{
568558
Filters: []gatewayapi.HTTPRouteFilter{{
569-
Type: gatewayapi.HTTPRouteFilterRequestRedirect,
559+
Type: gatewayapiv1.HTTPRouteFilterRequestRedirect,
570560
RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{
571-
Scheme: ptr("https"),
572-
Port: portNumPtr(443),
573-
StatusCode: ptr(http.StatusMovedPermanently),
561+
Scheme: ptr.To("https"),
562+
Port: ptr.To(gatewayapi.PortNumber(443)),
563+
StatusCode: ptr.To(http.StatusMovedPermanently),
574564
},
575565
}},
576566
Matches: []gatewayapi.HTTPRouteMatch{
577567
{
578568
Path: &gatewayapi.HTTPPathMatch{
579-
Type: ptr(gatewayapi.PathMatchPathPrefix),
569+
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
580570
Value: pointer.String("/"),
581571
},
582-
Headers: HTTPHeaderMatchList{},
583572
},
584573
},
585574
}},
@@ -601,19 +590,18 @@ func TestMakeRedirectHTTPRoute(t *testing.T) {
601590
Hostnames: []gatewayapi.Hostname{localHostShortest, localHostShort, localHostFull},
602591
Rules: []gatewayapi.HTTPRouteRule{{
603592
Filters: []gatewayapi.HTTPRouteFilter{{
604-
Type: gatewayapi.HTTPRouteFilterRequestRedirect,
593+
Type: gatewayapiv1.HTTPRouteFilterRequestRedirect,
605594
RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{
606-
Scheme: ptr("https"),
607-
Port: portNumPtr(443),
608-
StatusCode: ptr(http.StatusMovedPermanently),
595+
Scheme: ptr.To("https"),
596+
Port: ptr.To(gatewayapi.PortNumber(443)),
597+
StatusCode: ptr.To(http.StatusMovedPermanently),
609598
},
610599
}},
611600
Matches: []gatewayapi.HTTPRouteMatch{{
612601
Path: &gatewayapi.HTTPPathMatch{
613-
Type: ptr(gatewayapi.PathMatchPathPrefix),
602+
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
614603
Value: pointer.String("/"),
615604
},
616-
Headers: HTTPHeaderMatchList{},
617605
}},
618606
}},
619607
CommonRouteSpec: gatewayapi.CommonRouteSpec{
@@ -682,43 +670,43 @@ func TestMakeRedirectHTTPRoute(t *testing.T) {
682670
Rules: []gatewayapi.HTTPRouteRule{
683671
{
684672
Filters: []gatewayapi.HTTPRouteFilter{{
685-
Type: gatewayapi.HTTPRouteFilterRequestRedirect,
673+
Type: gatewayapiv1.HTTPRouteFilterRequestRedirect,
686674
RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{
687-
Scheme: ptr("https"),
688-
Port: portNumPtr(443),
689-
StatusCode: ptr(http.StatusMovedPermanently),
675+
Scheme: ptr.To("https"),
676+
Port: ptr.To(gatewayapi.PortNumber(443)),
677+
StatusCode: ptr.To(http.StatusMovedPermanently),
690678
},
691679
}},
692680
Matches: []gatewayapi.HTTPRouteMatch{
693681
{
694682
Path: &gatewayapi.HTTPPathMatch{
695-
Type: ptr(gatewayapi.PathMatchPathPrefix),
683+
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
696684
Value: pointer.String("/"),
697685
},
698686
Headers: []gatewayapi.HTTPHeaderMatch{{
699-
Type: ptr(gatewayapi.HeaderMatchExact),
700-
Name: gatewayapi.HTTPHeaderName("tag"),
687+
Type: ptr.To(gatewayapiv1.HeaderMatchExact),
688+
Name: gatewayapiv1.HTTPHeaderName("tag"),
701689
Value: "goo",
702690
}},
703691
}},
704692
}, {
705693
Filters: []gatewayapi.HTTPRouteFilter{{
706-
Type: gatewayapi.HTTPRouteFilterRequestRedirect,
694+
Type: gatewayapiv1.HTTPRouteFilterRequestRedirect,
707695
RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{
708-
Scheme: ptr("https"),
709-
Port: portNumPtr(443),
710-
StatusCode: ptr(http.StatusMovedPermanently),
696+
Scheme: ptr.To("https"),
697+
Port: ptr.To(gatewayapi.PortNumber(443)),
698+
StatusCode: ptr.To(http.StatusMovedPermanently),
711699
},
712700
}},
713701
Matches: []gatewayapi.HTTPRouteMatch{
714702
{
715703
Path: &gatewayapi.HTTPPathMatch{
716-
Type: ptr(gatewayapi.PathMatchPathPrefix),
704+
Type: ptr.To(gatewayapiv1.PathMatchPathPrefix),
717705
Value: pointer.String("/doo"),
718706
},
719707
Headers: []gatewayapi.HTTPHeaderMatch{{
720-
Type: ptr(gatewayapi.HeaderMatchExact),
721-
Name: gatewayapi.HTTPHeaderName("tag"),
708+
Type: ptr.To(gatewayapiv1.HeaderMatchExact),
709+
Name: gatewayapiv1.HTTPHeaderName("tag"),
722710
Value: "doo",
723711
}},
724712
}},

0 commit comments

Comments
 (0)