|
| 1 | +/* Copyright © 2026 Broadcom, Inc. All Rights Reserved. |
| 2 | + SPDX-License-Identifier: Apache-2.0 */ |
| 3 | + |
| 4 | +package gateway |
| 5 | + |
| 6 | +import ( |
| 7 | + "k8s.io/apimachinery/pkg/types" |
| 8 | + |
| 9 | + "github.com/vmware-tanzu/nsx-operator/pkg/nsx/services/dns" |
| 10 | + extdns "github.com/vmware-tanzu/nsx-operator/pkg/third_party/externaldns/endpoint" |
| 11 | +) |
| 12 | + |
| 13 | +// Route DNS: hostnames + ipCache → extdns.Endpoint. |
| 14 | +// Gateway annotation-hostname DNS (collectGatewayEndpointsByAnnotation / buildEndpointsFromAnnotations) |
| 15 | +// was moved to dns-networkinfo-hostname to separate the hostname-conflict-resolution feature. |
| 16 | + |
| 17 | +type parentGatewayMatch struct { |
| 18 | + nn types.NamespacedName |
| 19 | + filter string |
| 20 | + ips extdns.Targets |
| 21 | +} |
| 22 | + |
| 23 | +func mergeTargetsUnion(a, b extdns.Targets) extdns.Targets { |
| 24 | + return extdns.NewTargets(append(append([]string(nil), a...), b...)...) |
| 25 | +} |
| 26 | + |
| 27 | +// buildRouteDNSMergedEndpoints builds owner-scoped Route DNS rows (Gateway or ListenerSet→root Gateway, same rules as aggregation). |
| 28 | +func (a routeReconcilerAdapter[PT, T]) buildRouteDNSMergedEndpoints(route PT) (*dns.AggregatedDNSEndpoints, map[string]string, error) { |
| 29 | + owner := route.GetResourceRef() |
| 30 | + eps, allowed, err := a.reconciler.buildRouteDNSEndpointsForAggregation(route.GetNamespace(), owner, route.GetParentRefs(), route.GetRouteParentStatus(), route.GetObjectMeta(), route.GetSpecHostnames()) |
| 31 | + if err != nil || len(eps) == 0 { |
| 32 | + return nil, allowed, err |
| 33 | + } |
| 34 | + return dns.NewOwnerScopedAggregatedRouteDNS(owner, eps), allowed, nil |
| 35 | +} |
| 36 | + |
| 37 | +// buildEndpoints appends extdns endpoints per hostname; sets EndpointLabelParentGateway to gatewayLabel (comma-separated if merged). |
| 38 | +func buildEndpoints(out *[]*extdns.Endpoint, hostnames []string, targets extdns.Targets, parentGatewayLabel string) { |
| 39 | + ttl := extdns.TTL(0) |
| 40 | + for _, h := range hostnames { |
| 41 | + if h == "" { |
| 42 | + continue |
| 43 | + } |
| 44 | + for _, ep := range extdns.EndpointsForHostname(h, targets, ttl) { |
| 45 | + if ep == nil { |
| 46 | + continue |
| 47 | + } |
| 48 | + if parentGatewayLabel != "" { |
| 49 | + ep.WithLabel(dns.EndpointLabelParentGateway, parentGatewayLabel) |
| 50 | + } |
| 51 | + *out = append(*out, ep) |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments