zalando / postgres-operator

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

Failure to create when an ownerReference is set on postgresql cr #2768

Open bo0ts opened 1 month ago

bo0ts commented 1 month ago

Please, answer some short questions which should help us to understand your problem / question better?

I've tried creating a postgresql resource with an ownerReference set to another resource. This resulted in a failure to create the postgres instance with the following error message:

time="2024-09-27T12:00:14Z" level=info msg="creating a new Postgres cluster" cluster-name=my-namespace/my-postgres pkg=controller worker=5
time="2024-09-27T12:00:14Z" level=warning msg="cluster created failed: could not create master service: services \"my-postgres\" is forbidden: cannot set blockOwnerDeletion if an ownerReference refers to a resource you can't set finalizers on: , <nil>" cluster-name=my-namespace/my-postgres pkg=cluster worker=5

When I don't set an ownerReference on the postgresql resource the cluster creates without issue. Looking at a successfully created cluster I cannot see any ownerReferences set on the svc/my-postgres. The new owner references feature is not enabled in our environment.

bo0ts commented 1 month ago

Looking at https://github.com/zalando/postgres-operator/blob/master/pkg/cluster/k8sres.go#L2524 I understand why the error is happening: the operator tries to "forward" the ownerReference set on the CR, but I don't understand why it is doing that at all. The comment for the function also talks about the dependency on the CRD or StatefulSEt, but I assume it means the CR?