Skip to content

Commit

Permalink
Merge pull request #3452 from BadLiveware/feature/allow-target-annota…
Browse files Browse the repository at this point in the history
…tion-gateway

Allow annotation target override on gateway
  • Loading branch information
k8s-ci-robot authored Sep 15, 2023
2 parents a10a80e + 712582c commit 65db0c7
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 3 deletions.
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

0 comments on commit 65db0c7

Please sign in to comment.