Skip to content

Commit

Permalink
Merge pull request #5 from PDOK/ignore
Browse files Browse the repository at this point in the history
feat: add annotation to explicitly ignore certain ingress routes.
  • Loading branch information
rkettelerij authored Jun 24, 2024
2 parents 9d706c6 + d6a1450 commit d840d00
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 10 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion internal/model/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ const (
TagManagedBy = "managed-by-" + OperatorName

AnnotationBase = "uptime.pdok.nl"
AnnotationFinalizer = AnnotationBase + "/finalizer"
AnnotationID = AnnotationBase + "/id"
AnnotationName = AnnotationBase + "/name"
AnnotationURL = AnnotationBase + "/url"
AnnotationTags = AnnotationBase + "/tags"
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 {
Expand Down
20 changes: 17 additions & 3 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -74,17 +79,26 @@ 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)
r.logMutation(ctx, err, mutation, check)
}
}

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
}
Expand Down

0 comments on commit d840d00

Please sign in to comment.