Repository navigation
feat(edge): Write listener NetworkServices and order their teardown - #1523
Conversation
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
# 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
|
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. |
scotwells
left a comment
There was a problem hiding this comment.
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
ruleDrainDelaywhile 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
patchon networkservices andupdateon 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
|
All four points are addressed at 13bed65.
|
ecv
left a comment
There was a problem hiding this comment.
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
withdrawHoldthrough thed.grant == nilbranch. Add one. - The policy matches
system:serviceaccount:galactic-system:galactic-controllerby 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
left a comment
There was a problem hiding this comment.
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.
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.
|
Fixed in 5ab17f0. While services drain, a held advertisement stays only while its gVPC label and |
scotwells
left a comment
There was a problem hiding this comment.
Approved the teardown order: keep valid backend routes while gateways drain, but withdraw the old route when a backend moves or changes address.
The merge-base changed after approval.
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
Fixes #1509