mirror of
https://github.com/kubernetes-sigs/external-dns.git
synced 2025-08-05 17:16:59 +02:00
gateway-api: switch to v1beta1 apis where available
This commit is contained in:
parent
a7a56b9380
commit
b0dc1739aa
@ -5,9 +5,10 @@ It is meant to supplement the other provider-specific setup tutorials.
|
||||
|
||||
## Supported API Versions
|
||||
|
||||
The currently supported version of Gateway API is v1alpha2. However, the maintainers of ExternalDNS
|
||||
make no backwards compatibility guarantees with alpha versions of the API. Future releases may only
|
||||
support beta or stable 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 and v1beta1 APIs. Gateways and HTTPRoutes are supported using the v1beta1 API.
|
||||
TLSRoutes, TCPRoutes, and UDPRoutes are supported using the v1alpha2 API.
|
||||
|
||||
## Hostnames
|
||||
|
||||
|
@ -32,10 +32,10 @@ import (
|
||||
kubeinformers "k8s.io/client-go/informers"
|
||||
coreinformers "k8s.io/client-go/informers/core/v1"
|
||||
cache "k8s.io/client-go/tools/cache"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"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_v1a2 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1alpha2"
|
||||
informers_v1b1 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1beta1"
|
||||
|
||||
"sigs.k8s.io/external-dns/endpoint"
|
||||
)
|
||||
@ -51,11 +51,11 @@ type gatewayRoute interface {
|
||||
// Metadata returns the route's metadata.
|
||||
Metadata() *metav1.ObjectMeta
|
||||
// Hostnames returns the route's specified hostnames.
|
||||
Hostnames() []v1alpha2.Hostname
|
||||
Hostnames() []v1beta1.Hostname
|
||||
// Protocol returns the route's protocol type.
|
||||
Protocol() v1alpha2.ProtocolType
|
||||
Protocol() v1beta1.ProtocolType
|
||||
// RouteStatus returns the route's common status.
|
||||
RouteStatus() v1alpha2.RouteStatus
|
||||
RouteStatus() v1beta1.RouteStatus
|
||||
}
|
||||
|
||||
type newGatewayRouteInformerFunc func(informers.SharedInformerFactory) gatewayRouteInformer
|
||||
@ -82,7 +82,7 @@ func newGatewayInformerFactory(client gateway.Interface, namespace string, label
|
||||
type gatewayRouteSource struct {
|
||||
gwNamespace string
|
||||
gwLabels labels.Selector
|
||||
gwInformer informers_v1a2.GatewayInformer
|
||||
gwInformer informers_v1b1.GatewayInformer
|
||||
|
||||
rtKind string
|
||||
rtNamespace string
|
||||
@ -123,8 +123,8 @@ func newGatewayRouteSource(clients ClientGenerator, config *Config, kind string,
|
||||
}
|
||||
|
||||
informerFactory := newGatewayInformerFactory(client, config.GatewayNamespace, gwLabels)
|
||||
gwInformer := informerFactory.Gateway().V1alpha2().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) {
|
||||
@ -257,15 +257,15 @@ type gatewayRouteResolver struct {
|
||||
}
|
||||
|
||||
type gatewayListeners struct {
|
||||
gateway *v1alpha2.Gateway
|
||||
listeners map[v1alpha2.SectionName][]v1alpha2.Listener
|
||||
gateway *v1beta1.Gateway
|
||||
listeners map[v1beta1.SectionName][]v1beta1.Listener
|
||||
}
|
||||
|
||||
func newGatewayRouteResolver(src *gatewayRouteSource, gateways []*v1alpha2.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 {
|
||||
lss := make(map[v1alpha2.SectionName][]v1alpha2.Listener, len(gw.Spec.Listeners)+1)
|
||||
lss := make(map[v1beta1.SectionName][]v1beta1.Listener, len(gw.Spec.Listeners)+1)
|
||||
for i, lis := range gw.Spec.Listeners {
|
||||
lss[lis.Name] = gw.Spec.Listeners[i : i+1]
|
||||
}
|
||||
@ -397,23 +397,23 @@ func (c *gatewayRouteResolver) hosts(rt gatewayRoute) ([]string, error) {
|
||||
return hostnames, nil
|
||||
}
|
||||
|
||||
func (c *gatewayRouteResolver) routeIsAllowed(gw *v1alpha2.Gateway, lis *v1alpha2.Listener, rt gatewayRoute) bool {
|
||||
func (c *gatewayRouteResolver) routeIsAllowed(gw *v1beta1.Gateway, lis *v1beta1.Listener, rt gatewayRoute) bool {
|
||||
meta := rt.Metadata()
|
||||
allow := lis.AllowedRoutes
|
||||
|
||||
// Check the route's namespace.
|
||||
from := v1alpha2.NamespacesFromSame
|
||||
from := v1beta1.NamespacesFromSame
|
||||
if allow != nil && allow.Namespaces != nil && allow.Namespaces.From != nil {
|
||||
from = *allow.Namespaces.From
|
||||
}
|
||||
switch from {
|
||||
case v1alpha2.NamespacesFromAll:
|
||||
case v1beta1.NamespacesFromAll:
|
||||
// OK
|
||||
case v1alpha2.NamespacesFromSame:
|
||||
case v1beta1.NamespacesFromSame:
|
||||
if gw.Namespace != meta.Namespace {
|
||||
return false
|
||||
}
|
||||
case v1alpha2.NamespacesFromSelector:
|
||||
case v1beta1.NamespacesFromSelector:
|
||||
selector, err := metav1.LabelSelectorAsSelector(allow.Namespaces.Selector)
|
||||
if err != nil {
|
||||
log.Debugf("Gateway %s/%s section %q has invalid namespace selector: %v", gw.Namespace, gw.Name, lis.Name, err)
|
||||
@ -451,7 +451,7 @@ func (c *gatewayRouteResolver) routeIsAllowed(gw *v1alpha2.Gateway, lis *v1alpha
|
||||
|
||||
func gwRouteIsAccepted(conds []metav1.Condition) bool {
|
||||
for _, c := range conds {
|
||||
if v1alpha2.RouteConditionType(c.Type) == v1alpha2.RouteConditionAccepted {
|
||||
if v1beta1.RouteConditionType(c.Type) == v1beta1.RouteConditionAccepted {
|
||||
return c.Status == metav1.ConditionTrue
|
||||
}
|
||||
}
|
||||
@ -478,12 +478,12 @@ func uniqueTargets(targets endpoint.Targets) endpoint.Targets {
|
||||
|
||||
// gwProtocolMatches returns whether a and b are the same protocol,
|
||||
// where HTTP and HTTPS are considered the same.
|
||||
func gwProtocolMatches(a, b v1alpha2.ProtocolType) bool {
|
||||
if a == v1alpha2.HTTPSProtocolType {
|
||||
a = v1alpha2.HTTPProtocolType
|
||||
func gwProtocolMatches(a, b v1beta1.ProtocolType) bool {
|
||||
if a == v1beta1.HTTPSProtocolType {
|
||||
a = v1beta1.HTTPProtocolType
|
||||
}
|
||||
if b == v1alpha2.HTTPSProtocolType {
|
||||
b = v1alpha2.HTTPProtocolType
|
||||
if b == v1beta1.HTTPSProtocolType {
|
||||
b = v1beta1.HTTPProtocolType
|
||||
}
|
||||
return a == b
|
||||
}
|
||||
@ -531,7 +531,7 @@ func strVal(ptr *string, def string) string {
|
||||
return *ptr
|
||||
}
|
||||
|
||||
func sectionVal(ptr *v1alpha2.SectionName, def v1alpha2.SectionName) v1alpha2.SectionName {
|
||||
func sectionVal(ptr *v1beta1.SectionName, def v1beta1.SectionName) v1beta1.SectionName {
|
||||
if ptr == nil || *ptr == "" {
|
||||
return def
|
||||
}
|
||||
|
@ -19,28 +19,28 @@ package source
|
||||
import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||
informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
|
||||
informers_v1a2 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1alpha2"
|
||||
informers_v1b1 "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().V1alpha2().HTTPRoutes()}
|
||||
return &gatewayHTTPRouteInformer{factory.Gateway().V1beta1().HTTPRoutes()}
|
||||
})
|
||||
}
|
||||
|
||||
type gatewayHTTPRoute struct{ route *v1alpha2.HTTPRoute }
|
||||
type gatewayHTTPRoute struct{ route *v1beta1.HTTPRoute }
|
||||
|
||||
func (rt *gatewayHTTPRoute) Object() kubeObject { return rt.route }
|
||||
func (rt *gatewayHTTPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
|
||||
func (rt *gatewayHTTPRoute) Hostnames() []v1alpha2.Hostname { return rt.route.Spec.Hostnames }
|
||||
func (rt *gatewayHTTPRoute) Protocol() v1alpha2.ProtocolType { return v1alpha2.HTTPProtocolType }
|
||||
func (rt *gatewayHTTPRoute) RouteStatus() v1alpha2.RouteStatus { return rt.route.Status.RouteStatus }
|
||||
func (rt *gatewayHTTPRoute) Object() kubeObject { return rt.route }
|
||||
func (rt *gatewayHTTPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
|
||||
func (rt *gatewayHTTPRoute) Hostnames() []v1beta1.Hostname { return rt.route.Spec.Hostnames }
|
||||
func (rt *gatewayHTTPRoute) Protocol() v1beta1.ProtocolType { return v1beta1.HTTPProtocolType }
|
||||
func (rt *gatewayHTTPRoute) RouteStatus() v1beta1.RouteStatus { return rt.route.Status.RouteStatus }
|
||||
|
||||
type gatewayHTTPRouteInformer struct {
|
||||
informers_v1a2.HTTPRouteInformer
|
||||
informers_v1b1.HTTPRouteInformer
|
||||
}
|
||||
|
||||
func (inf gatewayHTTPRouteInformer) List(namespace string, selector labels.Selector) ([]gatewayRoute, error) {
|
||||
|
@ -26,7 +26,7 @@ import (
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
kubefake "k8s.io/client-go/kubernetes/fake"
|
||||
"sigs.k8s.io/external-dns/endpoint"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||
gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
|
||||
)
|
||||
|
||||
@ -38,23 +38,23 @@ func mustGetLabelSelector(s string) labels.Selector {
|
||||
return v
|
||||
}
|
||||
|
||||
func gatewayStatus(ips ...string) v1alpha2.GatewayStatus {
|
||||
typ := v1alpha2.IPAddressType
|
||||
addrs := make([]v1alpha2.GatewayAddress, len(ips))
|
||||
func gatewayStatus(ips ...string) v1beta1.GatewayStatus {
|
||||
typ := v1beta1.IPAddressType
|
||||
addrs := make([]v1beta1.GatewayAddress, len(ips))
|
||||
for i, ip := range ips {
|
||||
addrs[i] = v1alpha2.GatewayAddress{Type: &typ, Value: ip}
|
||||
addrs[i] = v1beta1.GatewayAddress{Type: &typ, Value: ip}
|
||||
}
|
||||
return v1alpha2.GatewayStatus{Addresses: addrs}
|
||||
return v1beta1.GatewayStatus{Addresses: addrs}
|
||||
}
|
||||
|
||||
func routeStatus(refs ...v1alpha2.ParentReference) v1alpha2.RouteStatus {
|
||||
var v v1alpha2.RouteStatus
|
||||
func routeStatus(refs ...v1beta1.ParentReference) v1beta1.RouteStatus {
|
||||
var v v1beta1.RouteStatus
|
||||
for _, ref := range refs {
|
||||
v.Parents = append(v.Parents, v1alpha2.RouteParentStatus{
|
||||
v.Parents = append(v.Parents, v1beta1.RouteParentStatus{
|
||||
ParentRef: ref,
|
||||
Conditions: []metav1.Condition{
|
||||
{
|
||||
Type: string(v1alpha2.RouteConditionAccepted),
|
||||
Type: string(v1beta1.RouteConditionAccepted),
|
||||
Status: metav1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
@ -63,28 +63,28 @@ func routeStatus(refs ...v1alpha2.ParentReference) v1alpha2.RouteStatus {
|
||||
return v
|
||||
}
|
||||
|
||||
func httpRouteStatus(refs ...v1alpha2.ParentReference) v1alpha2.HTTPRouteStatus {
|
||||
return v1alpha2.HTTPRouteStatus{RouteStatus: routeStatus(refs...)}
|
||||
func httpRouteStatus(refs ...v1beta1.ParentReference) v1beta1.HTTPRouteStatus {
|
||||
return v1beta1.HTTPRouteStatus{RouteStatus: routeStatus(refs...)}
|
||||
}
|
||||
|
||||
type parentRefOption func(*v1alpha2.ParentReference)
|
||||
type parentRefOption func(*v1beta1.ParentReference)
|
||||
|
||||
func withSectionName(name v1alpha2.SectionName) parentRefOption {
|
||||
return func(ref *v1alpha2.ParentReference) { ref.SectionName = &name }
|
||||
func withSectionName(name v1beta1.SectionName) parentRefOption {
|
||||
return func(ref *v1beta1.ParentReference) { ref.SectionName = &name }
|
||||
}
|
||||
|
||||
func withPortNumber(port v1alpha2.PortNumber) parentRefOption {
|
||||
return func(ref *v1alpha2.ParentReference) { ref.Port = &port }
|
||||
func withPortNumber(port v1beta1.PortNumber) parentRefOption {
|
||||
return func(ref *v1beta1.ParentReference) { ref.Port = &port }
|
||||
}
|
||||
|
||||
func gatewayParentRef(namespace, name string, options ...parentRefOption) v1alpha2.ParentReference {
|
||||
group := v1alpha2.Group("gateway.networking.k8s.io")
|
||||
kind := v1alpha2.Kind("Gateway")
|
||||
ref := v1alpha2.ParentReference{
|
||||
func gatewayParentRef(namespace, name string, options ...parentRefOption) v1beta1.ParentReference {
|
||||
group := v1beta1.Group("gateway.networking.k8s.io")
|
||||
kind := v1beta1.Kind("Gateway")
|
||||
ref := v1beta1.ParentReference{
|
||||
Group: &group,
|
||||
Kind: &kind,
|
||||
Name: v1alpha2.ObjectName(name),
|
||||
Namespace: (*v1alpha2.Namespace)(&namespace),
|
||||
Name: v1beta1.ObjectName(name),
|
||||
Namespace: (*v1beta1.Namespace)(&namespace),
|
||||
}
|
||||
for _, opt := range options {
|
||||
opt(&ref)
|
||||
@ -108,11 +108,11 @@ func newTestEndpointWithTTL(dnsName, recordType string, ttl int64, targets ...st
|
||||
func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
fromAll := v1alpha2.NamespacesFromAll
|
||||
fromSame := v1alpha2.NamespacesFromSame
|
||||
fromSelector := v1alpha2.NamespacesFromSelector
|
||||
allowAllNamespaces := &v1alpha2.AllowedRoutes{
|
||||
Namespaces: &v1alpha2.RouteNamespaces{
|
||||
fromAll := v1beta1.NamespacesFromAll
|
||||
fromSame := v1beta1.NamespacesFromSame
|
||||
fromSelector := v1beta1.NamespacesFromSelector
|
||||
allowAllNamespaces := &v1beta1.AllowedRoutes{
|
||||
Namespaces: &v1beta1.RouteNamespaces{
|
||||
From: &fromAll,
|
||||
},
|
||||
}
|
||||
@ -129,14 +129,14 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
}
|
||||
return v
|
||||
}
|
||||
hostnames := func(names ...v1alpha2.Hostname) []v1alpha2.Hostname { return names }
|
||||
hostnames := func(names ...v1beta1.Hostname) []v1beta1.Hostname { return names }
|
||||
|
||||
tests := []struct {
|
||||
title string
|
||||
config Config
|
||||
namespaces []*corev1.Namespace
|
||||
gateways []*v1alpha2.Gateway
|
||||
routes []*v1alpha2.HTTPRoute
|
||||
gateways []*v1beta1.Gateway
|
||||
routes []*v1beta1.HTTPRoute
|
||||
endpoints []*endpoint.Endpoint
|
||||
}{
|
||||
{
|
||||
@ -145,12 +145,12 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
GatewayNamespace: "gateway-namespace",
|
||||
},
|
||||
namespaces: namespaces("gateway-namespace", "not-gateway-namespace", "route-namespace"),
|
||||
gateways: []*v1alpha2.Gateway{
|
||||
gateways: []*v1beta1.Gateway{
|
||||
{
|
||||
ObjectMeta: objectMeta("gateway-namespace", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
AllowedRoutes: allowAllNamespaces,
|
||||
}},
|
||||
},
|
||||
@ -158,15 +158,15 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
},
|
||||
{
|
||||
ObjectMeta: objectMeta("not-gateway-namespace", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("2.3.4.5"),
|
||||
},
|
||||
},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("route-namespace", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("test.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus( // The route is attached to both gateways.
|
||||
@ -184,27 +184,27 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
Namespace: "route-namespace",
|
||||
},
|
||||
namespaces: namespaces("gateway-namespace", "route-namespace", "not-route-namespace"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("gateway-namespace", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
AllowedRoutes: allowAllNamespaces,
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{
|
||||
routes: []*v1beta1.HTTPRoute{
|
||||
{
|
||||
ObjectMeta: objectMeta("route-namespace", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("route-namespace.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("gateway-namespace", "test")),
|
||||
},
|
||||
{
|
||||
ObjectMeta: objectMeta("not-route-namespace", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("not-route-namespace.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("gateway-namespace", "test")),
|
||||
@ -220,15 +220,15 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
GatewayLabelFilter: "foo=bar",
|
||||
},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{
|
||||
gateways: []*v1beta1.Gateway{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "labels-match",
|
||||
Namespace: "default",
|
||||
Labels: map[string]string{"foo": "bar"},
|
||||
},
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
},
|
||||
@ -238,15 +238,15 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
Namespace: "default",
|
||||
Labels: map[string]string{"foo": "qux"},
|
||||
},
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("2.3.4.5"),
|
||||
},
|
||||
},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("test.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus( // The route is attached to both gateways.
|
||||
@ -264,21 +264,21 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
LabelFilter: mustGetLabelSelector("foo=bar"),
|
||||
},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{
|
||||
routes: []*v1beta1.HTTPRoute{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "labels-match",
|
||||
Namespace: "default",
|
||||
Labels: map[string]string{"foo": "bar"},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("labels-match.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -289,7 +289,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
Namespace: "default",
|
||||
Labels: map[string]string{"foo": "qux"},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("labels-dont-match.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -305,21 +305,21 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
AnnotationFilter: "foo=bar",
|
||||
},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{
|
||||
routes: []*v1beta1.HTTPRoute{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "annotations-match",
|
||||
Namespace: "default",
|
||||
Annotations: map[string]string{"foo": "bar"},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("annotations-match.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -330,7 +330,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
Namespace: "default",
|
||||
Annotations: map[string]string{"foo": "qux"},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("annotations-dont-match.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -344,14 +344,14 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "SkipControllerAnnotation",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "api",
|
||||
Namespace: "default",
|
||||
@ -359,7 +359,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
controllerAnnotationKey: "something-else",
|
||||
},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("api.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -370,25 +370,25 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "MultipleGateways",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{
|
||||
gateways: []*v1beta1.Gateway{
|
||||
{
|
||||
ObjectMeta: objectMeta("default", "one"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
},
|
||||
{
|
||||
ObjectMeta: objectMeta("default", "two"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("2.3.4.5"),
|
||||
},
|
||||
},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("test.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(
|
||||
@ -404,27 +404,27 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "MultipleListeners",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "one"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{
|
||||
{
|
||||
Name: "foo",
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("foo.example.internal"),
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("bar.example.internal"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("*.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(
|
||||
@ -440,27 +440,27 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "SectionNameMatch",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{
|
||||
{
|
||||
Name: "foo",
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("foo.example.internal"),
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("bar.example.internal"),
|
||||
},
|
||||
},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("*.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(
|
||||
@ -476,25 +476,25 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "PortNumberMatch",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{
|
||||
{
|
||||
Name: "foo",
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("foo.example.internal"),
|
||||
Port: 80,
|
||||
},
|
||||
{
|
||||
Name: "bar",
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("bar.example.internal"),
|
||||
Port: 80,
|
||||
},
|
||||
{
|
||||
Name: "qux",
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("qux.example.internal"),
|
||||
Port: 8080,
|
||||
},
|
||||
@ -502,9 +502,9 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("*.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(
|
||||
@ -520,20 +520,20 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "WildcardInGateway",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("*.example.internal"),
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "no-hostname"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Hostnames: []v1alpha2.Hostname{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: []v1beta1.Hostname{
|
||||
"foo.example.internal",
|
||||
},
|
||||
},
|
||||
@ -547,20 +547,20 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "WildcardInRoute",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("foo.example.internal"),
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "no-hostname"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Hostnames: []v1alpha2.Hostname{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: []v1beta1.Hostname{
|
||||
"*.example.internal",
|
||||
},
|
||||
},
|
||||
@ -574,20 +574,20 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "WildcardInRouteAndGateway",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("*.example.internal"),
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "no-hostname"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Hostnames: []v1alpha2.Hostname{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: []v1beta1.Hostname{
|
||||
"*.example.internal",
|
||||
},
|
||||
},
|
||||
@ -601,19 +601,19 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "NoRouteHostname",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
Hostname: hostnamePtr("foo.example.internal"),
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "no-hostname"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: nil,
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -627,9 +627,9 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: nil,
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(),
|
||||
@ -640,16 +640,16 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "NoHostnames",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "no-hostname"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: nil,
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -660,14 +660,14 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "HostnameAnnotation",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{
|
||||
routes: []*v1beta1.HTTPRoute{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "without-hostame",
|
||||
@ -676,7 +676,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "annotation.without-hostname.internal",
|
||||
},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: nil,
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -689,7 +689,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "annotation.with-hostname.internal",
|
||||
},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("with-hostname.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -707,14 +707,14 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
IgnoreHostnameAnnotation: true,
|
||||
},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "with-hostame",
|
||||
Namespace: "default",
|
||||
@ -722,7 +722,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
hostnameAnnotationKey: "annotation.with-hostname.internal",
|
||||
},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("with-hostname.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -737,24 +737,24 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
FQDNTemplate: "{{.Name}}.zero.internal, {{.Name}}.one.internal. , {{.Name}}.two.internal ",
|
||||
},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{
|
||||
routes: []*v1beta1.HTTPRoute{
|
||||
{
|
||||
ObjectMeta: objectMeta("default", "fqdn-with-hostnames"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("fqdn-with-hostnames.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
},
|
||||
{
|
||||
ObjectMeta: objectMeta("default", "fqdn-without-hostnames"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: nil,
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -774,16 +774,16 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
CombineFQDNAndAnnotation: true,
|
||||
},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "fqdn-with-hostnames"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("fqdn-with-hostnames.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -797,21 +797,21 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "TTL",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{
|
||||
routes: []*v1beta1.HTTPRoute{
|
||||
{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "valid-ttl",
|
||||
Namespace: "default",
|
||||
Annotations: map[string]string{ttlAnnotationKey: "15s"},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("valid-ttl.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -822,7 +822,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
Namespace: "default",
|
||||
Annotations: map[string]string{ttlAnnotationKey: "abc"},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("invalid-ttl.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -837,14 +837,14 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "ProviderAnnotations",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{Protocol: v1alpha2.HTTPProtocolType}},
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{Protocol: v1beta1.HTTPProtocolType}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "provider-annotations",
|
||||
Namespace: "default",
|
||||
@ -853,7 +853,7 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
aliasAnnotationKey: "true",
|
||||
},
|
||||
},
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("provider-annotations.com"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -868,31 +868,31 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "DifferentHostnameDifferentGateway",
|
||||
config: Config{},
|
||||
namespaces: namespaces("default"),
|
||||
gateways: []*v1alpha2.Gateway{
|
||||
gateways: []*v1beta1.Gateway{
|
||||
{
|
||||
ObjectMeta: objectMeta("default", "one"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Hostname: hostnamePtr("*.one.internal"),
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
},
|
||||
{
|
||||
ObjectMeta: objectMeta("default", "two"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Hostname: hostnamePtr("*.two.internal"),
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus("2.3.4.5"),
|
||||
},
|
||||
},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("test.one.internal", "test.two.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(
|
||||
@ -909,13 +909,13 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "AllowedRoutesSameNamespace",
|
||||
config: Config{},
|
||||
namespaces: namespaces("same-namespace", "other-namespace"),
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("same-namespace", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
AllowedRoutes: &v1alpha2.AllowedRoutes{
|
||||
Namespaces: &v1alpha2.RouteNamespaces{
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
AllowedRoutes: &v1beta1.AllowedRoutes{
|
||||
Namespaces: &v1beta1.RouteNamespaces{
|
||||
From: &fromSame,
|
||||
},
|
||||
},
|
||||
@ -923,17 +923,17 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{
|
||||
routes: []*v1beta1.HTTPRoute{
|
||||
{
|
||||
ObjectMeta: objectMeta("same-namespace", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("same-namespace.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("same-namespace", "test")),
|
||||
},
|
||||
{
|
||||
ObjectMeta: objectMeta("other-namespace", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("other-namespace.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("same-namespace", "test")),
|
||||
@ -965,13 +965,13 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
AllowedRoutes: &v1alpha2.AllowedRoutes{
|
||||
Namespaces: &v1alpha2.RouteNamespaces{
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
AllowedRoutes: &v1beta1.AllowedRoutes{
|
||||
Namespaces: &v1beta1.RouteNamespaces{
|
||||
From: &fromSelector,
|
||||
Selector: &metav1.LabelSelector{
|
||||
MatchLabels: map[string]string{"team": "foo"},
|
||||
@ -982,17 +982,17 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{
|
||||
routes: []*v1beta1.HTTPRoute{
|
||||
{
|
||||
ObjectMeta: objectMeta("foo", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("foo.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
},
|
||||
{
|
||||
ObjectMeta: objectMeta("bar", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("bar.example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -1006,13 +1006,13 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
title: "MissingNamespace",
|
||||
config: Config{},
|
||||
namespaces: nil,
|
||||
gateways: []*v1alpha2.Gateway{{
|
||||
gateways: []*v1beta1.Gateway{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.HTTPProtocolType,
|
||||
AllowedRoutes: &v1alpha2.AllowedRoutes{
|
||||
Namespaces: &v1alpha2.RouteNamespaces{
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.HTTPProtocolType,
|
||||
AllowedRoutes: &v1beta1.AllowedRoutes{
|
||||
Namespaces: &v1beta1.RouteNamespaces{
|
||||
// Namespace selector triggers namespace lookup.
|
||||
From: &fromSelector,
|
||||
Selector: &metav1.LabelSelector{
|
||||
@ -1024,9 +1024,9 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
},
|
||||
Status: gatewayStatus("1.2.3.4"),
|
||||
}},
|
||||
routes: []*v1alpha2.HTTPRoute{{
|
||||
routes: []*v1beta1.HTTPRoute{{
|
||||
ObjectMeta: objectMeta("default", "test"),
|
||||
Spec: v1alpha2.HTTPRouteSpec{
|
||||
Spec: v1beta1.HTTPRouteSpec{
|
||||
Hostnames: hostnames("example.internal"),
|
||||
},
|
||||
Status: httpRouteStatus(gatewayParentRef("default", "test")),
|
||||
@ -1042,12 +1042,12 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
gwClient := gatewayfake.NewSimpleClientset()
|
||||
for _, gw := range tt.gateways {
|
||||
_, err := gwClient.GatewayV1alpha2().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")
|
||||
|
||||
}
|
||||
for _, rt := range tt.routes {
|
||||
_, err := gwClient.GatewayV1alpha2().HTTPRoutes(rt.Namespace).Create(ctx, rt, metav1.CreateOptions{})
|
||||
_, err := gwClient.GatewayV1beta1().HTTPRoutes(rt.Namespace).Create(ctx, rt, metav1.CreateOptions{})
|
||||
require.NoError(t, err, "failed to create HTTPRoute")
|
||||
}
|
||||
kubeClient := kubefake.NewSimpleClientset()
|
||||
@ -1070,4 +1070,4 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func hostnamePtr(val v1alpha2.Hostname) *v1alpha2.Hostname { return &val }
|
||||
func hostnamePtr(val v1beta1.Hostname) *v1beta1.Hostname { return &val }
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||
informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
|
||||
informers_v1a2 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1alpha2"
|
||||
)
|
||||
@ -33,11 +34,13 @@ func NewGatewayTCPRouteSource(clients ClientGenerator, config *Config) (Source,
|
||||
|
||||
type gatewayTCPRoute struct{ route *v1alpha2.TCPRoute }
|
||||
|
||||
func (rt *gatewayTCPRoute) Object() kubeObject { return rt.route }
|
||||
func (rt *gatewayTCPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
|
||||
func (rt *gatewayTCPRoute) Hostnames() []v1alpha2.Hostname { return nil }
|
||||
func (rt *gatewayTCPRoute) Protocol() v1alpha2.ProtocolType { return v1alpha2.TCPProtocolType }
|
||||
func (rt *gatewayTCPRoute) RouteStatus() v1alpha2.RouteStatus { return rt.route.Status.RouteStatus }
|
||||
func (rt *gatewayTCPRoute) Object() kubeObject { return rt.route }
|
||||
func (rt *gatewayTCPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
|
||||
func (rt *gatewayTCPRoute) Hostnames() []v1beta1.Hostname { return nil }
|
||||
func (rt *gatewayTCPRoute) Protocol() v1beta1.ProtocolType { return v1beta1.TCPProtocolType }
|
||||
func (rt *gatewayTCPRoute) RouteStatus() v1beta1.RouteStatus {
|
||||
return v1b1RouteStatus(rt.route.Status.RouteStatus)
|
||||
}
|
||||
|
||||
type gatewayTCPRouteInformer struct {
|
||||
informers_v1a2.TCPRouteInformer
|
||||
@ -54,3 +57,50 @@ func (inf gatewayTCPRouteInformer) List(namespace string, selector labels.Select
|
||||
}
|
||||
return routes, nil
|
||||
}
|
||||
|
||||
func v1b1Hostnames(hostnames []v1alpha2.Hostname) []v1beta1.Hostname {
|
||||
if len(hostnames) == 0 {
|
||||
return nil
|
||||
}
|
||||
list := make([]v1beta1.Hostname, len(hostnames))
|
||||
for i, s := range hostnames {
|
||||
list[i] = v1beta1.Hostname(s)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func v1b1RouteStatus(s v1alpha2.RouteStatus) v1beta1.RouteStatus {
|
||||
return v1beta1.RouteStatus{
|
||||
Parents: v1b1RouteParentStatuses(s.Parents),
|
||||
}
|
||||
}
|
||||
|
||||
func v1b1RouteParentStatuses(statuses []v1alpha2.RouteParentStatus) []v1beta1.RouteParentStatus {
|
||||
if len(statuses) == 0 {
|
||||
return nil
|
||||
}
|
||||
list := make([]v1beta1.RouteParentStatus, len(statuses))
|
||||
for i, s := range statuses {
|
||||
list[i] = v1b1RouteParentStatus(s)
|
||||
}
|
||||
return list
|
||||
}
|
||||
|
||||
func v1b1RouteParentStatus(s v1alpha2.RouteParentStatus) v1beta1.RouteParentStatus {
|
||||
return v1beta1.RouteParentStatus{
|
||||
ParentRef: v1b1ParentReference(s.ParentRef),
|
||||
ControllerName: v1beta1.GatewayController(s.ControllerName),
|
||||
Conditions: s.Conditions,
|
||||
}
|
||||
}
|
||||
|
||||
func v1b1ParentReference(s v1alpha2.ParentReference) v1beta1.ParentReference {
|
||||
return v1beta1.ParentReference{
|
||||
Group: (*v1beta1.Group)(s.Group),
|
||||
Kind: (*v1beta1.Kind)(s.Kind),
|
||||
Namespace: (*v1beta1.Namespace)(s.Namespace),
|
||||
Name: v1beta1.ObjectName(s.Name),
|
||||
SectionName: (*v1beta1.SectionName)(s.SectionName),
|
||||
Port: (*v1beta1.PortNumber)(s.Port),
|
||||
}
|
||||
}
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
kubefake "k8s.io/client-go/kubernetes/fake"
|
||||
"sigs.k8s.io/external-dns/endpoint"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||
gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
|
||||
)
|
||||
|
||||
@ -48,19 +49,19 @@ func TestGatewayTCPRouteSourceEndpoints(t *testing.T) {
|
||||
require.NoError(t, err, "failed to create Namespace")
|
||||
|
||||
ips := []string{"10.64.0.1", "10.64.0.2"}
|
||||
gw := &v1alpha2.Gateway{
|
||||
gw := &v1beta1.Gateway{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "internal",
|
||||
Namespace: "default",
|
||||
},
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.TCPProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.TCPProtocolType,
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus(ips...),
|
||||
}
|
||||
_, err = gwClient.GatewayV1alpha2().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 := &v1alpha2.TCPRoute{
|
||||
@ -73,7 +74,7 @@ func TestGatewayTCPRouteSourceEndpoints(t *testing.T) {
|
||||
},
|
||||
Spec: v1alpha2.TCPRouteSpec{},
|
||||
Status: v1alpha2.TCPRouteStatus{
|
||||
RouteStatus: routeStatus(gatewayParentRef("default", "internal")),
|
||||
RouteStatus: v1a2RouteStatus(v1a2ParentRef("default", "internal")),
|
||||
},
|
||||
}
|
||||
_, err = gwClient.GatewayV1alpha2().TCPRoutes(rt.Namespace).Create(ctx, rt, metav1.CreateOptions{})
|
||||
@ -92,3 +93,31 @@ func TestGatewayTCPRouteSourceEndpoints(t *testing.T) {
|
||||
newTestEndpoint("api-template.foobar.internal", "A", ips...),
|
||||
})
|
||||
}
|
||||
|
||||
func v1a2ParentRef(namespace, name string) v1alpha2.ParentReference {
|
||||
group := v1alpha2.Group("gateway.networking.k8s.io")
|
||||
kind := v1alpha2.Kind("Gateway")
|
||||
ref := v1alpha2.ParentReference{
|
||||
Group: &group,
|
||||
Kind: &kind,
|
||||
Name: v1alpha2.ObjectName(name),
|
||||
Namespace: (*v1alpha2.Namespace)(&namespace),
|
||||
}
|
||||
return ref
|
||||
}
|
||||
|
||||
func v1a2RouteStatus(refs ...v1alpha2.ParentReference) v1alpha2.RouteStatus {
|
||||
var v v1alpha2.RouteStatus
|
||||
for _, ref := range refs {
|
||||
v.Parents = append(v.Parents, v1alpha2.RouteParentStatus{
|
||||
ParentRef: ref,
|
||||
Conditions: []metav1.Condition{
|
||||
{
|
||||
Type: string(v1alpha2.RouteConditionAccepted),
|
||||
Status: metav1.ConditionTrue,
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||
informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
|
||||
informers_v1a2 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1alpha2"
|
||||
)
|
||||
@ -33,11 +34,15 @@ func NewGatewayTLSRouteSource(clients ClientGenerator, config *Config) (Source,
|
||||
|
||||
type gatewayTLSRoute struct{ route *v1alpha2.TLSRoute }
|
||||
|
||||
func (rt *gatewayTLSRoute) Object() kubeObject { return rt.route }
|
||||
func (rt *gatewayTLSRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
|
||||
func (rt *gatewayTLSRoute) Hostnames() []v1alpha2.Hostname { return rt.route.Spec.Hostnames }
|
||||
func (rt *gatewayTLSRoute) Protocol() v1alpha2.ProtocolType { return v1alpha2.TLSProtocolType }
|
||||
func (rt *gatewayTLSRoute) RouteStatus() v1alpha2.RouteStatus { return rt.route.Status.RouteStatus }
|
||||
func (rt *gatewayTLSRoute) Object() kubeObject { return rt.route }
|
||||
func (rt *gatewayTLSRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
|
||||
func (rt *gatewayTLSRoute) Hostnames() []v1beta1.Hostname {
|
||||
return v1b1Hostnames(rt.route.Spec.Hostnames)
|
||||
}
|
||||
func (rt *gatewayTLSRoute) Protocol() v1beta1.ProtocolType { return v1beta1.TLSProtocolType }
|
||||
func (rt *gatewayTLSRoute) RouteStatus() v1beta1.RouteStatus {
|
||||
return v1b1RouteStatus(rt.route.Status.RouteStatus)
|
||||
}
|
||||
|
||||
type gatewayTLSRouteInformer struct {
|
||||
informers_v1a2.TLSRouteInformer
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
kubefake "k8s.io/client-go/kubernetes/fake"
|
||||
"sigs.k8s.io/external-dns/endpoint"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||
gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
|
||||
)
|
||||
|
||||
@ -48,19 +49,19 @@ func TestGatewayTLSRouteSourceEndpoints(t *testing.T) {
|
||||
require.NoError(t, err, "failed to create Namespace")
|
||||
|
||||
ips := []string{"10.64.0.1", "10.64.0.2"}
|
||||
gw := &v1alpha2.Gateway{
|
||||
gw := &v1beta1.Gateway{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "internal",
|
||||
Namespace: "default",
|
||||
},
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.TLSProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.TLSProtocolType,
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus(ips...),
|
||||
}
|
||||
_, err = gwClient.GatewayV1alpha2().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 := &v1alpha2.TLSRoute{
|
||||
@ -75,7 +76,7 @@ func TestGatewayTLSRouteSourceEndpoints(t *testing.T) {
|
||||
Hostnames: []v1alpha2.Hostname{"api-hostnames.foobar.internal"},
|
||||
},
|
||||
Status: v1alpha2.TLSRouteStatus{
|
||||
RouteStatus: routeStatus(gatewayParentRef("default", "internal")),
|
||||
RouteStatus: v1a2RouteStatus(v1a2ParentRef("default", "internal")),
|
||||
},
|
||||
}
|
||||
_, err = gwClient.GatewayV1alpha2().TLSRoutes(rt.Namespace).Create(ctx, rt, metav1.CreateOptions{})
|
||||
|
@ -20,6 +20,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/labels"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||
informers "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions"
|
||||
informers_v1a2 "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/apis/v1alpha2"
|
||||
)
|
||||
@ -33,11 +34,13 @@ func NewGatewayUDPRouteSource(clients ClientGenerator, config *Config) (Source,
|
||||
|
||||
type gatewayUDPRoute struct{ route *v1alpha2.UDPRoute }
|
||||
|
||||
func (rt *gatewayUDPRoute) Object() kubeObject { return rt.route }
|
||||
func (rt *gatewayUDPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
|
||||
func (rt *gatewayUDPRoute) Hostnames() []v1alpha2.Hostname { return nil }
|
||||
func (rt *gatewayUDPRoute) Protocol() v1alpha2.ProtocolType { return v1alpha2.UDPProtocolType }
|
||||
func (rt *gatewayUDPRoute) RouteStatus() v1alpha2.RouteStatus { return rt.route.Status.RouteStatus }
|
||||
func (rt *gatewayUDPRoute) Object() kubeObject { return rt.route }
|
||||
func (rt *gatewayUDPRoute) Metadata() *metav1.ObjectMeta { return &rt.route.ObjectMeta }
|
||||
func (rt *gatewayUDPRoute) Hostnames() []v1beta1.Hostname { return nil }
|
||||
func (rt *gatewayUDPRoute) Protocol() v1beta1.ProtocolType { return v1beta1.UDPProtocolType }
|
||||
func (rt *gatewayUDPRoute) RouteStatus() v1beta1.RouteStatus {
|
||||
return v1b1RouteStatus(rt.route.Status.RouteStatus)
|
||||
}
|
||||
|
||||
type gatewayUDPRouteInformer struct {
|
||||
informers_v1a2.UDPRouteInformer
|
||||
|
@ -26,6 +26,7 @@ import (
|
||||
kubefake "k8s.io/client-go/kubernetes/fake"
|
||||
"sigs.k8s.io/external-dns/endpoint"
|
||||
"sigs.k8s.io/gateway-api/apis/v1alpha2"
|
||||
"sigs.k8s.io/gateway-api/apis/v1beta1"
|
||||
gatewayfake "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/fake"
|
||||
)
|
||||
|
||||
@ -48,19 +49,19 @@ func TestGatewayUDPRouteSourceEndpoints(t *testing.T) {
|
||||
require.NoError(t, err, "failed to create Namespace")
|
||||
|
||||
ips := []string{"10.64.0.1", "10.64.0.2"}
|
||||
gw := &v1alpha2.Gateway{
|
||||
gw := &v1beta1.Gateway{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: "internal",
|
||||
Namespace: "default",
|
||||
},
|
||||
Spec: v1alpha2.GatewaySpec{
|
||||
Listeners: []v1alpha2.Listener{{
|
||||
Protocol: v1alpha2.UDPProtocolType,
|
||||
Spec: v1beta1.GatewaySpec{
|
||||
Listeners: []v1beta1.Listener{{
|
||||
Protocol: v1beta1.UDPProtocolType,
|
||||
}},
|
||||
},
|
||||
Status: gatewayStatus(ips...),
|
||||
}
|
||||
_, err = gwClient.GatewayV1alpha2().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 := &v1alpha2.UDPRoute{
|
||||
@ -73,7 +74,7 @@ func TestGatewayUDPRouteSourceEndpoints(t *testing.T) {
|
||||
},
|
||||
Spec: v1alpha2.UDPRouteSpec{},
|
||||
Status: v1alpha2.UDPRouteStatus{
|
||||
RouteStatus: routeStatus(gatewayParentRef("default", "internal")),
|
||||
RouteStatus: v1a2RouteStatus(v1a2ParentRef("default", "internal")),
|
||||
},
|
||||
}
|
||||
_, err = gwClient.GatewayV1alpha2().UDPRoutes(rt.Namespace).Create(ctx, rt, metav1.CreateOptions{})
|
||||
|
Loading…
Reference in New Issue
Block a user