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 {