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..2700b74 100644 --- a/go.sum +++ b/go.sum @@ -52,8 +52,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= 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= @@ -209,8 +209,8 @@ k8s.io/client-go v0.30.2 h1:sBIVJdojUNPDU/jObC+18tXWcTJVcwyqS9diGdWHk50= k8s.io/client-go v0.30.2/go.mod h1:JglKSWULm9xlJLx4KCkfLLQ7XwtlbflV6uFFSHTMgVs= 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..b137222 100644 --- a/internal/service/service.go +++ b/internal/service/service.go @@ -64,6 +64,11 @@ func WithDeletes(enableDeletes bool) UptimeCheckOption { } func (r *UptimeCheckService) Mutate(ctx context.Context, mutation m.Mutation, ingressName string, annotations map[string]string) { + _, ignore := annotations[m.AnnotationIgnore] + if ignore { + r.logRouteIgnore(ctx, mutation, ingressName) + return + } check, err := m.NewUptimeCheck(ingressName, annotations) if err != nil { r.logAnnotationErr(ctx, err) @@ -74,7 +79,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 +87,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 }