diff --git a/internal/controllers/topology/cluster/cluster_controller.go b/internal/controllers/topology/cluster/cluster_controller.go index b600e6e56dcb..6d6b5b8efaed 100644 --- a/internal/controllers/topology/cluster/cluster_controller.go +++ b/internal/controllers/topology/cluster/cluster_controller.go @@ -164,12 +164,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re return ctrl.Result{}, nil } - // In case the object is deleted, the managed topology stops to reconcile; - // (the other controllers will take care of deletion). - if !cluster.ObjectMeta.DeletionTimestamp.IsZero() { - return r.reconcileDelete(ctx, cluster) - } - patchHelper, err := patch.NewHelper(cluster, r.Client) if err != nil { return ctrl.Result{}, err @@ -204,6 +198,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re func (r *Reconciler) reconcile(ctx context.Context, s *scope.Scope) (ctrl.Result, error) { var err error + // in case the object is deleted, the managed topology stops to reconcile; + // (the other controllers will take care of deletion). + + if !s.Current.Cluster.ObjectMeta.DeletionTimestamp.IsZero() { + return r.reconcileDelete(ctx, s.Current.Cluster) + } + // Get ClusterClass. clusterClass := &clusterv1.ClusterClass{} key := client.ObjectKey{Name: s.Current.Cluster.Spec.Topology.Class, Namespace: s.Current.Cluster.Namespace} diff --git a/internal/controllers/topology/cluster/conditions.go b/internal/controllers/topology/cluster/conditions.go index 4157c012ad30..e22442e28f91 100644 --- a/internal/controllers/topology/cluster/conditions.go +++ b/internal/controllers/topology/cluster/conditions.go @@ -43,6 +43,20 @@ func (r *Reconciler) reconcileConditions(s *scope.Scope, cluster *clusterv1.Clus // In such a case, since some of the component's spec would be adrift from the topology the // topology cannot be considered fully reconciled. func (r *Reconciler) reconcileTopologyReconciledCondition(s *scope.Scope, cluster *clusterv1.Cluster, reconcileErr error) error { + + // Mark TopologyReconciled as false due to cluster deletion + if !cluster.ObjectMeta.DeletionTimestamp.IsZero() { + conditions.Set( + cluster, + conditions.FalseCondition( + clusterv1.TopologyReconciledCondition, + clusterv1.DeletedReason, + clusterv1.ConditionSeverityInfo, + "", + ), + ) + return nil + } // If an error occurred during reconciliation set the TopologyReconciled condition to false. // Add the error message from the reconcile function to the message of the condition. if reconcileErr != nil { diff --git a/internal/controllers/topology/cluster/conditions_test.go b/internal/controllers/topology/cluster/conditions_test.go index caf6e6378132..414bc05146ee 100644 --- a/internal/controllers/topology/cluster/conditions_test.go +++ b/internal/controllers/topology/cluster/conditions_test.go @@ -32,6 +32,7 @@ import ( ) func TestReconcileTopologyReconciledCondition(t *testing.T) { + deletionTime := metav1.Unix(0, 0) tests := []struct { name string reconcileErr error @@ -618,6 +619,17 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) { }, wantConditionStatus: corev1.ConditionTrue, }, + { + name: "should set the TopologyReconciledCondition to False if the cluster has been deleted", + cluster: &clusterv1.Cluster{ + ObjectMeta: metav1.ObjectMeta{ + DeletionTimestamp: &deletionTime, + }, + }, + wantConditionStatus: corev1.ConditionFalse, + wantConditionReason: clusterv1.DeletedReason, + wantConditionMessage: "", + }, } for _, tt := range tests {