vshn / appcat-service-postgresql

AppCat Service Provider for PostgreSQL
https://vshn.github.io/appcat-service-postgresql/
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Deletion of postgrestandalone in loop #72

Closed zugao closed 2 years ago

zugao commented 2 years ago

Description

The deletion of postgresqlstandalone CRD is not possible when the connection secret was not created in the first place. This particular case can occur when a deletion operation is issued right after creation or in case the connection secret was not created for any other reason.

Additional Context

Connection secret is created during second reconciliation phase which means there is a time frame where the deletion is not possible with current version. When deletion happens on that particular moment, the field Name is empty thus the client returns resource name may not be empty error. See logs for further details.

Logs

2022-06-10T12:37:06.923Z | ERROR | provider-postgresql.operator | controller/controller.go:326 | Reconciler error | {"controller": "postgresqlstandalone.postgresql.appcat.vshn.io", "controllerGroup": "postgresql.appcat.vshn.io", "controllerKind": "PostgresqlStandalone", "postgresqlStandalone": {"name":"my-instance","namespace":"default"}, "namespace": "default", "name": "my-instance", "reconcileID": "bc25a635-d4bb-4b3d-8a5a-d6296737d066", "error": "step \"delete connection secret\" failed: resource name may not be empty"}
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).reconcileHandler
    /Users/gabrielsaratura/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.0/pkg/internal/controller/controller.go:326
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).processNextWorkItem
    /Users/gabrielsaratura/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.0/pkg/internal/controller/controller.go:273
sigs.k8s.io/controller-runtime/pkg/internal/controller.(*Controller).Start.func2.2
    /Users/gabrielsaratura/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.12.0/pkg/internal/controller/controller.go:234

Expected Behavior

Deletion is done successfully even when the writeConnectionSecretToRef is not populated.

Steps To Reproduce

make local-install install-samples &&  \
kind get kubeconfig --name appcat-service-postgresql-v1.24.0 > ~/.kube/config && \
sleep 3 && \
kubectl delete postgresqlstandalone my-instance -n default

Versions

master, latest

ccremer commented 2 years ago

ah, good catch! I guess in the deletion step we need to add an if that checks if the writeConnectionSecretToRef.Name is set, and if not, use the name that the webhook defaulter would use if unset https://github.com/vshn/appcat-service-postgresql/blob/e0c201ca5e9ca15f2a7ea726e3034fe461c0b7ac/operator/standalone/webhook_defaulter.go#L17