Skip to content

Commit 12b75cd

Browse files
authored
🌱 Fix error handling when the resource is not found (#10907)
* fix: error handling when the resource is not found Signed-off-by: sivchari <[email protected]> * fix: test * fix: owner cluster handling Signed-off-by: sivchari <[email protected]> * remove duplicated error Signed-off-by: sivchari <[email protected]> * remove log variable Signed-off-by: sivchari <[email protected]> * fix error handling when the controller reads the cluster Signed-off-by: sivchari <[email protected]> * revert test modification Signed-off-by: sivchari <[email protected]> * delete log Signed-off-by: sivchari <[email protected]> * remove unnecessary deletion Signed-off-by: sivchari <[email protected]> * add detail of error Signed-off-by: sivchari <[email protected]> --------- Signed-off-by: sivchari <[email protected]>
1 parent ccef823 commit 12b75cd

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,11 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques
157157

158158
// Look up the owner of this kubeadm config if there is one
159159
configOwner, err := bsutil.GetTypedConfigOwner(ctx, r.Client, config)
160-
if apierrors.IsNotFound(err) {
161-
// Could not find the owner yet, this is not an error and will rereconcile when the owner gets set.
162-
return ctrl.Result{}, nil
163-
}
164160
if err != nil {
161+
if apierrors.IsNotFound(err) {
162+
// Could not find the owner yet, this is not an error and will rereconcile when the owner gets set.
163+
return ctrl.Result{}, nil
164+
}
165165
return ctrl.Result{}, errors.Wrapf(err, "failed to get owner")
166166
}
167167
if configOwner == nil {

controlplane/kubeadm/internal/controllers/controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -145,19 +145,21 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
145145
if apierrors.IsNotFound(err) {
146146
return ctrl.Result{}, nil
147147
}
148-
return ctrl.Result{Requeue: true}, nil
148+
return ctrl.Result{}, err
149149
}
150150

151151
// Fetch the Cluster.
152152
cluster, err := util.GetOwnerCluster(ctx, r.Client, kcp.ObjectMeta)
153153
if err != nil {
154-
log.Error(err, "Failed to retrieve owner Cluster from the API Server")
155-
return ctrl.Result{}, err
154+
// It should be an issue to be investigated if the controller get the NotFound status.
155+
// So, it should return the error.
156+
return ctrl.Result{}, errors.Wrapf(err, "failed to retrieve owner Cluster")
156157
}
157158
if cluster == nil {
158159
log.Info("Cluster Controller has not yet set OwnerRef")
159160
return ctrl.Result{}, nil
160161
}
162+
161163
log = log.WithValues("Cluster", klog.KObj(cluster))
162164
ctx = ctrl.LoggerInto(ctx, log)
163165

internal/controllers/machinehealthcheck/machinehealthcheck_controller.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
126126
}
127127

128128
// Error reading the object - requeue the request.
129-
log.Error(err, "Failed to fetch MachineHealthCheck")
130129
return ctrl.Result{}, err
131130
}
132131

0 commit comments

Comments
 (0)