Skip to content

Commit 4b3b3f7

Browse files
committed
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.
1 parent 76f09b1 commit 4b3b3f7

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

pkg/controller/postgresuser/postgresuser_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,11 +325,11 @@ func (r *ReconcilePostgresUser) getPostgresCR(instance *dbv1alpha1.PostgresUser)
325325
database := dbv1alpha1.Postgres{}
326326
err := r.client.Get(context.TODO(),
327327
types.NamespacedName{Namespace: instance.Namespace, Name: instance.Spec.Database}, &database)
328-
if !utils.MatchesInstanceAnnotation(database.Annotations, r.instanceFilter) {
329-
err = fmt.Errorf("database \"%s\" is not managed by this operator", database.Name)
328+
if err != nil {
330329
return nil, err
331330
}
332-
if err != nil {
331+
if !utils.MatchesInstanceAnnotation(database.Annotations, r.instanceFilter) {
332+
err = fmt.Errorf("database \"%s\" is not managed by this operator", database.Name)
333333
return nil, err
334334
}
335335
if !database.Status.Succeeded {

0 commit comments

Comments
 (0)