Repository navigation
feat(controllers): set client Service trafficDistribution from an annotation - #377
Timofei Larkin (lllamnyp) wants to merge 1 commit into
Conversation
…otation The etcd-operator.cozystack.io/client-service-traffic-distribution annotation on an EtcdCluster sets spec.trafficDistribution on the <cluster>-client Service (PreferClose, PreferSameZone or PreferSameNode), so clients of a cluster stretched across zones prefer a nearby member. It stands in for a typed spec field without changing the API for now. The field is written with server-side apply under its own field manager, so removing the annotation clears it unless another manager also set it, and a value someone else set without the annotation is left alone. A value outside that set, one the apiserver rejects (PreferSameZone and PreferSameNode before 1.34) or one it drops (no support before 1.31) is reported as a Warning Event and leaves the field unset; the rest of the reconcile carries on. The headless Service is not touched. Builds on the controller tests and docs of #376 by Andrei Kvapil. Assisted-By: LLM Signed-off-by: Timofei Larkin <lllamnyp@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info
📝 Walkthrough
Merge Risk: ⚪ Minimal · up to
|
What
The
etcd-operator.cozystack.io/client-service-traffic-distributionannotation on anEtcdClustersetsspec.trafficDistributionon the<cluster>-clientService. In a cluster stretched across zones, clients then prefer a ready member in their own zone, or on their own node withPreferSameNode. There is no CRD, API type or schema change.Prior work
This builds on #376 by Andrei Kvapil (@kvaps), which adds the same capability as a typed
spec.clientService.trafficDistributionfield. Thank you for working out the use case, the version matrix and the test shape. Reused from #376:status.observed" decision;What's different here:
ensureServicesand so no longer blocks bootstrap, scaling and status updates for the whole cluster.Stopgap, and how it migrates
The annotation is a deliberate stopgap: the capability is needed now, and an API change is deferred for now. A typed field can replace it later. Migration would work like this: when both are set, the field wins. The annotation is deprecated, keeps working for a release or more, then is removed. Because both write through the same server-side-apply field manager, switching from one to the other doesn't flap the Service.
Behaviour
Values:
PreferClose(Kubernetes 1.31+),PreferSameZoneandPreferSameNode(1.34+). The operator builds against k8s.io/api 0.33, whose constants define all three.Ownership: the field is written with server-side apply under field manager
etcd-operator-traffic-distribution, and drift is reconciled back while the annotation is set. The operator's other Service writes are merge patches that never include this field. Removing the annotation releases the field, so it is cleared unless another manager also set it. A value set by hand on a cluster without the annotation is left alone. Clusters that don't use the annotation get no extra writes: ownership is checked frommanagedFieldsbefore any apply.Invalid values: the operator emits a
WarningEvent on theEtcdCluster, leaves the field unset and continues the reconcile:InvalidTrafficDistribution;PreferSameZoneon 1.33 (confirmed against the envtest 1.33 apiserver) →TrafficDistributionRejected;TrafficDistributionNotPersisted. In that case each reconcile repeats a no-op apply, which costs one request and no storage write.Transient errors still fail the reconcile so it is retried, as with every other Service write.
Updates apply on the next reconcile. The controller watches
EtcdClusterwithout a generation filter, so editing the annotation triggers a reconcile.Docs:
docs/concepts.md#client-service-traffic-distributioncovers the zone-label prerequisites on nodes, spreading members across zones, and proxy support.Testing
controllers/client_service_test.go(fake client) covers:controllers/client_service_envtest_test.goruns against a real 1.33 apiserver, because the fake client in controller-runtime 0.21 can't apply. It covers:PreferSameZonetakes whichever outcome the apiserver version gives.go test ./controllers/ .with envtest 1.33 passes.go vetandgofmtare clean, andmake manifests generateshows no drift: theeventsRBAC rule already existed.Summary by CodeRabbit