Skip to content

Commit 30191f4

Browse files
committed
set TopologyReconciled to false on cluster deletion
1 parent 7a55e75 commit 30191f4

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

internal/controllers/topology/cluster/cluster_controller.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,12 +164,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
164164
return ctrl.Result{}, nil
165165
}
166166

167-
// In case the object is deleted, the managed topology stops to reconcile;
168-
// (the other controllers will take care of deletion).
169-
if !cluster.ObjectMeta.DeletionTimestamp.IsZero() {
170-
return r.reconcileDelete(ctx, cluster)
171-
}
172-
173167
patchHelper, err := patch.NewHelper(cluster, r.Client)
174168
if err != nil {
175169
return ctrl.Result{}, err
@@ -196,6 +190,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
196190
}
197191
}()
198192

193+
// In case the object is deleted, the managed topology stops to reconcile;
194+
// (the other controllers will take care of deletion).
195+
if !cluster.ObjectMeta.DeletionTimestamp.IsZero() {
196+
return r.reconcileDelete(ctx, cluster)
197+
}
198+
199199
// Handle normal reconciliation loop.
200200
return r.reconcile(ctx, s)
201201
}

internal/controllers/topology/cluster/conditions.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ func (r *Reconciler) reconcileConditions(s *scope.Scope, cluster *clusterv1.Clus
4343
// In such a case, since some of the component's spec would be adrift from the topology the
4444
// topology cannot be considered fully reconciled.
4545
func (r *Reconciler) reconcileTopologyReconciledCondition(s *scope.Scope, cluster *clusterv1.Cluster, reconcileErr error) error {
46+
// Mark TopologyReconciled as false due to cluster deletion.
47+
if !cluster.ObjectMeta.DeletionTimestamp.IsZero() {
48+
conditions.Set(
49+
cluster,
50+
conditions.FalseCondition(
51+
clusterv1.TopologyReconciledCondition,
52+
clusterv1.DeletedReason,
53+
clusterv1.ConditionSeverityInfo,
54+
"",
55+
),
56+
)
57+
return nil
58+
}
4659
// If an error occurred during reconciliation set the TopologyReconciled condition to false.
4760
// Add the error message from the reconcile function to the message of the condition.
4861
if reconcileErr != nil {

internal/controllers/topology/cluster/conditions_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) {
3939
scheme := runtime.NewScheme()
4040
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed())
4141

42+
deletionTime := metav1.Unix(0, 0)
4243
tests := []struct {
4344
name string
4445
reconcileErr error
@@ -585,6 +586,17 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) {
585586
},
586587
wantConditionStatus: corev1.ConditionTrue,
587588
},
589+
{
590+
name: "should set the TopologyReconciledCondition to False if the cluster has been deleted",
591+
cluster: &clusterv1.Cluster{
592+
ObjectMeta: metav1.ObjectMeta{
593+
DeletionTimestamp: &deletionTime,
594+
},
595+
},
596+
wantConditionStatus: corev1.ConditionFalse,
597+
wantConditionReason: clusterv1.DeletedReason,
598+
wantConditionMessage: "",
599+
},
588600
}
589601

590602
for _, tt := range tests {

0 commit comments

Comments
 (0)