Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 update TopologyReconciled condition on cluster deletion #8422

Merged
merged 1 commit into from
May 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions internal/controllers/topology/cluster/cluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -196,6 +190,12 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
}
}()

// 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)
}

// Handle normal reconciliation loop.
return r.reconcile(ctx, s)
}
Expand Down
13 changes: 13 additions & 0 deletions internal/controllers/topology/cluster/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ 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 {
Expand Down
12 changes: 12 additions & 0 deletions internal/controllers/topology/cluster/conditions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ func TestReconcileTopologyReconciledCondition(t *testing.T) {
scheme := runtime.NewScheme()
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed())

deletionTime := metav1.Unix(0, 0)
tests := []struct {
name string
reconcileErr error
Expand Down Expand Up @@ -585,6 +586,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 {
Expand Down