diff --git a/docs/test-version.md b/docs/test-version.md index 332530640..26ff5ad42 100644 --- a/docs/test-version.md +++ b/docs/test-version.md @@ -15,5 +15,5 @@ The following Gateway API version and Ingress were tested as part of the release | Ingress | Tested version | Unavailable features | | ------- | ----------------------- | ------------------------------ | -| Istio | v1.20.3 | retry,httpoption,update | -| Contour | v1.28.1 | httpoption,update | +| Istio | v1.20.3 | retry,update | +| Contour | v1.28.1 | update | diff --git a/pkg/reconciler/ingress/ingress.go b/pkg/reconciler/ingress/ingress.go index ea4721c9e..26bfef45d 100644 --- a/pkg/reconciler/ingress/ingress.go +++ b/pkg/reconciler/ingress/ingress.go @@ -103,7 +103,7 @@ func (c *Reconciler) reconcileIngress(ctx context.Context, ing *v1alpha1.Ingress } // For now, we only generate the redirected HTTPRoute for external visibility, - // because currently we do not support HTTPs on cluster-local domains. + // because currently we do not (yet) support HTTPs on cluster-local domains. var redirectHTTPRoute *gatewayapi.HTTPRoute if ing.Spec.HTTPOption == v1alpha1.HTTPOptionRedirected && rule.Visibility == v1alpha1.IngressVisibilityExternalIP { redirectHTTPRoute, err = c.reconcileRedirectHTTPRoute(ctx, ing, &rule) diff --git a/pkg/reconciler/ingress/ingress_test.go b/pkg/reconciler/ingress/ingress_test.go index fbacb157a..6b299aa5e 100644 --- a/pkg/reconciler/ingress/ingress_test.go +++ b/pkg/reconciler/ingress/ingress_test.go @@ -399,20 +399,20 @@ func TestReconcileTLS(t *testing.T) { Name: "TLS ingress with httpOption redirected", Key: "ns/name", Objects: append([]runtime.Object{ - ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(secretName)), + ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS()), secret(secretName, nsName), gw(defaultListener), }, servicesAndEndpoints...), WantCreates: []runtime.Object{ - httpRoute(t, ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(secretName)), withSectionName("kni-")), - httpRedirectRoute(t, ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(secretName)), withSectionName("http")), + httpRoute(t, ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS()), withSectionName("kni-")), + httpRedirectRoute(t, ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS()), withSectionName("http")), rp(secret(secretName, nsName)), }, WantUpdates: []clientgotesting.UpdateActionImpl{{ - Object: gw(defaultListener, tlsListener("secure.example.com", nsName, secretName)), + Object: gw(defaultListener, tlsListener("example.com", nsName, secretName)), }}, WantStatusUpdates: []clientgotesting.UpdateActionImpl{{ - Object: ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(secretName), func(i *v1alpha1.Ingress) { + Object: ing(withBasicSpec, withGatewayAPIClass, withHTTPOptionRedirected, withTLS(), func(i *v1alpha1.Ingress) { // These are the things we expect to change in status. i.Status.InitializeConditions() i.Status.MarkLoadBalancerReady( @@ -540,8 +540,7 @@ func makeItReady(i *v1alpha1.Ingress) { func httpRoute(t *testing.T, i *v1alpha1.Ingress, opts ...HTTPRouteOption) runtime.Object { t.Helper() ingress.InsertProbe(i) - ctx := (&testConfigStore{config: defaultConfig}).ToContext(context.Background()) - httpRoute, _ := resources.MakeHTTPRoute(ctx, i, &i.Spec.Rules[0], gatewayRef) + httpRoute, _ := resources.MakeHTTPRoute(i, &i.Spec.Rules[0], gatewayRef) for _, opt := range opts { opt(httpRoute) } @@ -708,8 +707,8 @@ func rp(to *corev1.Secret) *gatewayapi.ReferenceGrant { Namespace: gatewayapi.Namespace(testNamespace), }}, To: []gatewayapi.ReferenceGrantTo{{ - Group: gatewayapi.Group(""), - Kind: gatewayapi.Kind("Secret"), + Group: "", + Kind: "Secret", Name: (*gatewayapi.ObjectName)(&to.Name), }}, }, diff --git a/pkg/reconciler/ingress/reconcile_resources.go b/pkg/reconciler/ingress/reconcile_resources.go index 9bc272206..a7c7e9c64 100644 --- a/pkg/reconciler/ingress/reconcile_resources.go +++ b/pkg/reconciler/ingress/reconcile_resources.go @@ -25,6 +25,7 @@ import ( apierrs "k8s.io/apimachinery/pkg/api/errors" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" + "k8s.io/utils/pointer" "k8s.io/utils/ptr" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1" @@ -42,7 +43,6 @@ func (c *Reconciler) reconcileWorkloadRoute( ctx context.Context, ing *netv1alpha1.Ingress, rule *netv1alpha1.IngressRule, ) (*gatewayapi.HTTPRoute, error) { - gatewayConfig := config.FromContext(ctx).Gateway.Gateways[rule.Visibility] gatewayRef := gatewayapi.ParentReference{ Group: (*gatewayapi.Group)(&gatewayapi.GroupVersion.Group), @@ -102,26 +102,25 @@ func (c *Reconciler) reconcileHTTPRoute(ctx context.Context, recorder := controller.GetEventRecorder(ctx) - httproute, err := c.httprouteLister.HTTPRoutes(ing.Namespace).Get(desired.Name) + httpRoute, err := c.httprouteLister.HTTPRoutes(ing.Namespace).Get(desired.Name) if apierrs.IsNotFound(err) { - - httproute, err = c.gwapiclient.GatewayV1beta1().HTTPRoutes(desired.Namespace).Create(ctx, desired, metav1.CreateOptions{}) + httpRoute, err = c.gwapiclient.GatewayV1beta1().HTTPRoutes(desired.Namespace).Create(ctx, desired, metav1.CreateOptions{}) if err != nil { recorder.Eventf(ing, corev1.EventTypeWarning, "CreationFailed", "Failed to create HTTPRoute: %v", err) return nil, fmt.Errorf("failed to create HTTPRoute: %w", err) } - recorder.Eventf(ing, corev1.EventTypeNormal, "Created", "Created HTTPRoute %q", httproute.GetName()) - return httproute, nil + recorder.Eventf(ing, corev1.EventTypeNormal, "Created", "Created HTTPRoute %q", httpRoute.GetName()) + return httpRoute, nil } else if err != nil { return nil, err } else { - if !equality.Semantic.DeepEqual(httproute.Spec, desired.Spec) || - !equality.Semantic.DeepEqual(httproute.Annotations, desired.Annotations) || - !equality.Semantic.DeepEqual(httproute.Labels, desired.Labels) { + if !equality.Semantic.DeepEqual(httpRoute.Spec, desired.Spec) || + !equality.Semantic.DeepEqual(httpRoute.Annotations, desired.Annotations) || + !equality.Semantic.DeepEqual(httpRoute.Labels, desired.Labels) { // Don't modify the informers copy. - origin := httproute.DeepCopy() + origin := httpRoute.DeepCopy() origin.Spec = desired.Spec origin.Annotations = desired.Annotations origin.Labels = desired.Labels @@ -136,7 +135,7 @@ func (c *Reconciler) reconcileHTTPRoute(ctx context.Context, } } - return httproute, err + return httpRoute, err } func (c *Reconciler) reconcileTLS( diff --git a/pkg/reconciler/ingress/resources/httproute.go b/pkg/reconciler/ingress/resources/httproute.go index 4fbc9fd73..b81c16299 100644 --- a/pkg/reconciler/ingress/resources/httproute.go +++ b/pkg/reconciler/ingress/resources/httproute.go @@ -20,6 +20,7 @@ import ( "net/http" "sort" + "k8s.io/utils/pointer" "knative.dev/pkg/kmap" corev1 "k8s.io/api/core/v1" @@ -75,16 +76,6 @@ func makeHTTPRouteSpec( rules := makeHTTPRouteRule(rule) - gatewayConfig := config.FromContext(ctx).Gateway - namespacedNameGateway := gatewayConfig.Gateways[rule.Visibility].Gateway - - gatewayRef := gatewayapi.ParentReference{ - Group: (*gatewayapi.Group)(&gatewayapi.GroupVersion.Group), - Kind: (*gatewayapi.Kind)(ptr.To("Gateway")), - Namespace: ptr.To(gatewayapi.Namespace(namespacedNameGateway.Namespace)), - Name: gatewayapi.ObjectName(namespacedNameGateway.Name), - } - return gatewayapi.HTTPRouteSpec{ Hostnames: hostnames, Rules: rules, @@ -163,14 +154,6 @@ func makeHTTPRouteRule(rule *netv1alpha1.IngressRule) []gatewayapi.HTTPRouteRule backendRefs = append(backendRefs, backendRef) } - pathPrefix := "/" - if path.Path != "" { - pathPrefix = path.Path - } - pathMatch := gatewayapi.HTTPPathMatch{ - Type: ptr.To(gatewayapiv1.PathMatchPathPrefix), - Value: ptr.To(pathPrefix), - } matches := matchesFromRulePath(path) rule := gatewayapi.HTTPRouteRule{ BackendRefs: backendRefs, @@ -236,11 +219,11 @@ func makeRedirectHTTPRouteRule(rule *netv1alpha1.IngressRule) []gatewayapi.HTTPR for _, path := range rule.HTTP.Paths { preFilters := []gatewayapi.HTTPRouteFilter{ { - Type: gatewayapi.HTTPRouteFilterRequestRedirect, + Type: gatewayapiv1.HTTPRouteFilterRequestRedirect, RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{ - Scheme: ptr("https"), - Port: portNumPtr(443), - StatusCode: ptr(http.StatusMovedPermanently), + Scheme: ptr.To("https"), + Port: ptr.To(gatewayapi.PortNumber(443)), + StatusCode: ptr.To(http.StatusMovedPermanently), }, }} @@ -260,24 +243,15 @@ func matchesFromRulePath(path netv1alpha1.HTTPIngressPath) []gatewayapi.HTTPRout pathPrefix = path.Path } pathMatch := gatewayapi.HTTPPathMatch{ - Type: ptr(gatewayapi.PathMatchPathPrefix), + Type: ptr.To(gatewayapiv1.PathMatchPathPrefix), Value: pointer.String(pathPrefix), } - var headerMatchList []gatewayapi.HTTPHeaderMatch - for k, v := range path.Headers { - headerMatch := gatewayapi.HTTPHeaderMatch{ - Type: ptr.To(gatewayapiv1.HeaderMatchExact), - Name: gatewayapiv1.HTTPHeaderName(k), - Value: v.Exact, - } - headerMatchList = append(headerMatchList, headerMatch) - } - headerMatchList := []gatewayapi.HTTPHeaderMatch{} + var headerMatchList []gatewayapi.HTTPHeaderMatch for k, v := range path.Headers { headerMatch := gatewayapi.HTTPHeaderMatch{ - Type: ptr(gatewayapi.HeaderMatchExact), - Name: gatewayapi.HTTPHeaderName(k), + Type: ptr.To(gatewayapiv1.HeaderMatchExact), + Name: gatewayapiv1.HTTPHeaderName(k), Value: v.Exact, } headerMatchList = append(headerMatchList, headerMatch) diff --git a/pkg/reconciler/ingress/resources/httproute_test.go b/pkg/reconciler/ingress/resources/httproute_test.go index e3786fbca..1dd259573 100644 --- a/pkg/reconciler/ingress/resources/httproute_test.go +++ b/pkg/reconciler/ingress/resources/httproute_test.go @@ -23,21 +23,18 @@ import ( "github.com/google/go-cmp/cmp" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/utils/ptr" - "knative.dev/net-gateway-api/pkg/reconciler/ingress/config" "k8s.io/utils/pointer" + "k8s.io/utils/ptr" "knative.dev/networking/pkg/apis/networking" "knative.dev/networking/pkg/apis/networking/v1alpha1" "knative.dev/pkg/kmeta" - "knative.dev/pkg/reconciler" gatewayapiv1 "sigs.k8s.io/gateway-api/apis/v1" gatewayapi "sigs.k8s.io/gateway-api/apis/v1beta1" ) const ( - testNamespace = "test-ns" - testIngressName = "test-ingress" - testGatewayClass = "test-class" + testNamespace = "test-ns" + testIngressName = "test-ingress" ) var ( @@ -57,9 +54,9 @@ var ( gatewayRef = gatewayapi.ParentReference{ Group: (*gatewayapi.Group)(pointer.String("gateway.networking.k8s.io")), Kind: (*gatewayapi.Kind)(pointer.String("Gateway")), - Namespace: ptr[gatewayapi.Namespace]("test-ns"), + Namespace: ptr.To[gatewayapi.Namespace]("test-ns"), Name: gatewayapi.ObjectName("foo"), - SectionName: ptr[gatewayapi.SectionName]("http"), + SectionName: ptr.To[gatewayapi.SectionName]("http"), } ) @@ -218,7 +215,6 @@ func TestMakeHTTPRoute(t *testing.T) { Type: ptr.To(gatewayapiv1.PathMatchPathPrefix), Value: ptr.To("/"), }, - Headers: HTTPHeaderMatchList{}, }, }, }}, @@ -298,7 +294,6 @@ func TestMakeHTTPRoute(t *testing.T) { Type: ptr.To(gatewayapiv1.PathMatchPathPrefix), Value: ptr.To("/"), }, - Headers: HTTPHeaderMatchList{}, }}, }}, CommonRouteSpec: gatewayapi.CommonRouteSpec{ @@ -476,12 +471,7 @@ func TestMakeHTTPRoute(t *testing.T) { }}}, }, CommonRouteSpec: gatewayapi.CommonRouteSpec{ - ParentRefs: []gatewayapi.ParentReference{{ - Group: (*gatewayapi.Group)(ptr.To("gateway.networking.k8s.io")), - Kind: (*gatewayapi.Kind)(ptr.To("Gateway")), - Namespace: ptr.To[gatewayapi.Namespace]("test-ns"), - Name: gatewayapi.ObjectName("foo"), - }}, + ParentRefs: []gatewayapi.ParentReference{gatewayRef}, }, }, }}, @@ -566,20 +556,19 @@ func TestMakeRedirectHTTPRoute(t *testing.T) { Hostnames: []gatewayapi.Hostname{externalHost}, Rules: []gatewayapi.HTTPRouteRule{{ Filters: []gatewayapi.HTTPRouteFilter{{ - Type: gatewayapi.HTTPRouteFilterRequestRedirect, + Type: gatewayapiv1.HTTPRouteFilterRequestRedirect, RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{ - Scheme: ptr("https"), - Port: portNumPtr(443), - StatusCode: ptr(http.StatusMovedPermanently), + Scheme: ptr.To("https"), + Port: ptr.To(gatewayapi.PortNumber(443)), + StatusCode: ptr.To(http.StatusMovedPermanently), }, }}, Matches: []gatewayapi.HTTPRouteMatch{ { Path: &gatewayapi.HTTPPathMatch{ - Type: ptr(gatewayapi.PathMatchPathPrefix), + Type: ptr.To(gatewayapiv1.PathMatchPathPrefix), Value: pointer.String("/"), }, - Headers: HTTPHeaderMatchList{}, }, }, }}, @@ -601,19 +590,18 @@ func TestMakeRedirectHTTPRoute(t *testing.T) { Hostnames: []gatewayapi.Hostname{localHostShortest, localHostShort, localHostFull}, Rules: []gatewayapi.HTTPRouteRule{{ Filters: []gatewayapi.HTTPRouteFilter{{ - Type: gatewayapi.HTTPRouteFilterRequestRedirect, + Type: gatewayapiv1.HTTPRouteFilterRequestRedirect, RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{ - Scheme: ptr("https"), - Port: portNumPtr(443), - StatusCode: ptr(http.StatusMovedPermanently), + Scheme: ptr.To("https"), + Port: ptr.To(gatewayapi.PortNumber(443)), + StatusCode: ptr.To(http.StatusMovedPermanently), }, }}, Matches: []gatewayapi.HTTPRouteMatch{{ Path: &gatewayapi.HTTPPathMatch{ - Type: ptr(gatewayapi.PathMatchPathPrefix), + Type: ptr.To(gatewayapiv1.PathMatchPathPrefix), Value: pointer.String("/"), }, - Headers: HTTPHeaderMatchList{}, }}, }}, CommonRouteSpec: gatewayapi.CommonRouteSpec{ @@ -682,43 +670,43 @@ func TestMakeRedirectHTTPRoute(t *testing.T) { Rules: []gatewayapi.HTTPRouteRule{ { Filters: []gatewayapi.HTTPRouteFilter{{ - Type: gatewayapi.HTTPRouteFilterRequestRedirect, + Type: gatewayapiv1.HTTPRouteFilterRequestRedirect, RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{ - Scheme: ptr("https"), - Port: portNumPtr(443), - StatusCode: ptr(http.StatusMovedPermanently), + Scheme: ptr.To("https"), + Port: ptr.To(gatewayapi.PortNumber(443)), + StatusCode: ptr.To(http.StatusMovedPermanently), }, }}, Matches: []gatewayapi.HTTPRouteMatch{ { Path: &gatewayapi.HTTPPathMatch{ - Type: ptr(gatewayapi.PathMatchPathPrefix), + Type: ptr.To(gatewayapiv1.PathMatchPathPrefix), Value: pointer.String("/"), }, Headers: []gatewayapi.HTTPHeaderMatch{{ - Type: ptr(gatewayapi.HeaderMatchExact), - Name: gatewayapi.HTTPHeaderName("tag"), + Type: ptr.To(gatewayapiv1.HeaderMatchExact), + Name: gatewayapiv1.HTTPHeaderName("tag"), Value: "goo", }}, }}, }, { Filters: []gatewayapi.HTTPRouteFilter{{ - Type: gatewayapi.HTTPRouteFilterRequestRedirect, + Type: gatewayapiv1.HTTPRouteFilterRequestRedirect, RequestRedirect: &gatewayapi.HTTPRequestRedirectFilter{ - Scheme: ptr("https"), - Port: portNumPtr(443), - StatusCode: ptr(http.StatusMovedPermanently), + Scheme: ptr.To("https"), + Port: ptr.To(gatewayapi.PortNumber(443)), + StatusCode: ptr.To(http.StatusMovedPermanently), }, }}, Matches: []gatewayapi.HTTPRouteMatch{ { Path: &gatewayapi.HTTPPathMatch{ - Type: ptr(gatewayapi.PathMatchPathPrefix), + Type: ptr.To(gatewayapiv1.PathMatchPathPrefix), Value: pointer.String("/doo"), }, Headers: []gatewayapi.HTTPHeaderMatch{{ - Type: ptr(gatewayapi.HeaderMatchExact), - Name: gatewayapi.HTTPHeaderName("tag"), + Type: ptr.To(gatewayapiv1.HeaderMatchExact), + Name: gatewayapiv1.HTTPHeaderName("tag"), Value: "doo", }}, }},