Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow annotation target override on gateway #3452

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/annotations/annotations.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ The following table documents which sources support which annotations:
| CloudFoundry | | | | | | |
| CRD | | | | | | |
| F5 | | | | | Yes | |
| Gateway | Yes | Yes[^1] | | | Yes | Yes |
| Gateway | Yes | Yes[^1] | | Yes[^4] | Yes | Yes |
| Gloo | | | | | Yes | Yes |
| Ingress | Yes | Yes[^1] | | Yes | Yes | Yes |
| Istio | Yes | Yes[^1] | | Yes | Yes | Yes |
Expand All @@ -27,6 +27,7 @@ The following table documents which sources support which annotations:
[^1]: Unless the `--ignore-hostname-annotation` flag is specified.
[^2]: Only behaves differently than `hostname` for `Service`s of type `LoadBalancer`.
[^3]: Also supported on `Pods` referenced from a headless `Service`'s `Endpoints`.
[^4]: The annotation should be on the `Gateway`

## external-dns.alpha.kubernetes.io/access

Expand Down
8 changes: 6 additions & 2 deletions source/gateway.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,8 +352,12 @@ func (c *gatewayRouteResolver) resolve(rt gatewayRoute) (map[string]endpoint.Tar
if !ok {
continue
}
for _, addr := range gw.gateway.Status.Addresses {
hostTargets[host] = append(hostTargets[host], addr.Value)
override := getTargetsFromTargetAnnotation(gw.gateway.Annotations)
hostTargets[host] = append(hostTargets[host], override...)
if len(override) == 0 {
for _, addr := range gw.gateway.Status.Addresses {
hostTargets[host] = append(hostTargets[host], addr.Value)
}
}
match = true
}
Expand Down
85 changes: 85 additions & 0 deletions source/gateway_httproute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1033,6 +1033,91 @@ func TestGatewayHTTPRouteSourceEndpoints(t *testing.T) {
}},
endpoints: nil,
},
{
title: "AnnotationOverride",
config: Config{
GatewayNamespace: "gateway-namespace",
},
namespaces: namespaces("gateway-namespace", "route-namespace"),
gateways: []*v1beta1.Gateway{
{
ObjectMeta: metav1.ObjectMeta{
Name: "overriden-gateway",
Namespace: "gateway-namespace",
Annotations: map[string]string{
targetAnnotationKey: "4.3.2.1",
},
},
Spec: v1beta1.GatewaySpec{
Listeners: []v1beta1.Listener{{
Protocol: v1beta1.HTTPProtocolType,
AllowedRoutes: allowAllNamespaces,
}},
},
Status: gatewayStatus("1.2.3.4"),
},
},
routes: []*v1beta1.HTTPRoute{{
ObjectMeta: objectMeta("route-namespace", "test"),
Spec: v1beta1.HTTPRouteSpec{
Hostnames: hostnames("test.example.internal"),
},
Status: httpRouteStatus( // The route is attached to both gateways.
gatewayParentRef("gateway-namespace", "overriden-gateway"),
),
}},
endpoints: []*endpoint.Endpoint{
newTestEndpoint("test.example.internal", "A", "4.3.2.1"),
},
},
{
title: "MutlipleGatewaysOneAnnotationOverride",
config: Config{
GatewayNamespace: "gateway-namespace",
},
namespaces: namespaces("gateway-namespace", "route-namespace"),
gateways: []*v1beta1.Gateway{
{
ObjectMeta: metav1.ObjectMeta{
Name: "overriden-gateway",
Namespace: "gateway-namespace",
Annotations: map[string]string{
targetAnnotationKey: "4.3.2.1",
},
},
Spec: v1beta1.GatewaySpec{
Listeners: []v1beta1.Listener{{
Protocol: v1beta1.HTTPProtocolType,
AllowedRoutes: allowAllNamespaces,
}},
},
Status: gatewayStatus("1.2.3.4"),
},
{
ObjectMeta: objectMeta("gateway-namespace", "test"),
Spec: v1beta1.GatewaySpec{
Listeners: []v1beta1.Listener{{
Protocol: v1beta1.HTTPProtocolType,
AllowedRoutes: allowAllNamespaces,
}},
},
Status: gatewayStatus("2.3.4.5"),
},
},
routes: []*v1beta1.HTTPRoute{{
ObjectMeta: objectMeta("route-namespace", "test"),
Spec: v1beta1.HTTPRouteSpec{
Hostnames: hostnames("test.example.internal"),
},
Status: httpRouteStatus( // The route is attached to both gateways.
gatewayParentRef("gateway-namespace", "overriden-gateway"),
gatewayParentRef("gateway-namespace", "test"),
),
}},
endpoints: []*endpoint.Endpoint{
newTestEndpoint("test.example.internal", "A", "4.3.2.1", "2.3.4.5"),
},
},
}
for _, tt := range tests {
tt := tt
Expand Down
Loading