Skip to content

feat(edge): Write listener NetworkServices and order their teardown - #1523

Merged
privateip merged 10 commits into
fix/issue-1509-publishfrom
fix/issue-1509
Nov 29, 2026
Merged

privateip merged 10 commits into
fix/issue-1509-publishfrom
fix/issue-1509

Conversation

@privateip

@privateip privateip commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An accepted listener still has no gateway service, so no gateway can serve its public addresses.

Core now writes one gateway service per listener port, with the listener's addresses, affinity and health check, and removes the service of a port that goes away.

Deleting or refusing a listener removes its services first, then keeps serving backends advertised for a configurable delay, 30 seconds by default, so every gateway node finishes draining the public addresses before the backends go.

An admission policy limits core's writes to listener services, and every listener now carries a finalizer, so the rollback notes say how to clear it by hand.

Test plan

  • Each port of an accepted listener gets one gateway service, and a removed port loses its service
  • After a listener's services go, its serving backends stay advertised for the delay, even across a controller restart, while gone or unready backends are withdrawn at once
  • Core cannot create, change or delete a gateway service that does not belong to a listener
  • CI passes

Fixes #1509

While an EdgeListener is accepted, core now writes one NetworkService
per port in galactic-system, named <listener>-<protocol>-<port> (with a
hash suffix when the name has a dot or is too long for 63 characters)
and controlled by the listener. Each carries the listener's addresses,
the port's protocol, port and backendPort, its sessionAffinity,
edgeListenerRef, the ingress gVPC's status.vpc as vpcRef, and a TCP
health check with the listener's failurePolicy on healthPort or the
first tcp backendPort. The service of a removed port is deleted, and so
is every service of a listener no longer accepted. A name held by a
NetworkService the listener does not control is left alone, named in
Programmed's message and recorded in an Event.

The gateway holds a NetworkService with its networkservice-teardown
finalizer until it has withdrawn the service's addresses. Core keeps
the listener's /128s until those services are gone, so a VIP is never
advertised toward a backend the gateways can no longer resolve. A new
galactic.datumapis.com/edge-listener finalizer holds a deleted listener
through the same order: delete its services, wait for them to go,
withdraw its /128s, then release it. A listener removed without its
finalizer keeps its /128s until the garbage collector and the gateways
have removed its services.

Tests cover an older listener taking its address back from a younger
one while the gateways hold the younger's services, and that a pass
over an unchanged listener writes nothing.

The galactic-controller-edge-listener Role now also grants the
NetworkService writes and the listener finalizer.

Fixes #1509
@privateip privateip self-assigned this Nov 29, 2026
@privateip
privateip added this pull request to stack #1524 November 29, 2026 03:43
# Conflicts:
#	docs/designs/edge-public-listener.md
#	internal/edge/listener/listener_fixture_envtest_test.go
The comment broke mid-sentence after an earlier edit.

Refs #1509
@privateip

Copy link
Copy Markdown
Contributor Author

Review verdicts at head f3a2d35: the correctness re-review says merge, and the conventions review held on points now settled.

The body now states the Role's reach. Core can create, change and delete gateway services in the gateway namespace, and touches only those labelled for its listeners. It patches listeners only to hold them with a finalizer.

This lands before the gateway work in #1511 on purpose. Nothing runs unless the edge controllers and the new listener and ingress flags are set, and no gateway serves a listener until #1511 merges.

The merge commits stay, for the same reason as the rest of the stack. The resolution of the design document conflict with main kept both sides, and the re-review confirmed nothing was lost. Draft #845 also changes gateway service validation. The design already says whichever lands second reconciles that rule, and the two share no files.

@privateip
privateip marked this pull request as ready for review November 29, 2026 04:55
@privateip
privateip requested a review from a team as a code owner November 29, 2026 04:55
@privateip
privateip requested a review from scotwells November 29, 2026 04:55

