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

🌱 Fix error handling when the resource is not found #10907

Merged
merged 10 commits into from
Aug 27, 2024
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques

// Look up the owner of this kubeadm config if there is one
configOwner, err := bsutil.GetTypedConfigOwner(ctx, r.Client, config)
if apierrors.IsNotFound(err) {
// Could not find the owner yet, this is not an error and will rereconcile when the owner gets set.
return ctrl.Result{}, nil
}
if err != nil {
if apierrors.IsNotFound(err) {
// Could not find the owner yet, this is not an error and will rereconcile when the owner gets set.
return ctrl.Result{}, nil
}
return ctrl.Result{}, errors.Wrapf(err, "failed to get owner")
}
if configOwner == nil {
Expand Down
8 changes: 5 additions & 3 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,21 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.
if apierrors.IsNotFound(err) {
return ctrl.Result{}, nil
}
return ctrl.Result{Requeue: true}, nil
return ctrl.Result{}, err
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
sbueringer marked this conversation as resolved.
Show resolved Hide resolved
}

// Fetch the Cluster.
cluster, err := util.GetOwnerCluster(ctx, r.Client, kcp.ObjectMeta)
if err != nil {
log.Error(err, "Failed to retrieve owner Cluster from the API Server")
return ctrl.Result{}, err
// It should be an issue to be investigated if the controller get the NotFound status.
// So, it should return the error.
return ctrl.Result{}, errors.Wrapf(err, "failed to retrieve owner Cluster")
}
if cluster == nil {
log.Info("Cluster Controller has not yet set OwnerRef")
return ctrl.Result{}, nil
}

log = log.WithValues("Cluster", klog.KObj(cluster))
ctx = ctrl.LoggerInto(ctx, log)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re
}

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

Expand Down
Loading