Skip to content

Commit

Permalink
Merge pull request #4610 from abursavich/gateway-api
Browse files Browse the repository at this point in the history
Gateway API: Revert Gateway and HTTPRoute objects from v1 to v1beta1
  • Loading branch information
k8s-ci-robot authored Jul 27, 2024
2 parents e62d854 + 2daa842 commit 4da484b
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 83 deletions.
23 changes: 19 additions & 4 deletions docs/tutorials/gateway-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,25 @@ It is meant to supplement the other provider-specific setup tutorials.

## Supported API Versions

As the Gateway API is still in an experimental phase, ExternalDNS makes no backwards
compatibilty guarantees regarding its support. However, it currently supports a mixture of
v1alpha2, v1beta1, v1 APIs. Gateways and HTTPRoutes are supported using the v1 and v1beta1 API (which is converted to v1 when using the latest CRDs).
GRPCRoutes, TLSRoutes, TCPRoutes, and UDPRoutes are supported using the v1alpha2 API.
ExternalDNS currently supports a mixture of v1alpha2, v1beta1, v1 APIs.

Gateway API has two release channels: Standard and Experimental.
The Experimental channel includes v1alpha2, v1beta2, and v1 APIs.
The Standard channel only includes v1beta2 and v1 APIs, not v1alpha2.

TCPRoutes, TLSRoutes, and UDPRoutes only exist in v1alpha2 and continued support for
these versions is NOT guaranteed. At some time in the future, Gateway API will graduate
these Routes to v1. ExternalDNS will likely follow that upgrade and move to the v1 API,
where they will be available in the Standard release channel. This will be a breaking
change if your Experimental CRDs are not updated to include the new v1 API.

Gateways and HTTPRoutes are available in v1alpha2, v1beta1, and v1 APIs.
However, some notable environments are behind in upgrading their CRDs to include the v1 API.
For compatibility reasons Gateways and HTTPRoutes use the v1beta1 API.

GRPCRoutes are available in v1alpha2 and v1 APIs, not v1beta2.
Therefore, GRPCRoutes use the v1 API which is available in both release channels.
Unfortunately, this means they will not be available in environments with old CRDs.

## Hostnames

