Skip to content

Commit 0c3b1a6

Browse files
committed
fix misleading condition if legacy cluster is not found
1 parent bf98494 commit 0c3b1a6

1 file changed

Lines changed: 22 additions & 7 deletions

File tree

percona/controller/pgcluster/owner_ref_migration.go

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,28 @@ func (r *PGClusterReconciler) reconcileOwnerRefMigrationStatus(ctx context.Conte
7171
return errors.Wrap(err, "discover legacy PostgresCluster GVK")
7272
}
7373

74+
legacy := &unstructured.Unstructured{}
75+
legacy.SetGroupVersionKind(LegacyGVK)
76+
77+
if err := r.Client.Get(ctx, types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, legacy); err != nil {
78+
if apierrors.IsNotFound(err) {
79+
err := setStatusCondition(ctx, r.Client, cr, metav1.Condition{
80+
Type: "APIGroupMigration",
81+
Status: metav1.ConditionTrue,
82+
Reason: "APIGroupMigrationNotNeeded",
83+
Message: "Legacy PostgresCluster not found",
84+
ObservedGeneration: cr.GetGeneration(),
85+
})
86+
if err != nil {
87+
return errors.Wrap(err, "set status condition to true")
88+
}
89+
90+
return nil
91+
}
92+
93+
return errors.Wrap(err, "get legacy PostgresCluster")
94+
}
95+
7496
err := setStatusCondition(ctx, r.Client, cr, metav1.Condition{
7597
Type: "APIGroupMigration",
7698
Status: metav1.ConditionFalse,
@@ -82,13 +104,6 @@ func (r *PGClusterReconciler) reconcileOwnerRefMigrationStatus(ctx context.Conte
82104
return errors.Wrap(err, "set status condition to false")
83105
}
84106

85-
legacy := &unstructured.Unstructured{}
86-
legacy.SetGroupVersionKind(LegacyGVK)
87-
88-
if err := r.Client.Get(ctx, types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, legacy); err != nil {
89-
return client.IgnoreNotFound(err)
90-
}
91-
92107
newPC := &v1beta1.PostgresCluster{}
93108
err = r.Client.Get(ctx, types.NamespacedName{Name: cr.Name, Namespace: cr.Namespace}, newPC)
94109
switch {

0 commit comments

Comments
 (0)