zalando / postgres-operator

Postgres operator creates and manages PostgreSQL clusters running in Kubernetes
https://postgres-operator.readthedocs.io/
MIT License
4.38k stars 980 forks source link

sync all resources to cluster fields #2713

Closed FxKu closed 3 months ago

FxKu commented 3 months ago

While developing owner references support I realized once again that we store many child resources as cluster objects so we can access them even after the manifest is gone. But not for all resources, which might cause issues when deleting them because c.Namespace field might be empty:

time="2024-08-01T12:32:33Z" level=debug msg="removing leftover Patroni objects (endpoints / services and configmaps)" cluster-name=default/acid-clone-cluster pkg=cluster worker=2
time="2024-08-01T12:32:33Z" level=warning msg="could not fetch service \"/\": an empty namespace may not be set when a resource name is provided" cluster-name=default/acid-clone-cluster pkg=cluster worker=2

Fixing it for missing resources such as logical backup cron job and streams is easy. But it gets a bit tricky with objects created by Patroni, namely config service/endpoint and optionally configmaps. This PR introduces extra sync treatment for these, but only mapping to cluster fields. No diffs, no updates. This should allow us to loop over them on deletion.

Some more minor changes:

The streams feature saw some bigger refactoring:

fixes #2719

hughcapet commented 3 months ago

not true anymore? https://github.com/zalando/postgres-operator/blob/a87307e56b264a7e107b1c52c6b4ded5eea8f0eb/e2e/tests/test_e2e.py#L1678

(+ add Patroni objects to check_cluster_child_resources_owner_references() in e2e and add config service/endpoints and configmaps to the TestInheritedAnnotations unit test)

FxKu commented 3 months ago

:+1:

hughcapet commented 3 months ago

👍

hughcapet commented 3 months ago

👍