From 12b75cd84a802614b45c9f7e4ba4b4c4819f3107 Mon Sep 17 00:00:00 2001 From: sivchari Date: Tue, 27 Aug 2024 18:23:31 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=8C=B1=20=20Fix=20error=20handling=20when?= =?UTF-8?q?=20the=20resource=20is=20not=20found=20(#10907)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fix: error handling when the resource is not found Signed-off-by: sivchari * fix: test * fix: owner cluster handling Signed-off-by: sivchari * remove duplicated error Signed-off-by: sivchari * remove log variable Signed-off-by: sivchari * fix error handling when the controller reads the cluster Signed-off-by: sivchari * revert test modification Signed-off-by: sivchari * delete log Signed-off-by: sivchari * remove unnecessary deletion Signed-off-by: sivchari * add detail of error Signed-off-by: sivchari --------- Signed-off-by: sivchari --- .../internal/controllers/kubeadmconfig_controller.go | 8 ++++---- controlplane/kubeadm/internal/controllers/controller.go | 8 +++++--- .../machinehealthcheck/machinehealthcheck_controller.go | 1 - 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go index af698cad812f..b67c3f020370 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go @@ -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 { diff --git a/controlplane/kubeadm/internal/controllers/controller.go b/controlplane/kubeadm/internal/controllers/controller.go index a77071841c34..39e5a7bb908d 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -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) diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go index 0065a969f560..ce7a18cc10f4 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -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 }