K8SPG-1057 refactor dcs - #1727
Conversation
|
the lint failure - this is the known Endpoints deprecation warning (Kubernetes recommends EndpointSlice going forward), not something introduced by this PR. @egegunes confirmed it's acceptable to leave as-is for now; tracked separately in K8SPG-866. I did name the dcs backend as |
commit: 3f15a9d |
|
honestly i don't think i like calling @mayankshah1607 please take a look when you have the chance |
As part of K8SPG-1057, Patroni's DCS logic is hard-coded to Kubernetes Endpoints throughout
internal/patroniandinternal/controller/postgrescluster- config generation, RBAC, Service reconciliation, and status observation all directly assume "Kubernetes DCS," with no seam between generic Patroni logic and DCS-specific behavior.Cause:
K8SPG-1057 - we want to add support for an additional DCS backend (etcd) in a follow-up stacked PR, but the current code has no ownership boundary to build that on without scattering
if-branches for the new backend across the reconciler.Solution:
Introduce a new package:
internal/patroni/dcsThis package becomes the single place that knows about specific DCS implementations.
It exposes a Backend interface. This PR ships one implementation, migrating the existing Kubernetes-Endpoints behavior into it with no functional change:
internal/patroni/dcs/kubernetes_endpoints.goA second implementation (etcd) is out of scope here and lands as a follow-up stacked PR on top of this one.
The backend is selected once per reconcile:
backend := dcs.For(cluster)After that, callers interact only with backend capabilities and do not know which DCS is active.
Backend-owned behavior migrated in this PR (Kubernetes Endpoints only; etcd column shows the target shape for the follow-up):
Design rules
Callers request capabilities (dcs.For(cluster).X(...)) and handle results generically - including the primary-Service routing seam (PrimaryService), which previously would have forced DCS-specific branching back into the controller.
Import direction
controller → patroni
controller → dcs → patroni
patroni does not import dcs. The controller wires the two together by passing backend-provided data (dcsYAML, dcsEnvVars, etc.) into existing patroni helpers.
No behavior change. Verified via: full build/vet clean, complete unit + envtest suite passing (internal/patroni, internal/patroni/dcs, internal/controller/postgrescluster), and make generate-rbac producing a zero diff against the generated ClusterRole.
CHECKLIST
Jira
Tests
Config/Logging/Testability