-
Notifications
You must be signed in to change notification settings - Fork 24
feat(gateway): configure DNS records for Gateway API resources #1427
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
base: main
Are you sure you want to change the base?
Changes from all commits
c882eb5
8c68706
4cfcb3a
541a1f8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* Copyright © 2026 Broadcom, Inc. All Rights Reserved. | ||
| SPDX-License-Identifier: Apache-2.0 */ | ||
|
|
||
| package gateway | ||
|
|
||
| import ( | ||
| "k8s.io/apimachinery/pkg/types" | ||
|
|
||
| "github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/dns" | ||
| extdns "github.com/vmware-tanzu/nsx-operator/pkg/third_party/externaldns/endpoint" | ||
| ) | ||
|
|
||
| // Route DNS: hostnames + ipCache → extdns.Endpoint. | ||
| // Gateway annotation-hostname DNS (collectGatewayEndpointsByAnnotation / buildEndpointsFromAnnotations) | ||
| // was moved to dns-networkinfo-hostname to separate the hostname-conflict-resolution feature. | ||
|
|
||
| type parentGatewayMatch struct { | ||
| nn types.NamespacedName | ||
| filter string | ||
| ips extdns.Targets | ||
| } | ||
|
|
||
| func mergeTargetsUnion(a, b extdns.Targets) extdns.Targets { | ||
| return extdns.NewTargets(append(append([]string(nil), a...), b...)...) | ||
| } | ||
|
|
||
| // buildRouteDNSMergedEndpoints builds owner-scoped Route DNS rows (Gateway or ListenerSet→root Gateway, same rules as aggregation). | ||
| func (a routeReconcilerAdapter[PT, T]) buildRouteDNSMergedEndpoints(route PT) (*dns.AggregatedDNSEndpoints, map[string]string, error) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where's the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you mean move the existing code in this file to |
||
| owner := route.GetResourceRef() | ||
| eps, allowed, err := a.reconciler.buildRouteDNSEndpointsForAggregation(route.GetNamespace(), owner, route.GetParentRefs(), route.GetRouteParentStatus(), route.GetObjectMeta(), route.GetSpecHostnames()) | ||
| if err != nil || len(eps) == 0 { | ||
| return nil, allowed, err | ||
| } | ||
| return dns.NewOwnerScopedAggregatedRouteDNS(owner, eps), allowed, nil | ||
| } | ||
|
|
||
| // buildEndpoints appends extdns endpoints per hostname; sets EndpointLabelParentGateway to gatewayLabel (comma-separated if merged). | ||
| func buildEndpoints(out *[]*extdns.Endpoint, hostnames []string, targets extdns.Targets, parentGatewayLabel string) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious why this func follows an output param pattern while most everything else follows returning vals.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is actually to append the generated Endpoints to an existing slice, the caller is within a for-loop. |
||
| ttl := extdns.TTL(0) | ||
| for _, h := range hostnames { | ||
| if h == "" { | ||
| continue | ||
| } | ||
| for _, ep := range extdns.EndpointsForHostname(h, targets, ttl) { | ||
| if ep == nil { | ||
| continue | ||
| } | ||
| if parentGatewayLabel != "" { | ||
| ep.WithLabel(dns.EndpointLabelParentGateway, parentGatewayLabel) | ||
| } | ||
| *out = append(*out, ep) | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is the nil val needed? Won't this add a literal
nilentry in?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[]string(nil)equals to the belowvar s []string, but we don't need to introduce a dedicated temporary variablesThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, makes sense. Bit tricky to read.