Skip to content

Commit

Permalink
🌱 Fix error handling when the resource is not found (#10907)
Browse files Browse the repository at this point in the history
* fix: error handling when the resource is not found

Signed-off-by: sivchari <shibuuuu5@gmail.com>

* fix: test

* fix: owner cluster handling

Signed-off-by: sivchari <shibuuuu5@gmail.com>

* remove duplicated error

Signed-off-by: sivchari <shibuuuu5@gmail.com>

* remove log variable

Signed-off-by: sivchari <shibuuuu5@gmail.com>

* fix error handling when the controller reads the cluster

Signed-off-by: sivchari <shibuuuu5@gmail.com>

* revert test modification

Signed-off-by: sivchari <shibuuuu5@gmail.com>

* delete log

Signed-off-by: sivchari <shibuuuu5@gmail.com>

* remove unnecessary deletion

Signed-off-by: sivchari <shibuuuu5@gmail.com>

* add detail of error

Signed-off-by: sivchari <shibuuuu5@gmail.com>

---------

Signed-off-by: sivchari <shibuuuu5@gmail.com>
  • Loading branch information
sivchari authored Aug 27, 2024
1 parent ccef823 commit 12b75cd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
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
}

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

0 comments on commit 12b75cd

Please sign in to comment.