Expand Down
15 changes: 8 additions & 7 deletions source/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@ import (
coreinformers "k8s.io/client-go/informers/core/v1"
cache "k8s.io/client-go/tools/cache"
v1 "sigs.k8s.io/gateway-api/apis/v1"
v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gateway "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned"
informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
informers_v1 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1"
informers_v1beta1 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1beta1"

"sigs.k8s.io/external-dns/endpoint"
)
Expand Down Expand Up @@ -83,7 +84,7 @@ func newGatewayInformerFactory(client gateway.Interface, namespace string, label
type gatewayRouteSource struct {
gwNamespace string
gwLabels labels.Selector
gwInformer informers_v1.GatewayInformer
gwInformer informers_v1beta1.GatewayInformer

rtKind string
rtNamespace string
Expand Down Expand Up @@ -124,8 +125,8 @@ func newGatewayRouteSource(clients ClientGenerator, config *Config, kind string,
}

informerFactory := newGatewayInformerFactory(client, config.GatewayNamespace, gwLabels)
gwInformer := informerFactory.Gateway().V1().Gateways() // TODO: Gateway informer should be shared across gateway sources.
gwInformer.Informer() // Register with factory before starting.
gwInformer := informerFactory.Gateway().V1beta1().Gateways() // TODO: Gateway informer should be shared across gateway sources.
gwInformer.Informer() // Register with factory before starting.

rtInformerFactory := informerFactory
if config.Namespace != config.GatewayNamespace || !selectorsEqual(rtLabels, gwLabels) {
Expand Down Expand Up @@ -251,11 +252,11 @@ type gatewayRouteResolver struct {
}

type gatewayListeners struct {
gateway *v1.Gateway
gateway *v1beta1.Gateway
listeners map[v1.SectionName][]v1.Listener
}

func newGatewayRouteResolver(src *gatewayRouteSource, gateways []*v1.Gateway, namespaces []*corev1.Namespace) *gatewayRouteResolver {
func newGatewayRouteResolver(src *gatewayRouteSource, gateways []*v1beta1.Gateway, namespaces []*corev1.Namespace) *gatewayRouteResolver {
// Create Gateway Listener lookup table.
gws := make(map[types.NamespacedName]gatewayListeners, len(gateways))
for _, gw := range gateways {
Expand Down Expand Up @@ -395,7 +396,7 @@ func (c *gatewayRouteResolver) hosts(rt gatewayRoute) ([]string, error) {
return hostnames, nil
}

func (c *gatewayRouteResolver) routeIsAllowed(gw *v1.Gateway, lis *v1.Listener, rt gatewayRoute) bool {
func (c *gatewayRouteResolver) routeIsAllowed(gw *v1beta1.Gateway, lis *v1.Listener, rt gatewayRoute) bool {
meta := rt.Metadata()
allow := lis.AllowedRoutes

Expand Down
5 changes: 3 additions & 2 deletions source/gateway_grpcroute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
kubefake "k8s.io/client-go/kubernetes/fake"
"sigs.k8s.io/external-dns/endpoint"
v1 "sigs.k8s.io/gateway-api/apis/v1"
v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
)

Expand All @@ -48,7 +49,7 @@ func TestGatewayGRPCRouteSourceEndpoints(t *testing.T) {
require.NoError(t, err, "failed to create Namespace")

ips := []string{"10.64.0.1", "10.64.0.2"}
gw := &v1.Gateway{
gw := &v1beta1.Gateway{
ObjectMeta: metav1.ObjectMeta{
Name: "internal",
Namespace: "default",
Expand All @@ -60,7 +61,7 @@ func TestGatewayGRPCRouteSourceEndpoints(t *testing.T) {
},
Status: gatewayStatus(ips...),
}
_, err = gwClient.GatewayV1().Gateways(gw.Namespace).Create(ctx, gw, metav1.CreateOptions{})
_, err = gwClient.GatewayV1beta1().Gateways(gw.Namespace).Create(ctx, gw, metav1.CreateOptions{})
require.NoError(t, err, "failed to create Gateway")

rt := &v1.GRPCRoute{
Expand Down
11 changes: 6 additions & 5 deletions source/gateway_httproute.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/labels"
v1 "sigs.k8s.io/gateway-api/apis/v1"
v1beta1 "sigs.k8s.io/gateway-api/apis/v1beta1"
informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
informers_v1 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1"
informers_v1beta1 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1beta1"
)

// NewGatewayHTTPRouteSource creates a new Gateway HTTPRoute source with the given config.
func NewGatewayHTTPRouteSource(clients ClientGenerator, config *Config) (Source, error) {
return newGatewayRouteSource(clients, config, "HTTPRoute", func(factory informers.SharedInformerFactory) gatewayRouteInformer {
return &gatewayHTTPRouteInformer{factory.Gateway().V1().HTTPRoutes()}
return &gatewayHTTPRouteInformer{factory.Gateway().V1beta1().HTTPRoutes()}
})
}

Expand All @@ -40,7 +41,7 @@ func (rt *gatewayHTTPRoute) Protocol() v1.ProtocolType { return v1.HTTPProtoc
func (rt *gatewayHTTPRoute) RouteStatus() v1.RouteStatus { return rt.route.Status.RouteStatus }

type gatewayHTTPRouteInformer struct {
informers_v1.HTTPRouteInformer
informers_v1beta1.HTTPRouteInformer
}

func (inf gatewayHTTPRouteInformer) List(namespace string, selector labels.Selector) ([]gatewayRoute, error) {
Expand All @@ -54,10 +55,10 @@ func (inf gatewayHTTPRouteInformer) List(namespace string, selector labels.Selec
// We make a shallow copy since we're only interested in setting the TypeMeta.
clone := *rt
clone.TypeMeta = metav1.TypeMeta{
APIVersion: v1.GroupVersion.String(),
APIVersion: v1beta1.GroupVersion.String(),
Kind: "HTTPRoute",
}
routes[i] = &gatewayHTTPRoute{clone}
routes[i] = &gatewayHTTPRoute{v1.HTTPRoute(clone)}
}
return routes, nil
}
Loading

0 comments on commit 4da484b

Please sign in to comment.