From a265ec060cea820a0171f1f827ecbe7ad84d0df6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Susa=20T=C3=BCnker?= Date: Tue, 2 Sep 2025 14:20:22 +0200 Subject: [PATCH 1/2] fix(ingress): check enabled annotation before gathering data MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves the enabled annotation check before gatherApiCheckData() to prevent errors when ingresses lack required group annotation. Fixes regression from #49 where disabled ingresses were causing continuous error logs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- api/checkly/v1alpha1/zz_generated.deepcopy.go | 5 ++ .../networking/ingress_controller.go | 47 ++++++++++++++----- 2 files changed, 41 insertions(+), 11 deletions(-) diff --git a/api/checkly/v1alpha1/zz_generated.deepcopy.go b/api/checkly/v1alpha1/zz_generated.deepcopy.go index fa4bcf5..f8d61e8 100644 --- a/api/checkly/v1alpha1/zz_generated.deepcopy.go +++ b/api/checkly/v1alpha1/zz_generated.deepcopy.go @@ -287,6 +287,11 @@ func (in *GroupSpec) DeepCopyInto(out *GroupSpec) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.PrivateLocations != nil { + in, out := &in.PrivateLocations, &out.PrivateLocations + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.AlertChannels != nil { in, out := &in.AlertChannels, &out.AlertChannels *out = make([]string, len(*in)) diff --git a/internal/controller/networking/ingress_controller.go b/internal/controller/networking/ingress_controller.go index ffbf130..569f5af 100644 --- a/internal/controller/networking/ingress_controller.go +++ b/internal/controller/networking/ingress_controller.go @@ -73,24 +73,25 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct } logger.Info("Ingress Object found") - // Gather data for the checkly check - logger.Info("Gathering data for the check") - apiCheckResources, err := r.gatherApiCheckData(&ingress) - if err != nil { - logger.Error(err, "unable to gather data for the apiCheck resource", "Ingress Name", ingress.Name, "Ingress namespace", ingress.Namespace) - return ctrl.Result{}, err - } - // Do we want to do anything with the ingress? if value, exists := ingress.Annotations[annotationEnabled]; !exists || value == "false" { - logger.Info("Checking to see if we need to delete any resources as we're not handling this ingress", "Ingress Name", ingress.Name, "Ingress namespace", ingress.Namespace) + logger.Info("Ingress not enabled for Checkly monitoring, cleaning up any existing resources", "Ingress Name", ingress.Name, "Ingress namespace", ingress.Namespace) - r.deleteIngressApiChecks(ctx, req, apiCheckResources, ingress) + // Clean up existing ApiChecks without requiring annotations + r.cleanupApiChecksForIngress(ctx, &ingress) if ingress.GetDeletionTimestamp() == nil { return ctrl.Result{}, nil } } + + // Gather data for the checkly check (only if enabled) + logger.Info("Gathering data for the check") + apiCheckResources, err := r.gatherApiCheckData(&ingress) + if err != nil { + logger.Error(err, "unable to gather data for the apiCheck resource", "Ingress Name", ingress.Name, "Ingress namespace", ingress.Namespace) + return ctrl.Result{}, err + } // //////////////////////////////// // Delete Logic // /////////////////////////////// @@ -99,7 +100,7 @@ func (r *IngressReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct if controllerutil.ContainsFinalizer(&ingress, checklyFinalizer) { logger.Info("Finalizer present, need to delete ApiCheck first", "Ingress Name", ingress.Name, "Ingress namespace", ingress.Namespace) - r.deleteIngressApiChecks(ctx, req, apiCheckResources, ingress) + r.cleanupApiChecksForIngress(ctx, &ingress) // Delete finalizer logic logger.Info("Deleting finalizer", "Ingress Name", ingress.Name, "Ingress namespace", ingress.Namespace) @@ -342,6 +343,30 @@ func (r *IngressReconciler) compareApiChecks( return } +func (r *IngressReconciler) cleanupApiChecksForIngress( + ctx context.Context, + ingress *networkingv1.Ingress, +) { + logger := log.FromContext(ctx) + + var existingApiChecks checklyv1alpha1.ApiCheckList + err := r.List(ctx, &existingApiChecks, client.InNamespace(ingress.Namespace), client.MatchingLabels{"ingress-controller": ingress.Name}) + if err != nil { + logger.Error(err, "Failed to list existing ApiChecks for cleanup", "Ingress Name", ingress.Name, "Ingress namespace", ingress.Namespace) + return + } + + for _, apiCheck := range existingApiChecks.Items { + logger.Info("Deleting existing ApiCheck", "ApiCheck Name", apiCheck.Name, "Ingress Name", ingress.Name) + err = r.Delete(ctx, &apiCheck) + if err != nil { + logger.Error(err, "Failed to delete ApiCheck during cleanup", "ApiCheck Name", apiCheck.Name, "Namespace", apiCheck.Namespace) + continue + } + logger.Info("Successfully deleted ApiCheck", "ApiCheck Name", apiCheck.Name) + } +} + func (r *IngressReconciler) deleteIngressApiChecks( ctx context.Context, req ctrl.Request, From d4d2097ca4c83462a1d15c021b5a75d24c74ab1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Susa=20T=C3=BCnker?= <74345218+sujaya-sys@users.noreply.github.com> Date: Tue, 2 Sep 2025 14:33:14 +0200 Subject: [PATCH 2/2] Update zz_generated.deepcopy.go --- api/checkly/v1alpha1/zz_generated.deepcopy.go | 5 ----- 1 file changed, 5 deletions(-) diff --git a/api/checkly/v1alpha1/zz_generated.deepcopy.go b/api/checkly/v1alpha1/zz_generated.deepcopy.go index f8d61e8..fa4bcf5 100644 --- a/api/checkly/v1alpha1/zz_generated.deepcopy.go +++ b/api/checkly/v1alpha1/zz_generated.deepcopy.go @@ -287,11 +287,6 @@ func (in *GroupSpec) DeepCopyInto(out *GroupSpec) { *out = make([]string, len(*in)) copy(*out, *in) } - if in.PrivateLocations != nil { - in, out := &in.PrivateLocations, &out.PrivateLocations - *out = make([]string, len(*in)) - copy(*out, *in) - } if in.AlertChannels != nil { in, out := &in.AlertChannels, &out.AlertChannels *out = make([]string, len(*in))