Skip to content

Commit

Permalink
feat: add annotation to explicitly ignore certain ingress routes.
Browse files Browse the repository at this point in the history
  • Loading branch information
rkettelerij committed Jun 24, 2024
1 parent 9d706c6 commit 5d8516d
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 6 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
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand All @@ -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=
Expand Down Expand Up @@ -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=
Expand Down Expand Up @@ -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=
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
19 changes: 16 additions & 3 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -74,17 +78,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 5d8516d

Please sign in to comment.