Skip to content

Commit 24f77fc

Browse files
🐛 Remove the check for HCloudCredentialsInvalid to unblock reconcilement (#1930)
* remove the check for `HCloudCredentialsInvalid` to unblock reconcilement Currently, we skip reconciling HCloudMachine completely if the condition `HCloudTokenAvailable` is set to false with reason `HCloudCredentialsInvalid`. This means that even when the CAPH controller restarts, the HCloudMachine is not reconciled. We don't want this behaviour, as on CAPH restart we want to reconcile all the related objects. Therefore, the early check that skips reconciliation based on the condition is removed. Note that this does not cause repeated reconciliation attempts with invalid credentials as we still stop reconciling immediately after setting the `HCloudCredentialsInvalid` condition during the normal reconcile loop. The only difference is that we no longer prevent reconciliation from starting based on a previously set condition. Signed-off-by: Dhairya Arora <dhairya.arora@syself.com> * if credentials are invalid on delete, set HCloudCredentialsInvalid condition --------- Signed-off-by: Dhairya Arora <dhairya.arora@syself.com>
1 parent a271b44 commit 24f77fc

2 files changed

Lines changed: 7 additions & 9 deletions

File tree

controllers/hcloudmachine_controller.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,6 @@ func (r *HCloudMachineReconciler) Reconcile(ctx context.Context, req reconcile.R
100100

101101
log = log.WithValues("Machine", klog.KObj(machine))
102102

103-
// If the HCloudMachine has an unauthorized / HCloudCredentialsInvalid error, stop reconciling.
104-
// There is no point in retrying API calls with an invalid token.
105-
// The MachineHealthCheck will eventually remediate the machine by deleting and recreating it.
106-
if conditions.IsFalse(hcloudMachine, infrav1.HCloudTokenAvailableCondition) &&
107-
conditions.GetReason(hcloudMachine, infrav1.HCloudTokenAvailableCondition) == infrav1.HCloudCredentialsInvalidReason {
108-
log.Info("HCloudMachine has HCloudCredentialsInvalid, stopping reconciliation")
109-
return reconcile.Result{}, nil
110-
}
111-
112103
// Fetch the Cluster.
113104
cluster, err := util.GetClusterFromMetadata(ctx, r.Client, machine.ObjectMeta)
114105
if err != nil {
@@ -167,6 +158,8 @@ func (r *HCloudMachineReconciler) Reconcile(ctx context.Context, req reconcile.R
167158
defer func() {
168159
if reterr != nil && errors.Is(reterr, hcloudclient.ErrUnauthorized) {
169160
conditions.MarkFalse(hcloudMachine, infrav1.HCloudTokenAvailableCondition, infrav1.HCloudCredentialsInvalidReason, clusterv1.ConditionSeverityError, "wrong hcloud token")
161+
// set reterr as nil, so that we don't get stuck in an infinite reconciliation loop if HCloud token is invalid.
162+
reterr = nil
170163
} else {
171164
conditions.MarkTrue(hcloudMachine, infrav1.HCloudTokenAvailableCondition)
172165
}

pkg/services/hcloud/server/server.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -277,6 +277,11 @@ func handleRateLimit(hm *infrav1.HCloudMachine, err error, functionName string,
277277

278278
// Delete implements delete method of server.
279279
func (s *Service) Delete(ctx context.Context) (res reconcile.Result, err error) {
280+
// Nothing to do, if ProviderID is nil
281+
if s.scope.HCloudMachine.Spec.ProviderID == nil {
282+
return reconcile.Result{}, nil
283+
}
284+
280285
server, err := s.findServer(ctx)
281286
if err != nil {
282287
return reconcile.Result{}, handleRateLimit(s.scope.HCloudMachine, err, "findServer", "failed to find server for deletion", s.scope.Logger)

0 commit comments

Comments
 (0)