@scotwells scotwells left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deleting or refusing a listener can drop live traffic for several seconds.

  • The teardown order doesn't hold. Finalize (internal/edge/listener/reconciler.go:165) withdraws the backend /128s as soon as the listener's NetworkServices are gone. The gateway releases its finalizer once it has deleted its VIP advertisements, but each gateway node keeps the VIP loaded for ruleDrainDelay while that withdrawal spreads, and the finalizer doesn't wait on the nodes (internal/controller/networkservice_controller.go:331). For those seconds, plus BGP convergence, gateways keep accepting VIP traffic and forward it to backends nobody can resolve any more. The refused-listener path at publish.go:42 behaves the same way. Hold the /128s for at least the drain delay after the services are gone, or make the gateway's finalizer cover its drain. Then fix provider-contract.md:323, which promises the reverse.
  • Stale backends stay advertised during a long teardown. While services are still leaving, publishing returns before withdrawing anything. A backend whose attachment was deleted keeps its /128 for as long as the gateway holds the service, which is indefinitely if galactic-gateway is down. Keep withdrawing gone backends while the teardown waits.
  • Core can rewrite any NetworkService in galactic-system, including production NLB services. The new rule (config/galactic-edge/controller-rbac.yaml:192) grants it, and only the code's own checks stop it. Add an admission policy that limits core's writes to listener-owned services, as already done for its rolebindings. Also drop patch on networkservices and update on edgelisteners, which nothing uses.

Every listener now gets a finalizer, so rolling the controller back below this change leaves deleting listeners stuck. Put that in the rollback notes.

# Conflicts:
#	config/galactic-edge/controller-rbac.yaml
#	internal/edge/listener/listener_envtest_test.go
#	internal/edge/listener/listener_fixture_envtest_test.go
#	internal/edge/listener/reconciler.go
#	internal/edge/listener/setup.go
The teardown withdrew a refused or deleted listener's backend /128s as
soon as its NetworkServices were gone. The gateway's teardown finalizer
goes once the service's advertisements are deleted, but each gateway
node keeps serving the service for its drain delay (5 s) after that,
and the withdrawal takes time to converge in BGP, so the VIP could be
advertised toward a backend the gateways no longer resolve.

Core now keeps the /128s for --edge-listener-withdraw-delay (default
30 s, which must exceed the gateway drain delay) after it first sees
the services gone, and decides the listener again at the deadline. It
records that instant in the galactic.datumapis.com/edge-listener-
services-gone annotation, so a restart of core does not shorten the
hold. A test pins the gateway's drain delay to the value core assumes.

During a long teardown, while the gateway holds the services or the
delay runs, core keeps only the /128s of backends that would still
serve: an attachment that goes, or stops being eligible or holding its
lease, loses its /128 at once.

Refs #1509
Core's Role in galactic-system lets it write NetworkServices, and RBAC
cannot scope that by label, so core could rewrite any service in the
gateway namespace. A new ValidatingAdmissionPolicy,
galactic-edge-controller-listener-services, now lets the
galactic-controller ServiceAccount create, update or delete a
NetworkService only when the object names an EdgeListener in
spec.edgeListenerRef and carries the galactic.datumapis.com/edge-listener
label, and for an update or delete only when the existing object does
too.

The Role also drops verbs nothing uses: patch on networkservices, which
core creates, updates and deletes, and update on edgelisteners, whose
finalizer and annotation core writes by merge patch. update on
edgelisteners/finalizers stays for the owner references that block a
listener's deletion.

An envtest, run as galactic-controller under the shipped RBAC and
policies, shows the policy refusing core's writes to a platform service
and allowing its writes to a listener's.

Refs #1509
Every EdgeListener now carries core's galactic.datumapis.com/edge-listener
finalizer, so rolling galactic-controller back below this change leaves
a listener deleted afterwards stuck deleting. The design's Feature
Enablement and Rollback section and the controller docs now say how to
finish the teardown by hand, in the order core keeps: delete the
listener's NetworkServices, wait out the withdraw delay, delete its /128
advertisements, then clear the finalizer, with example commands using
placeholder names.

Refs #1509
@privateip

Copy link
Copy Markdown
Contributor Author

