Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ metadata:
uptime.pdok.nl/name: "Logical name of the check"
uptime.pdok.nl/url: "https://site.example/service/wms/v1_0"
uptime.pdok.nl/tags: "metadata,separated,by,commas"
uptime.pdok.nl/interval-in-minutes: "5"
uptime.pdok.nl/request-headers: "Accept: application/json, Accept-Language: en"
uptime.pdok.nl/response-check-for-string-contains: "It works!"
uptime.pdok.nl/response-check-for-string-not-contains: "NullPointerException"
Expand Down
11 changes: 7 additions & 4 deletions internal/controller/ingressroute_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,11 @@ var _ = Describe("IngressRoute Controller", func() {
_, err = controllerReconciler.Reconcile(ctx, reconcile.Request{NamespacedName: typeNamespacedName})
Expect(err).NotTo(HaveOccurred())
Expect(testProvider.checks).To(ContainElement(m.UptimeCheck{
ID: "y45735y375",
URL: "https://test.example",
Name: "Test uptime check",
Tags: []string{"managed-by-uptime-operator"},
ID: "y45735y375",
URL: "https://test.example",
Name: "Test uptime check",
Tags: []string{"managed-by-uptime-operator"},
Interval: 1,
}))

By("Fetching and updating IngressRoute (adding extra uptime annotation)")
Expand All @@ -151,6 +152,7 @@ var _ = Describe("IngressRoute Controller", func() {
Name: "Test uptime check",
Tags: []string{"managed-by-uptime-operator"},
StringContains: "OK",
Interval: 1,
}))

By("Reconciling the IngressRoute again to make sure it doesn't cause any side effects")
Expand All @@ -176,6 +178,7 @@ var _ = Describe("IngressRoute Controller", func() {
Name: "Test uptime check",
Tags: []string{"managed-by-uptime-operator"},
StringContains: "OK",
Interval: 1,
}))

By("Delete IngressRoute")
Expand Down
19 changes: 19 additions & 0 deletions internal/model/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package model
import (
"fmt"
"slices"
"strconv"
"strings"
)

Expand All @@ -17,6 +18,7 @@ const (
AnnotationName = AnnotationBase + "/name"
AnnotationURL = AnnotationBase + "/url"
AnnotationTags = AnnotationBase + "/tags"
AnnotationInterval = AnnotationBase + "/interval-in-minutes"
AnnotationRequestHeaders = AnnotationBase + "/request-headers"
AnnotationStringContains = AnnotationBase + "/response-check-for-string-contains"
AnnotationStringNotContains = AnnotationBase + "/response-check-for-string-not-contains"
Expand All @@ -29,6 +31,7 @@ type UptimeCheck struct {
Name string `json:"name"`
URL string `json:"url"`
Tags []string `json:"tags"`
Interval int `json:"resolution"`
RequestHeaders map[string]string `json:"request_headers"` //nolint:tagliatelle // grandfathered in
StringContains string `json:"string_contains"` //nolint:tagliatelle // grandfathered in
StringNotContains string `json:"string_not_contains"` //nolint:tagliatelle // grandfathered in
Expand All @@ -47,11 +50,16 @@ func NewUptimeCheck(ingressName string, annotations map[string]string) (*UptimeC
if !ok {
return nil, fmt.Errorf("%s annotation not found on ingress route %s", AnnotationURL, ingressName)
}
interval, err := getInterval(annotations)
if err != nil {
return nil, err
}
check := &UptimeCheck{
ID: id,
Name: name,
URL: url,
Tags: stringToSlice(annotations[AnnotationTags]),
Interval: interval,
RequestHeaders: kvStringToMap(annotations[AnnotationRequestHeaders]),
StringContains: annotations[AnnotationStringContains],
StringNotContains: annotations[AnnotationStringNotContains],
Expand All @@ -62,6 +70,17 @@ func NewUptimeCheck(ingressName string, annotations map[string]string) (*UptimeC
return check, nil
}

func getInterval(annotations map[string]string) (int, error) {
if _, ok := annotations[AnnotationInterval]; ok {
interval, err := strconv.Atoi(annotations[AnnotationInterval])
if err != nil {
return 1, fmt.Errorf("%s annotation should contain integer value: %w", AnnotationInterval, err)
}
return interval, nil
}
return 1, nil
}

func kvStringToMap(s string) map[string]string {
if s == "" {
return nil
Expand Down
2 changes: 1 addition & 1 deletion internal/service/providers/pingdom.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ func (m *PingdomUptimeProvider) checkToJSON(check model.UptimeCheck, includeType
"url": relativeURL,
"encryption": true, // assume all checks run over HTTPS
"port": port,
"resolution": 1,
"resolution": check.Interval,
"tags": check.Tags,
}
if includeType {
Expand Down
Loading