external-dns/source/gateway_httproute.go
System-Arch 066a11e215
feat(source/gateway-api)!: migrate Gateway and HTTPRoute to v1 (#6291)
* source/gateway-api: Migrate Gateway and HTTPRoute from v1beta1 to v1

This migrates the Kubernetes API interactions for Gateway and HTTPRoute
objects from v1beta1 to v1.

The v1beta1 revert was originally made in PR #4610 (July 2024) because
GKE clusters were not yet serving v1 CRDs. That is no longer the case:
v1 Gateway and HTTPRoute have been available since Gateway API v1.0.0
(October 2023) and all major managed Kubernetes providers now serve them.

This change does NOT modify TLSRoute, TCPRoute, or UDPRoute, which
remain at v1alpha2. TLSRoute's migration to v1 depends on Gateway API
v1.5.0+ and is tracked separately in #6247.

* Updated Gateway API "Supported API Versions" section.

* Document minimum supported Gateway API CRD version

Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>

* Merge branch 'master' into gateway-api-v1

* Revised "Supported API Versions" Gateway API doc.

Incorporated review suggestions from @mloiseleur

* Removed extraneous empty links in import blocks

---------

Co-authored-by: Michel Loiseleur <97035654+mloiseleur@users.noreply.github.com>
2026-04-06 17:47:30 +05:30

67 lines
2.6 KiB
Go

/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package source
import (
"context"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
v1 "sigs.k8s.io/gateway-api/apis/v1"
informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
informers_v1 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1"
)
// NewGatewayHTTPRouteSource creates a new Gateway HTTPRoute source with the given config.
func NewGatewayHTTPRouteSource(ctx context.Context, clients ClientGenerator, config *Config) (Source, error) {
return newGatewayRouteSource(ctx, clients, config, "HTTPRoute", func(factory informers.SharedInformerFactory) gatewayRouteInformer {
return &gatewayHTTPRouteInformer{factory.Gateway().V1().HTTPRoutes()}
})
}
type gatewayHTTPRoute struct{ route v1.HTTPRoute } // NOTE: Must update TypeMeta in List when changing the APIVersion.
func (rt *gatewayHTTPRoute) Object() kubeObject { return &rt.route }
func (rt *gatewayHTTPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
func (rt *gatewayHTTPRoute) Hostnames() []v1.Hostname { return rt.route.Spec.Hostnames }
func (rt *gatewayHTTPRoute) ParentRefs() []v1.ParentReference { return rt.route.Spec.ParentRefs }
func (rt *gatewayHTTPRoute) Protocol() v1.ProtocolType { return v1.HTTPProtocolType }
func (rt *gatewayHTTPRoute) RouteStatus() v1.RouteStatus { return rt.route.Status.RouteStatus }
type gatewayHTTPRouteInformer struct {
informers_v1.HTTPRouteInformer
}
func (inf gatewayHTTPRouteInformer) List(namespace string, selector labels.Selector) ([]gatewayRoute, error) {
list, err := inf.HTTPRouteInformer.Lister().HTTPRoutes(namespace).List(selector)
if err != nil {
return nil, err
}
routes := make([]gatewayRoute, len(list))
for i, rt := range list {
// List results are supposed to be treated as read-only.
// We make a shallow copy since we're only interested in setting the TypeMeta.
clone := *rt
clone.TypeMeta = metav1.TypeMeta{
APIVersion: v1.GroupVersion.String(),
Kind: "HTTPRoute",
}
routes[i] = &gatewayHTTPRoute{clone}
}
return routes, nil
}