All four points are addressed at 13bed65.

  • After a listener's services are gone, core holds its /128s for --edge-listener-withdraw-delay, 30 seconds by default. Startup refuses a value at or under the gateway's 5 second drain, and a test pins that drain value. Core saves the time the services went in an annotation on the listener, so a restart cannot shorten the hold. The refused-listener path does the same, and the provider contract now states this order.
  • During the hold, core keeps only the /128s of backends that would still serve. A deleted or unready backend is withdrawn at once, even while the gateway holds the service indefinitely.
  • A new admission policy limits galactic-controller's create, update and delete of NetworkServices to objects carrying edgeListenerRef and the listener label, checking the old object on update and delete. The listener Role now has create, update and delete on networkservices, patch on edgelisteners and their status, and update on edgelisteners/finalizers, which blockOwnerDeletion needs.
  • The design's rollback section and the controller docs say how to clear the finalizer by hand after a rollback.

@privateip
privateip requested review from a team and scotwells November 29, 2026 14:09
ecv
ecv previously approved these changes Nov 29, 2026

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve.

scotwells's blocking points are fixed at 13bed65. A deleted listener's backend /128s now outlive its NetworkServices by --edge-listener-withdraw-delay (default 30s; startup refuses a value at or below the gateway's 5s drain delay), and the moment the services went is recorded on the listener, so a restart cannot shorten the hold. Halving the hold fails both TestListenerWithdrawDelay and TestListenerWithdrawDelayRestart under envtest. The new galactic-edge-controller-listener-services policy limits core's NetworkService writes to listener-labelled services with an edgeListenerRef, TestControllerNetworkServicePolicy covers it, and patch on networkservices and update on edgelisteners are gone. TestRuleDrainDelayMatchesListener ties the 5s constant to the gateway's ruleDrainDelay.

Follow-ups:

  • withdrawGone, the path for a listener removed without its finalizer (the rollback the new docs describe), withdraws the /128s as soon as the services are gone, with no hold, so it still drops traffic for the drain window. Hold it the same way, or say so in the rollback notes.
  • Every hold test deletes the listener; none flips an accepted listener to refused, which shares withdrawHold through the d.grant == nil branch. Add one.
  • The policy matches system:serviceaccount:galactic-system:galactic-controller by name while the controller's identity is configurable. A cell that renames it silently loses the restriction; derive it or add a bundle check.
  • No test covers the startup refusal of a short withdraw delay.
  • The 30s margin for BGP convergence is not measured yet; record what is observed before relying on it.

# Conflicts:
#	internal/edge/listener/listener_envtest_test.go

@scotwells scotwells left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please withdraw the old backend route during teardown if the attachment moves to another gVPC or changes address. stillServes checks readiness, UID and lease, but not whether the current VPC and address still match the advertisement. A healthy attachment can therefore keep its old /128 published in the wrong network for the drain period. Please cover that change while a service is draining.

@privateip
privateip requested review from a team, ecv and scotwells November 29, 2026 16:35
ecv
ecv previously approved these changes Nov 29, 2026

@ecv ecv left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approve.

Merge of fix/issue-1509-publish only: it brings #1521's new lease and instance tests through #1522, reviewed there. This PR's own commits are unchanged since my last approval.

While a listener's NetworkServices drain, core kept each /128 whose
backend was still ready and leased, without checking that the attachment
still had the gVPC and address the advertisement carried. A healthy
attachment that moved kept its old /128 published in the old network
for the whole drain.

A held advertisement now stays only while its gVPC label and prefix
match the attachment's current status.vpc and status.address.
@privateip

Copy link
Copy Markdown
Contributor Author

Fixed in 5ab17f0. While services drain, a held advertisement stays only while its gVPC label and /128 match the attachment's current status.vpc and status.address, so a moved attachment loses its old /128 at once. TestListenerHeldWithdrawsMoved changes one backend's address and moves another to a different gVPC during the drain: both old /128s go, and an unmoved backend keeps its /128. It fails without the fix. The provider contract's drain paragraph covers the moved case.

scotwells
scotwells previously approved these changes Nov 29, 2026

@scotwells scotwells left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved the teardown order: keep valid backend routes while gateways drain, but withdraw the old route when a backend moves or changes address.

@privateip
privateip dismissed scotwells’s stale review November 29, 2026 21:27

The merge-base changed after approval.

@privateip
privateip merged commit 81e9f5b into main Nov 29, 2026
30 checks passed
@privateip
privateip deleted the fix/issue-1509 branch November 29, 2026 21:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Build Edge public listener core controllers

3 participants