From 5d8516d871f6798a36b4a54693b0404842d2f074 Mon Sep 17 00:00:00 2001 From: Richard Kettelerij Date: Mon, 24 Jun 2024 10:46:25 +0200 Subject: [PATCH] feat: add annotation to explicitly ignore certain ingress routes. --- README.md | 6 ++++++ go.mod | 4 ++-- go.sum | 6 ++++++ internal/model/check.go | 3 ++- internal/service/service.go | 19 ++++++++++++++++--- 5 files changed, 32 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 9259b72..9db56df 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,12 @@ The `id`, `name` and `url` annotations are mandatory, the rest is optional. Both `traefik.containo.us/v1alpha1` as well as `traefik.io/v1alpha1` resources are supported. +### Ignoring routes + +To exclude a route from uptime monitoring you can explicitly add a `uptime.pdok.nl/ignore` annotation. +The difference between a route without any annotation or a route with an `/ignore` annotation is that the +latter won't cause any error logging. + ## Run/usage ```shell diff --git a/go.mod b/go.mod index 1c4de36..aca3007 100644 --- a/go.mod +++ b/go.mod @@ -39,7 +39,7 @@ require ( github.com/google/gnostic-models v0.6.8 // indirect github.com/google/go-cmp v0.6.0 // indirect github.com/google/gofuzz v1.2.0 // indirect - github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8 // indirect + github.com/google/pprof v0.0.0-20240622144329-c177fd99eaa9 // indirect github.com/google/uuid v1.6.0 // indirect github.com/gorilla/mux v1.8.1 // indirect github.com/gorilla/websocket v1.5.3 // indirect @@ -81,7 +81,7 @@ require ( k8s.io/api v0.30.2 // indirect k8s.io/apiextensions-apiserver v0.30.2 // indirect k8s.io/klog/v2 v2.130.1 // indirect - k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a // indirect + k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b // indirect k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 // indirect sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect diff --git a/go.sum b/go.sum index f303861..4eb11c2 100644 --- a/go.sum +++ b/go.sum @@ -33,6 +33,7 @@ github.com/go-openapi/jsonreference v0.21.0 h1:Rs+Y7hSXT83Jacb7kFyjn4ijOuVGSvOdF github.com/go-openapi/jsonreference v0.21.0/go.mod h1:LmZmgsrTkVg9LG4EaHeY8cBDslNPMo06cago5JNLkm4= github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+GrE= github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ= +github.com/go-task/slim-sprig v0.0.0-20230315185526-52ccab3ef572 h1:tfuBGBXKqDEevZMzYi5KSi8KkcZtzBcTgAUUtapy0OI= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/go-test/deep v1.0.4 h1:u2CU3YKy9I2pmu9pX0eq50wCgjfGIt539SqR7FbHiho= @@ -54,6 +55,8 @@ github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0= github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8 h1:ASJ/LAqdCHOyMYI+dwNxn7Rd8FscNkMyTr1KZU1JI/M= github.com/google/pprof v0.0.0-20240618054019-d3b898a103f8/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= +github.com/google/pprof v0.0.0-20240622144329-c177fd99eaa9 h1:ouFdLLCOyCfnxGpQTMZKHLyHr/D1GFbQzEsJxumO16E= +github.com/google/pprof v0.0.0-20240622144329-c177fd99eaa9/go.mod h1:K1liHPHnj73Fdn/EKuT8nrFqBihUSKXoLYU0BuatOYo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/gorilla/mux v1.8.1 h1:TuBL49tXwgrFYWhqrNgrUNEY92u81SPhu7sTdzQEiWY= @@ -85,6 +88,7 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= github.com/onsi/ginkgo/v2 v2.19.0 h1:9Cnnf7UHo57Hy3k6/m5k3dRfGTMXGvxhHFvkDTCTpvA= github.com/onsi/ginkgo/v2 v2.19.0/go.mod h1:rlwLi9PilAFJ8jCg9UE1QP6VBpd6/xj3SRC0d6TU0To= github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk= @@ -211,6 +215,8 @@ k8s.io/klog/v2 v2.130.1 h1:n9Xl7H1Xvksem4KFG4PYbdQCQxqc/tTUyrgXaOhHSzk= k8s.io/klog/v2 v2.130.1/go.mod h1:3Jpz1GvMt720eyJH1ckRHK1EDfpxISzJ7I9OYgaDtPE= k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a h1:zD1uj3Jf+mD4zmA7W+goE5TxDkI7OGJjBNBzq5fJtLA= k8s.io/kube-openapi v0.0.0-20240521193020-835d969ad83a/go.mod h1:UxDHUPsUwTOOxSU+oXURfFBcAS6JwiRXTYqYwfuGowc= +k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b h1:Q9xmGWBvOGd8UJyccgpYlLosk/JlfP3xQLNkQlHJeXw= +k8s.io/kube-openapi v0.0.0-20240620174524-b456828f718b/go.mod h1:UxDHUPsUwTOOxSU+oXURfFBcAS6JwiRXTYqYwfuGowc= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0 h1:jgGTlFYnhF1PM1Ax/lAlxUPE+KfCIXHaathvJg1C3ak= k8s.io/utils v0.0.0-20240502163921-fe8a2dddb1d0/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0= sigs.k8s.io/controller-runtime v0.18.4 h1:87+guW1zhvuPLh1PHybKdYFLU0YJp4FhJRmiHvm5BZw= diff --git a/internal/model/check.go b/internal/model/check.go index 4115f18..db34d80 100644 --- a/internal/model/check.go +++ b/internal/model/check.go @@ -13,7 +13,6 @@ const ( TagManagedBy = "managed-by-" + OperatorName AnnotationBase = "uptime.pdok.nl" - AnnotationFinalizer = AnnotationBase + "/finalizer" AnnotationID = AnnotationBase + "/id" AnnotationName = AnnotationBase + "/name" AnnotationURL = AnnotationBase + "/url" @@ -21,6 +20,8 @@ const ( AnnotationRequestHeaders = AnnotationBase + "/request-headers" AnnotationStringContains = AnnotationBase + "/response-check-for-string-contains" AnnotationStringNotContains = AnnotationBase + "/response-check-for-string-not-contains" + AnnotationFinalizer = AnnotationBase + "/finalizer" + AnnotationIgnore = AnnotationBase + "/ignore" ) type UptimeCheck struct { diff --git a/internal/service/service.go b/internal/service/service.go index 1564252..045f943 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -64,6 +64,10 @@ func WithDeletes(enableDeletes bool) UptimeCheckOption { } func (r *UptimeCheckService) Mutate(ctx context.Context, mutation m.Mutation, ingressName string, annotations map[string]string) { + if annotations[m.AnnotationIgnore] != "" { + r.logRouteIgnore(ctx, mutation, ingressName) + return + } check, err := m.NewUptimeCheck(ingressName, annotations) if err != nil { r.logAnnotationErr(ctx, err) @@ -74,7 +78,7 @@ func (r *UptimeCheckService) Mutate(ctx context.Context, mutation m.Mutation, in r.logMutation(ctx, err, mutation, check) } else if mutation == m.Delete { if !r.enableDeletes { - r.logDeleteDisabled(ctx, check, err) + r.logDeleteDisabled(ctx, check) return } err = r.provider.DeleteCheck(ctx, *check) @@ -82,9 +86,18 @@ func (r *UptimeCheckService) Mutate(ctx context.Context, mutation m.Mutation, in } } -func (r *UptimeCheckService) logDeleteDisabled(ctx context.Context, check *m.UptimeCheck, err error) { +func (r *UptimeCheckService) logDeleteDisabled(ctx context.Context, check *m.UptimeCheck) { msg := fmt.Sprintf("delete of uptime check '%s' (id: %s) not executed since 'enable-deletes=false'.", check.Name, check.ID) - log.FromContext(ctx).Error(err, msg, "check", check) + log.FromContext(ctx).Info(msg, "check", check) + if r.slack == nil { + return + } + r.slack.Send(ctx, ":information_source: "+msg) +} + +func (r *UptimeCheckService) logRouteIgnore(ctx context.Context, mutation m.Mutation, name string) { + msg := fmt.Sprintf("ignoring %s for ingress route %s, since this route is marked to be excluded from uptime monitoring", mutation, name) + log.FromContext(ctx).Info(msg) if r.slack == nil { return }