Skip to content

Commit

Permalink
Merge pull request #8422 from cahillsf/cahillsf/dev
Browse files Browse the repository at this point in the history
🐛 update TopologyReconciled condition on cluster deletion
  • Loading branch information
k8s-ci-robot authored May 17, 2023
2 parents cf8611e + 30191f4 commit d8c458a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
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

0 comments on commit d8c458a

Please sign in to comment.