From 1d72802abd48cc0d4143ed69018fa6a3748e550b Mon Sep 17 00:00:00 2001 From: Dario Tranchitella Date: Wed, 22 Jan 2025 11:08:01 +0100 Subject: [PATCH] refactor: avoid logging error and sentinel for status (#673) Signed-off-by: Dario Tranchitella --- controllers/tenantcontrolplane_controller.go | 6 ++++++ internal/resources/k8s_service_resource.go | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/controllers/tenantcontrolplane_controller.go b/controllers/tenantcontrolplane_controller.go index 1d441e3..92ddf0f 100644 --- a/controllers/tenantcontrolplane_controller.go +++ b/controllers/tenantcontrolplane_controller.go @@ -199,6 +199,12 @@ func (r *TenantControlPlaneReconciler) Reconcile(ctx context.Context, req ctrl.R } if err = utils.UpdateStatus(ctx, r.Client, tenantControlPlane, resource); err != nil { + if kamajierrors.ShouldReconcileErrorBeIgnored(err) { + log.V(1).Info("sentinel error, enqueuing back request", "error", err.Error()) + + return ctrl.Result{Requeue: true}, nil + } + log.Error(err, "update of the resource failed", "resource", resource.GetName()) return ctrl.Result{}, err diff --git a/internal/resources/k8s_service_resource.go b/internal/resources/k8s_service_resource.go index f854858..07e2f97 100644 --- a/internal/resources/k8s_service_resource.go +++ b/internal/resources/k8s_service_resource.go @@ -14,7 +14,6 @@ import ( "k8s.io/utils/ptr" "sigs.k8s.io/controller-runtime/pkg/client" "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" - "sigs.k8s.io/controller-runtime/pkg/log" kamajiv1alpha1 "github.com/clastix/kamaji/api/v1alpha1" "github.com/clastix/kamaji/internal/utilities" @@ -42,8 +41,6 @@ func (r *KubernetesServiceResource) CleanUp(context.Context, *kamajiv1alpha1.Ten } func (r *KubernetesServiceResource) UpdateTenantControlPlaneStatus(ctx context.Context, tenantControlPlane *kamajiv1alpha1.TenantControlPlane) error { - logger := log.FromContext(ctx, "resource", r.GetName()) - tenantControlPlane.Status.Kubernetes.Service.ServiceStatus = r.resource.Status tenantControlPlane.Status.Kubernetes.Service.Name = r.resource.GetName() tenantControlPlane.Status.Kubernetes.Service.Namespace = r.resource.GetNamespace() @@ -51,8 +48,6 @@ func (r *KubernetesServiceResource) UpdateTenantControlPlaneStatus(ctx context.C address, err := tenantControlPlane.DeclaredControlPlaneAddress(ctx, r.Client) if err != nil { - logger.Error(err, "cannot retrieve Tenant Control Plane address") - return err } tenantControlPlane.Status.ControlPlaneEndpoint = net.JoinHostPort(address, strconv.FormatInt(int64(tenantControlPlane.Spec.NetworkProfile.Port), 10))