From 4b3b3f72d9b55b75ea7a7ae086bbdf61d5a5bf15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20Depriester?= Date: Fri, 8 Dec 2023 16:14:58 +0100 Subject: [PATCH] fix(postgresuser): return k8s client error before annotations In the GetPostgresCR function, we should return the k8s client error before checking the annotations. If not, deleting a Postgres resource will cause the linked PostgresUsers to enter an infinite reconciliation loop as the CR NotFound error will never be returned to the Reconcile function. --- pkg/controller/postgresuser/postgresuser_controller.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pkg/controller/postgresuser/postgresuser_controller.go b/pkg/controller/postgresuser/postgresuser_controller.go index ffd04ec2..82784249 100644 --- a/pkg/controller/postgresuser/postgresuser_controller.go +++ b/pkg/controller/postgresuser/postgresuser_controller.go @@ -325,11 +325,11 @@ func (r *ReconcilePostgresUser) getPostgresCR(instance *dbv1alpha1.PostgresUser) database := dbv1alpha1.Postgres{} err := r.client.Get(context.TODO(), types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Database}, &database) - if !utils.MatchesInstanceAnnotation(database.Annotations, r.instanceFilter) { - err = fmt.Errorf("database \"%s\" is not managed by this operator", database.Name) + if err != nil { return nil, err } - if err != nil { + if !utils.MatchesInstanceAnnotation(database.Annotations, r.instanceFilter) { + err = fmt.Errorf("database \"%s\" is not managed by this operator", database.Name) return nil, err } if !database.Status.Succeeded {