From 3d3199b47802c7bc07d1dfab92354bd4ca8e5308 Mon Sep 17 00:00:00 2001 From: sivchari Date: Fri, 19 Jul 2024 11:08:39 +0900 Subject: [PATCH 01/10] fix: error handling when the resource is not found Signed-off-by: sivchari --- .../controllers/kubeadmconfig_controller.go | 11 +++++++---- .../kubeadm/internal/controllers/controller.go | 14 +++++++++----- internal/controllers/cluster/cluster_controller.go | 1 + .../clusterclass/clusterclass_controller.go | 1 + internal/controllers/machine/machine_controller.go | 3 +++ .../machinedeployment_controller.go | 1 + .../machineset/machineset_controller.go | 3 +++ 7 files changed, 25 insertions(+), 9 deletions(-) diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go index 435bf03f644d..fa24423b863f 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go @@ -152,16 +152,19 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques if apierrors.IsNotFound(err) { return ctrl.Result{}, nil } + // Error reading the object - requeue the request. + log.Error(err, "Failed to fetch KubeadmConfig") return ctrl.Result{}, err } // 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 + } + log.Error(err, "Failed to retrieve owner Cluster from the API Server") 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..b8c2cefd8a03 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -145,19 +145,23 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl. if apierrors.IsNotFound(err) { return ctrl.Result{}, nil } - return ctrl.Result{Requeue: true}, nil + + // Error reading the object - requeue the request. + log.Error(err, "Failed to fetch KubeadmControlPlane") + return ctrl.Result{}, err } // Fetch the Cluster. cluster, err := util.GetOwnerCluster(ctx, r.Client, kcp.ObjectMeta) if err != nil { + if apierrors.IsNotFound(err) { + log.Info("Cluster Controller has not yet set OwnerRef") + return ctrl.Result{}, nil + } log.Error(err, "Failed to retrieve owner Cluster from the API Server") return ctrl.Result{}, err } - 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/cluster/cluster_controller.go b/internal/controllers/cluster/cluster_controller.go index 452cfe9c0521..0fff70e9bf85 100644 --- a/internal/controllers/cluster/cluster_controller.go +++ b/internal/controllers/cluster/cluster_controller.go @@ -112,6 +112,7 @@ 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 Cluster") return ctrl.Result{}, err } diff --git a/internal/controllers/clusterclass/clusterclass_controller.go b/internal/controllers/clusterclass/clusterclass_controller.go index 9fc0c5a0ef11..e5e485788d55 100644 --- a/internal/controllers/clusterclass/clusterclass_controller.go +++ b/internal/controllers/clusterclass/clusterclass_controller.go @@ -96,6 +96,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re return ctrl.Result{}, nil } // Error reading the object - requeue the request. + log.Error(err, "Failed to fetch ClusterClass") return ctrl.Result{}, err } diff --git a/internal/controllers/machine/machine_controller.go b/internal/controllers/machine/machine_controller.go index 2dbbd916713b..4309eab6918d 100644 --- a/internal/controllers/machine/machine_controller.go +++ b/internal/controllers/machine/machine_controller.go @@ -152,6 +152,8 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt } func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) { + log := ctrl.LoggerFrom(ctx) + // Fetch the Machine instance m := &clusterv1.Machine{} if err := r.Client.Get(ctx, req.NamespacedName, m); err != nil { @@ -162,6 +164,7 @@ 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 Machine") return ctrl.Result{}, err } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller.go b/internal/controllers/machinedeployment/machinedeployment_controller.go index 99629642da81..0a3fe03b3889 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller.go @@ -119,6 +119,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re return ctrl.Result{}, nil } // Error reading the object - requeue the request. + log.Error(err, "Failed to fetch MachineDeployment") return ctrl.Result{}, err } diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index e5d802fcbb28..2ee231e54181 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -133,6 +133,8 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt } func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) { + log := ctrl.LoggerFrom(ctx) + machineSet := &clusterv1.MachineSet{} if err := r.Client.Get(ctx, req.NamespacedName, machineSet); err != nil { if apierrors.IsNotFound(err) { @@ -141,6 +143,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re return ctrl.Result{}, nil } // Error reading the object - requeue the request. + log.Error(err, "Failed to fetch MachineSet") return ctrl.Result{}, err } From 34989ac5016498210bc36f5f47aba3150ce36277 Mon Sep 17 00:00:00 2001 From: sivchari Date: Fri, 19 Jul 2024 11:28:11 +0900 Subject: [PATCH 02/10] fix: test --- controlplane/kubeadm/internal/controllers/controller_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/controlplane/kubeadm/internal/controllers/controller_test.go b/controlplane/kubeadm/internal/controllers/controller_test.go index 5a3c8971f632..4b2af2777302 100644 --- a/controlplane/kubeadm/internal/controllers/controller_test.go +++ b/controlplane/kubeadm/internal/controllers/controller_test.go @@ -136,7 +136,7 @@ func TestClusterToKubeadmControlPlaneOtherControlPlane(t *testing.T) { g.Expect(got).To(BeNil()) } -func TestReconcileReturnErrorWhenOwnerClusterIsMissing(t *testing.T) { +func TestReconcileDoesNothingWhenOwnerClusterIsMissing(t *testing.T) { g := NewWithT(t) ns, err := env.CreateNamespace(ctx, "test-reconcile-return-error") @@ -165,7 +165,7 @@ func TestReconcileReturnErrorWhenOwnerClusterIsMissing(t *testing.T) { g.Eventually(func() error { _, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)}) return err - }, 10*time.Second).Should(HaveOccurred()) + }, 10*time.Second).Should(BeNil()) } func TestReconcileUpdateObservedGeneration(t *testing.T) { From 0b2867b4eac4754941a7d114ab3a4d3d156188ed Mon Sep 17 00:00:00 2001 From: sivchari Date: Fri, 19 Jul 2024 11:45:04 +0900 Subject: [PATCH 03/10] fix: owner cluster handling Signed-off-by: sivchari --- .../kubeadm/internal/controllers/controller.go | 12 +++++++----- .../kubeadm/internal/controllers/controller_test.go | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/controlplane/kubeadm/internal/controllers/controller.go b/controlplane/kubeadm/internal/controllers/controller.go index b8c2cefd8a03..0df5566d0e54 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -154,12 +154,14 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl. // Fetch the Cluster. cluster, err := util.GetOwnerCluster(ctx, r.Client, kcp.ObjectMeta) if err != nil { - if apierrors.IsNotFound(err) { - log.Info("Cluster Controller has not yet set OwnerRef") - return ctrl.Result{}, nil + if !apierrors.IsNotFound(err) { + log.Error(err, "Failed to retrieve owner Cluster from the API Server") + return ctrl.Result{}, err } - log.Error(err, "Failed to retrieve owner Cluster from the API Server") - return ctrl.Result{}, err + } + if apierrors.IsNotFound(err) || cluster == nil { + log.Info("Cluster Controller has not yet set OwnerRef") + return ctrl.Result{}, nil } log = log.WithValues("Cluster", klog.KObj(cluster)) diff --git a/controlplane/kubeadm/internal/controllers/controller_test.go b/controlplane/kubeadm/internal/controllers/controller_test.go index 4b2af2777302..35ed87d2f92c 100644 --- a/controlplane/kubeadm/internal/controllers/controller_test.go +++ b/controlplane/kubeadm/internal/controllers/controller_test.go @@ -343,7 +343,7 @@ func TestReconcileNoCluster(t *testing.T) { } _, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)}) - g.Expect(err).To(HaveOccurred()) + g.Expect(err).ToNot(HaveOccurred()) machineList := &clusterv1.MachineList{} g.Expect(fakeClient.List(ctx, machineList, client.InNamespace(metav1.NamespaceDefault))).To(Succeed()) From 38390e491eca28c3d378d856570b34546ab4da0f Mon Sep 17 00:00:00 2001 From: sivchari Date: Fri, 19 Jul 2024 16:53:06 +0900 Subject: [PATCH 04/10] remove duplicated error Signed-off-by: sivchari --- .../kubeadm/internal/controllers/kubeadmconfig_controller.go | 3 --- controlplane/kubeadm/internal/controllers/controller.go | 4 ---- internal/controllers/clusterclass/clusterclass_controller.go | 2 -- internal/controllers/machine/machine_controller.go | 3 --- .../machinedeployment/machinedeployment_controller.go | 2 -- .../machinehealthcheck/machinehealthcheck_controller.go | 3 --- internal/controllers/machineset/machineset_controller.go | 2 -- 7 files changed, 19 deletions(-) diff --git a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go index fa24423b863f..7c39fa4d71d6 100644 --- a/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go +++ b/bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go @@ -152,8 +152,6 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques if apierrors.IsNotFound(err) { return ctrl.Result{}, nil } - // Error reading the object - requeue the request. - log.Error(err, "Failed to fetch KubeadmConfig") return ctrl.Result{}, err } @@ -164,7 +162,6 @@ func (r *KubeadmConfigReconciler) Reconcile(ctx context.Context, req ctrl.Reques // Could not find the owner yet, this is not an error and will rereconcile when the owner gets set. return ctrl.Result{}, nil } - log.Error(err, "Failed to retrieve owner Cluster from the API Server") 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 0df5566d0e54..24061f3f1214 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -145,9 +145,6 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl. if apierrors.IsNotFound(err) { return ctrl.Result{}, nil } - - // Error reading the object - requeue the request. - log.Error(err, "Failed to fetch KubeadmControlPlane") return ctrl.Result{}, err } @@ -155,7 +152,6 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl. cluster, err := util.GetOwnerCluster(ctx, r.Client, kcp.ObjectMeta) if err != nil { if !apierrors.IsNotFound(err) { - log.Error(err, "Failed to retrieve owner Cluster from the API Server") return ctrl.Result{}, err } } diff --git a/internal/controllers/clusterclass/clusterclass_controller.go b/internal/controllers/clusterclass/clusterclass_controller.go index e5e485788d55..9d5eae6fd235 100644 --- a/internal/controllers/clusterclass/clusterclass_controller.go +++ b/internal/controllers/clusterclass/clusterclass_controller.go @@ -95,8 +95,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re if apierrors.IsNotFound(err) { return ctrl.Result{}, nil } - // Error reading the object - requeue the request. - log.Error(err, "Failed to fetch ClusterClass") return ctrl.Result{}, err } diff --git a/internal/controllers/machine/machine_controller.go b/internal/controllers/machine/machine_controller.go index 4309eab6918d..eab2938ae597 100644 --- a/internal/controllers/machine/machine_controller.go +++ b/internal/controllers/machine/machine_controller.go @@ -162,9 +162,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // For additional cleanup logic use finalizers. return ctrl.Result{}, nil } - - // Error reading the object - requeue the request. - log.Error(err, "failed to fetch Machine") return ctrl.Result{}, err } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller.go b/internal/controllers/machinedeployment/machinedeployment_controller.go index 0a3fe03b3889..02d4f2ff3cf4 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller.go @@ -118,8 +118,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // For additional cleanup logic use finalizers. return ctrl.Result{}, nil } - // Error reading the object - requeue the request. - log.Error(err, "Failed to fetch MachineDeployment") return ctrl.Result{}, err } diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go index 0065a969f560..510c201f4878 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -124,9 +124,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // For additional cleanup logic use finalizers. return ctrl.Result{}, nil } - - // Error reading the object - requeue the request. - log.Error(err, "Failed to fetch MachineHealthCheck") return ctrl.Result{}, err } diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index 2ee231e54181..b45e2199d7b5 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -142,8 +142,6 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // For additional cleanup logic use finalizers. return ctrl.Result{}, nil } - // Error reading the object - requeue the request. - log.Error(err, "Failed to fetch MachineSet") return ctrl.Result{}, err } From ca19b57bdbaf2a0cc4d77ac8c363379210f81e05 Mon Sep 17 00:00:00 2001 From: sivchari Date: Fri, 19 Jul 2024 23:14:42 +0900 Subject: [PATCH 05/10] remove log variable Signed-off-by: sivchari --- internal/controllers/machine/machine_controller.go | 2 -- internal/controllers/machineset/machineset_controller.go | 2 -- 2 files changed, 4 deletions(-) diff --git a/internal/controllers/machine/machine_controller.go b/internal/controllers/machine/machine_controller.go index eab2938ae597..4807d4712ba5 100644 --- a/internal/controllers/machine/machine_controller.go +++ b/internal/controllers/machine/machine_controller.go @@ -152,8 +152,6 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt } func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) { - log := ctrl.LoggerFrom(ctx) - // Fetch the Machine instance m := &clusterv1.Machine{} if err := r.Client.Get(ctx, req.NamespacedName, m); err != nil { diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index b45e2199d7b5..52c9595d424a 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -133,8 +133,6 @@ func (r *Reconciler) SetupWithManager(ctx context.Context, mgr ctrl.Manager, opt } func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Result, reterr error) { - log := ctrl.LoggerFrom(ctx) - machineSet := &clusterv1.MachineSet{} if err := r.Client.Get(ctx, req.NamespacedName, machineSet); err != nil { if apierrors.IsNotFound(err) { From 11bb972a4e9d17c1c424af6e23d874c4d47614eb Mon Sep 17 00:00:00 2001 From: sivchari Date: Sat, 3 Aug 2024 11:42:32 +0900 Subject: [PATCH 06/10] fix error handling when the controller reads the cluster Signed-off-by: sivchari --- controlplane/kubeadm/internal/controllers/controller.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/controlplane/kubeadm/internal/controllers/controller.go b/controlplane/kubeadm/internal/controllers/controller.go index 24061f3f1214..d23f7c6bf5a8 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -151,11 +151,11 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl. // Fetch the Cluster. cluster, err := util.GetOwnerCluster(ctx, r.Client, kcp.ObjectMeta) if err != nil { - if !apierrors.IsNotFound(err) { - 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{}, err } - if apierrors.IsNotFound(err) || cluster == nil { + if cluster == nil { log.Info("Cluster Controller has not yet set OwnerRef") return ctrl.Result{}, nil } From ad13de19fd2066f24183e1a8c79499557ef823e4 Mon Sep 17 00:00:00 2001 From: sivchari Date: Sat, 3 Aug 2024 11:44:43 +0900 Subject: [PATCH 07/10] revert test modification Signed-off-by: sivchari --- .../kubeadm/internal/controllers/controller_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/controlplane/kubeadm/internal/controllers/controller_test.go b/controlplane/kubeadm/internal/controllers/controller_test.go index 35ed87d2f92c..5a3c8971f632 100644 --- a/controlplane/kubeadm/internal/controllers/controller_test.go +++ b/controlplane/kubeadm/internal/controllers/controller_test.go @@ -136,7 +136,7 @@ func TestClusterToKubeadmControlPlaneOtherControlPlane(t *testing.T) { g.Expect(got).To(BeNil()) } -func TestReconcileDoesNothingWhenOwnerClusterIsMissing(t *testing.T) { +func TestReconcileReturnErrorWhenOwnerClusterIsMissing(t *testing.T) { g := NewWithT(t) ns, err := env.CreateNamespace(ctx, "test-reconcile-return-error") @@ -165,7 +165,7 @@ func TestReconcileDoesNothingWhenOwnerClusterIsMissing(t *testing.T) { g.Eventually(func() error { _, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)}) return err - }, 10*time.Second).Should(BeNil()) + }, 10*time.Second).Should(HaveOccurred()) } func TestReconcileUpdateObservedGeneration(t *testing.T) { @@ -343,7 +343,7 @@ func TestReconcileNoCluster(t *testing.T) { } _, err = r.Reconcile(ctx, ctrl.Request{NamespacedName: util.ObjectKey(kcp)}) - g.Expect(err).ToNot(HaveOccurred()) + g.Expect(err).To(HaveOccurred()) machineList := &clusterv1.MachineList{} g.Expect(fakeClient.List(ctx, machineList, client.InNamespace(metav1.NamespaceDefault))).To(Succeed()) From a8278151cf4b3a2c10fd27544b28ce31af89ea79 Mon Sep 17 00:00:00 2001 From: sivchari Date: Sat, 3 Aug 2024 11:46:26 +0900 Subject: [PATCH 08/10] delete log Signed-off-by: sivchari --- internal/controllers/cluster/cluster_controller.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/controllers/cluster/cluster_controller.go b/internal/controllers/cluster/cluster_controller.go index 0fff70e9bf85..452cfe9c0521 100644 --- a/internal/controllers/cluster/cluster_controller.go +++ b/internal/controllers/cluster/cluster_controller.go @@ -112,7 +112,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 Cluster") return ctrl.Result{}, err } From 32083e46a8b3dbf3e143445a811a619d9e889602 Mon Sep 17 00:00:00 2001 From: sivchari Date: Sat, 3 Aug 2024 11:47:52 +0900 Subject: [PATCH 09/10] remove unnecessary deletion Signed-off-by: sivchari --- internal/controllers/clusterclass/clusterclass_controller.go | 1 + internal/controllers/machine/machine_controller.go | 2 ++ .../machinedeployment/machinedeployment_controller.go | 1 + .../machinehealthcheck/machinehealthcheck_controller.go | 2 ++ internal/controllers/machineset/machineset_controller.go | 1 + 5 files changed, 7 insertions(+) diff --git a/internal/controllers/clusterclass/clusterclass_controller.go b/internal/controllers/clusterclass/clusterclass_controller.go index 9d5eae6fd235..9fc0c5a0ef11 100644 --- a/internal/controllers/clusterclass/clusterclass_controller.go +++ b/internal/controllers/clusterclass/clusterclass_controller.go @@ -95,6 +95,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re if apierrors.IsNotFound(err) { return ctrl.Result{}, nil } + // Error reading the object - requeue the request. return ctrl.Result{}, err } diff --git a/internal/controllers/machine/machine_controller.go b/internal/controllers/machine/machine_controller.go index 4807d4712ba5..2dbbd916713b 100644 --- a/internal/controllers/machine/machine_controller.go +++ b/internal/controllers/machine/machine_controller.go @@ -160,6 +160,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // For additional cleanup logic use finalizers. return ctrl.Result{}, nil } + + // Error reading the object - requeue the request. return ctrl.Result{}, err } diff --git a/internal/controllers/machinedeployment/machinedeployment_controller.go b/internal/controllers/machinedeployment/machinedeployment_controller.go index 02d4f2ff3cf4..99629642da81 100644 --- a/internal/controllers/machinedeployment/machinedeployment_controller.go +++ b/internal/controllers/machinedeployment/machinedeployment_controller.go @@ -118,6 +118,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // For additional cleanup logic use finalizers. return ctrl.Result{}, nil } + // Error reading the object - requeue the request. return ctrl.Result{}, err } diff --git a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go index 510c201f4878..ce7a18cc10f4 100644 --- a/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go +++ b/internal/controllers/machinehealthcheck/machinehealthcheck_controller.go @@ -124,6 +124,8 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // For additional cleanup logic use finalizers. return ctrl.Result{}, nil } + + // Error reading the object - requeue the request. return ctrl.Result{}, err } diff --git a/internal/controllers/machineset/machineset_controller.go b/internal/controllers/machineset/machineset_controller.go index 52c9595d424a..e5d802fcbb28 100644 --- a/internal/controllers/machineset/machineset_controller.go +++ b/internal/controllers/machineset/machineset_controller.go @@ -140,6 +140,7 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (_ ctrl.Re // For additional cleanup logic use finalizers. return ctrl.Result{}, nil } + // Error reading the object - requeue the request. return ctrl.Result{}, err } From 9eb3d90a8d32f35eff4d0142726d77ceaae26ceb Mon Sep 17 00:00:00 2001 From: sivchari Date: Wed, 21 Aug 2024 10:29:52 +0900 Subject: [PATCH 10/10] add detail of error Signed-off-by: sivchari --- controlplane/kubeadm/internal/controllers/controller.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/controlplane/kubeadm/internal/controllers/controller.go b/controlplane/kubeadm/internal/controllers/controller.go index d23f7c6bf5a8..39e5a7bb908d 100644 --- a/controlplane/kubeadm/internal/controllers/controller.go +++ b/controlplane/kubeadm/internal/controllers/controller.go @@ -153,7 +153,7 @@ func (r *KubeadmControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl. if err != nil { // It should be an issue to be investigated if the controller get the NotFound status. // So, it should return the error. - return ctrl.Result{}, err + return ctrl.Result{}, errors.Wrapf(err, "failed to retrieve owner Cluster") } if cluster == nil { log.Info("Cluster Controller has not yet set OwnerRef")