From b40060bc4734237a21254c6b4a0e9679147c6114 Mon Sep 17 00:00:00 2001 From: reoring Date: Mon, 9 Nov 2026 18:20:43 +0900 Subject: [PATCH] gatewayendpoint: honour gateway.endpoint.dns.appthrust.io/excluded-listeners Listener sections named in the annotation are excluded from publication and from retained receipts, so a Platform Gateway may serve a managed domain (dashboard instances at .appthrust.app) without emitting wildcard records that the Zone contract forbids. --- README.md | 12 ++++ .../controllers/gateway/controller.go | 20 +++++++ .../gateway/excluded_listeners_test.go | 55 +++++++++++++++++++ 3 files changed, 87 insertions(+) create mode 100644 internal/go/apps/gatewayendpoint/controllers/gateway/excluded_listeners_test.go diff --git a/README.md b/README.md index ac2f090..493f587 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,18 @@ dns-api adds custom resources to your cluster: The controller watches those resources and reconciles the real DNS provider state. +### Delegating DNS for Gateway listeners + +A Gateway owner can set +`gateway.endpoint.dns.appthrust.io/excluded-listeners: "https-managed,http-managed"` +on the Gateway. These comma-separated listener section names are excluded from +Gateway EndpointRecordSet publication, including wildcard redirect routes, exact +HTTPRoute hosts, and previously admitted hostname retention. Other listeners are +unchanged. Apply the annotation before adding listeners whose DNS has another +owner, and deploy a dns-api version supporting this contract first; older versions +do not honour the annotation. The other writer owns its RecordSets and deletion. + + ## Install The controller is distributed as a container image and a Helm chart on GitHub Container Registry. Choose the released version you want to run: diff --git a/internal/go/apps/gatewayendpoint/controllers/gateway/controller.go b/internal/go/apps/gatewayendpoint/controllers/gateway/controller.go index a31a7fb..2333fd8 100644 --- a/internal/go/apps/gatewayendpoint/controllers/gateway/controller.go +++ b/internal/go/apps/gatewayendpoint/controllers/gateway/controller.go @@ -33,6 +33,7 @@ const ( managedByLabel = "app.kubernetes.io/managed-by" managedByValue = "dns-api-gateway-endpoint" httpRouteGatewayIndex = "gateway.endpoint.dns.appthrust.io/parent-gateway" + excludedListenersAnnotation = "gateway.endpoint.dns.appthrust.io/excluded-listeners" ) type Reconciler struct { @@ -260,6 +261,7 @@ func (r *Reconciler) endpointRecordSetsForGateway(ctx context.Context, gateway * hostnames := map[string]struct{}{} retainedHostnames := map[string]struct{}{} receiptBindings := map[string]admissionReceiptBinding{} + excluded := excludedListeners(gateway) for i := range routes.Items { route := &routes.Items[i] if !route.DeletionTimestamp.IsZero() { @@ -267,6 +269,9 @@ func (r *Reconciler) endpointRecordSetsForGateway(ctx context.Context, gateway * } fullyAccepted := allRouteParentRefsAccepted(route) for _, binding := range routeGatewayBindings(route, gateway) { + if _, skip := excluded[binding.listener.Name]; skip { + continue + } acceptance := routeParentAcceptance(route, binding.ref) for _, hostname := range effectiveHostnamesForListener(route, binding.listener) { match, hasReceipt := admissionReceiptBinding{}, false @@ -344,6 +349,21 @@ func (r *Reconciler) endpointRecordSetsForGateway(ctx context.Context, gateway * }}, nil } +// The Gateway owner may delegate DNS for selected listener sections to a +// different writer. Apply this before both new admission and receipt retention. +func excludedListeners(gateway *gatewayv1.Gateway) map[gatewayv1.SectionName]struct{} { + var excluded map[gatewayv1.SectionName]struct{} + for name := range strings.SplitSeq(gateway.Annotations[excludedListenersAnnotation], ",") { + if name = strings.TrimSpace(name); name != "" { + if excluded == nil { + excluded = make(map[gatewayv1.SectionName]struct{}) + } + excluded[gatewayv1.SectionName(name)] = struct{}{} + } + } + return excluded +} + func (r *Reconciler) applyGatewayEndpointRecordSets(ctx context.Context, namespace string, gatewayKey client.ObjectKey, desired []endpointv1alpha1.EndpointRecordSet) error { desiredNames := map[string]struct{}{} for _, item := range desired { diff --git a/internal/go/apps/gatewayendpoint/controllers/gateway/excluded_listeners_test.go b/internal/go/apps/gatewayendpoint/controllers/gateway/excluded_listeners_test.go new file mode 100644 index 0000000..57d7256 --- /dev/null +++ b/internal/go/apps/gatewayendpoint/controllers/gateway/excluded_listeners_test.go @@ -0,0 +1,55 @@ +package gateway + +import ( + "reflect" + "testing" + + endpoint "github.com/appthrust/dns-api/pkg/go/api/endpoint/v1alpha1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/types" + "sigs.k8s.io/controller-runtime/pkg/client" + "sigs.k8s.io/controller-runtime/pkg/client/fake" + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" +) + +func TestManagedListenersDoNotPublishDNS(t *testing.T) { + ctx := t.Context() + wildcard := gatewayv1.Hostname("*.appthrust.app") + public := &gatewayv1.Gateway{ObjectMeta: metav1.ObjectMeta{Name: "public", Namespace: "platform", UID: "gateway", Generation: 1}, Spec: gatewayv1.GatewaySpec{ + GatewayClassName: "envoy", Listeners: []gatewayv1.Listener{{Name: "https-platform"}, {Name: "https-managed", Hostname: &wildcard}, {Name: "http-managed", Hostname: &wildcard}}, + }, Status: gatewayv1.GatewayStatus{Addresses: []gatewayv1.GatewayStatusAddress{{Value: "pmc.elb.example.test"}}}} + routes := []*gatewayv1.HTTPRoute{ + acceptedHTTPRoute("platform", "console", "platform", "https-platform", "console.appthrust.com"), + acceptedHTTPRoute("platform", "redirect", "platform", "http-managed", "*.appthrust.app"), + acceptedHTTPRoute("dashboards", "acme", "platform", "https-managed", "acme.appthrust.app"), + } + objects := []client.Object{public} + for _, route := range routes { + route.UID, route.Generation = types.UID(route.Name), 1 + route.Status.Parents[0].Conditions[0].ObservedGeneration = route.Generation + objects = append(objects, route) + } + r := &Reconciler{Client: fake.NewClientBuilder().WithScheme(testScheme(t)).WithObjects(objects...).Build()} + before, err := r.endpointRecordSetsForGateway(ctx, public, "dns", nil) + if err != nil || len(before) != 1 || len(before[0].Spec.Hostnames) != 3 { + t.Fatalf("baseline publication: %#v %v", before, err) + } + public.Annotations = map[string]string{excludedListenersAnnotation: " https-managed, http-managed,https-managed "} + for _, existing := range []*endpoint.EndpointRecordSet{nil, &before[0]} { + records, err := r.endpointRecordSetsForGateway(ctx, public, "dns", existing) + if err != nil || len(records) != 1 || !reflect.DeepEqual(records[0].Spec.Hostnames, []string{"console.appthrust.com"}) { + t.Fatalf("managed hosts must never be emitted or retained: %#v %v", records, err) + } + } + // Even during an address outage, prior admission cannot retain an excluded host. + public.Status.Addresses = nil + records, err := r.endpointRecordSetsForGateway(ctx, public, "dns", &before[0]) + if err != nil || len(records) != 1 || !reflect.DeepEqual(records[0].Spec.Hostnames, []string{"console.appthrust.com"}) { + t.Fatalf("excluded receipt retained during outage: %#v %v", records, err) + } + public.Annotations[excludedListenersAnnotation] = "https-platform,https-managed,http-managed" + records, err = r.endpointRecordSetsForGateway(ctx, public, "dns", &before[0]) + if err != nil || len(records) != 0 { + t.Fatalf("all excluded listeners must withdraw gateway publication: %#v %v", records, err) + } +}