Skip to content

Commit a17f39a

Browse files
authored
feat: api private location (#62)
* chore: update checkly-go-sdk new version 1.11.0 * feat: add privateLocation field to operator and crd fixes #60 fixes #43 * test(privateLocation): add privateLocation to test * chore(dependencies): update dependencies
1 parent 29316e8 commit a17f39a

9 files changed

Lines changed: 60 additions & 23 deletions

File tree

api/checkly/v1alpha1/group_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ type GroupSpec struct {
3131
// Locations determines the locations where the checks are run from, see https://www.checklyhq.com/docs/monitoring/global-locations/ for a list, use AWS Region codes, ex. eu-west-1 for Ireland
3232
Locations []string `json:"locations,omitempty"`
3333

34+
// Locations determines the locations where the checks are run from, see https://www.checklyhq.com/docs/monitoring/global-locations/ for a list, use AWS Region codes, ex. eu-west-1 for Ireland
35+
PrivateLocations []string `json:"privateLocations,omitempty"`
36+
3437
// Activated determines if the created group is muted or not, default false
3538
Activated bool `json:"muted,omitempty"`
3639

config/crd/bases/k8s.checklyhq.com_groups.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ spec:
5555
description: Activated determines if the created group is muted or
5656
not, default false
5757
type: boolean
58+
privateLocations:
59+
description: Locations determines the locations where the checks are
60+
run from, see https://www.checklyhq.com/docs/monitoring/global-locations/
61+
for a list, use AWS Region codes, ex. eu-west-1 for Ireland
62+
items:
63+
type: string
64+
type: array
5865
type: object
5966
status:
6067
description: GroupStatus defines the observed state of Group

external/checkly/group.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,13 @@ import (
2424
)
2525

2626
type Group struct {
27-
Name string
28-
ID int64
29-
Locations []string
30-
Activated bool
31-
AlertChannels []checkly.AlertChannelSubscription
32-
Labels map[string]string
27+
Name string
28+
ID int64
29+
Locations []string
30+
PrivateLocations []string
31+
Activated bool
32+
AlertChannels []checkly.AlertChannelSubscription
33+
Labels map[string]string
3334
}
3435

3536
func checklyGroup(group Group) (check checkly.Group) {
@@ -54,6 +55,12 @@ func checklyGroup(group Group) (check checkly.Group) {
5455
},
5556
}
5657

58+
locations := []string{}
59+
60+
if len(group.PrivateLocations) != 0 {
61+
checkValueArray(group.Locations, []string{"eu-west-1"})
62+
}
63+
5764
check = checkly.Group{
5865
Name: group.Name,
5966
Activated: true,
@@ -62,7 +69,8 @@ func checklyGroup(group Group) (check checkly.Group) {
6269
LocalSetupScript: "",
6370
LocalTearDownScript: "",
6471
Concurrency: 2,
65-
Locations: checkValueArray(group.Locations, []string{"eu-west-1"}),
72+
Locations: locations,
73+
PrivateLocations: &group.PrivateLocations,
6674
Tags: tags,
6775
AlertSettings: alertSettings,
6876
UseGlobalAlertSettings: false,

external/checkly/group_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ import "testing"
2020

2121
func TestChecklyGroup(t *testing.T) {
2222
data := Group{
23-
Name: "foo",
24-
Locations: []string{"basement"},
23+
Name: "foo",
24+
Locations: []string{"basement"},
25+
PrivateLocations: []string{"ground-floor"},
2526
}
2627

2728
testData := checklyGroup(data)

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ require (
5656
require (
5757
github.com/beorn7/perks v1.0.1 // indirect
5858
github.com/cespare/xxhash/v2 v2.3.0 // indirect
59-
github.com/checkly/checkly-go-sdk v1.8.1
59+
github.com/checkly/checkly-go-sdk v1.11.0
6060
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
6161
github.com/fsnotify/fsnotify v1.7.0 // indirect
6262
github.com/go-logr/logr v1.4.2 // indirect

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
1010
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
1111
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
1212
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
13-
github.com/checkly/checkly-go-sdk v1.8.1 h1:s8TAlbruie1lxGVdkqwfimMBKnTrjso26yByJI1uoPI=
14-
github.com/checkly/checkly-go-sdk v1.8.1/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
13+
github.com/checkly/checkly-go-sdk v1.11.0 h1:rMlELoLEZNZzxqKLPCeptjBMdDeBcM4eV/NlGK+psik=
14+
github.com/checkly/checkly-go-sdk v1.11.0/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
1515
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
1616
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
1717
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=

internal/controller/checkly/group_controller.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222

23+
"github.com/checkly/checkly-go-sdk"
2324
"k8s.io/apimachinery/pkg/api/errors"
2425
"k8s.io/apimachinery/pkg/runtime"
2526
"k8s.io/apimachinery/pkg/types"
@@ -28,7 +29,6 @@ import (
2829
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
2930
"sigs.k8s.io/controller-runtime/pkg/log"
3031

31-
"github.com/checkly/checkly-go-sdk"
3232
checklyv1alpha1 "github.com/checkly/checkly-operator/api/checkly/v1alpha1"
3333
external "github.com/checkly/checkly-operator/external/checkly"
3434
)
@@ -141,12 +141,13 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
141141

142142
// Create internal Check type
143143
internalCheck := external.Group{
144-
Name: group.Name,
145-
Activated: group.Spec.Activated,
146-
Locations: group.Spec.Locations,
147-
AlertChannels: alertChannels,
148-
ID: group.Status.ID,
149-
Labels: group.Labels,
144+
Name: group.Name,
145+
Activated: group.Spec.Activated,
146+
Locations: group.Spec.Locations,
147+
PrivateLocations: group.Spec.PrivateLocations,
148+
AlertChannels: alertChannels,
149+
ID: group.Status.ID,
150+
Labels: group.Labels,
150151
}
151152

152153
// /////////////////////////////

internal/controller/checkly/group_controller_test.go

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ import (
2020
"time"
2121

2222
"github.com/checkly/checkly-go-sdk"
23-
checklyv1alpha1 "github.com/checkly/checkly-operator/api/checkly/v1alpha1"
2423
. "github.com/onsi/ginkgo"
2524
. "github.com/onsi/gomega"
2625
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2726
"k8s.io/apimachinery/pkg/types"
27+
28+
checklyv1alpha1 "github.com/checkly/checkly-operator/api/checkly/v1alpha1"
2829
)
2930

3031
var _ = Describe("ApiCheck Controller", func() {
@@ -51,6 +52,7 @@ var _ = Describe("ApiCheck Controller", func() {
5152
It("Full reconciliation", func() {
5253

5354
updatedLocations := []string{"eu-west-2", "eu-west-1"}
55+
updatedPrivateLocations := []string{"ground-floor"}
5456
groupKey := types.NamespacedName{
5557
Name: "test-group",
5658
}
@@ -64,8 +66,9 @@ var _ = Describe("ApiCheck Controller", func() {
6466
Name: groupKey.Name,
6567
},
6668
Spec: checklyv1alpha1.GroupSpec{
67-
Locations: []string{"eu-west-1"},
68-
AlertChannels: []string{alertChannelKey.Name},
69+
Locations: []string{"eu-west-1"},
70+
PrivateLocations: []string{},
71+
AlertChannels: []string{alertChannelKey.Name},
6972
},
7073
}
7174

@@ -140,6 +143,20 @@ var _ = Describe("ApiCheck Controller", func() {
140143
}
141144
}, timeout, interval).Should(BeTrue())
142145

146+
updated.Spec.PrivateLocations = updatedPrivateLocations
147+
Expect(k8sClient.Update(context.Background(), updated)).Should(Succeed())
148+
149+
By("Expecting update")
150+
Eventually(func() bool {
151+
f := &checklyv1alpha1.Group{}
152+
err := k8sClient.Get(context.Background(), groupKey, f)
153+
if len(f.Spec.PrivateLocations) == 1 && err == nil {
154+
return true
155+
} else {
156+
return false
157+
}
158+
}, timeout, interval).Should(BeTrue())
159+
143160
// Delete group
144161
By("Expecting to delete successfully")
145162
Eventually(func() error {

internal/controller/checkly/suite_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"os"
2323
"path/filepath"
2424
"testing"
25+
//+kubebuilder:scaffold:imports
2526

2627
"github.com/checkly/checkly-go-sdk"
2728
. "github.com/onsi/ginkgo"
@@ -35,7 +36,6 @@ import (
3536
"sigs.k8s.io/controller-runtime/pkg/log/zap"
3637

3738
checklyv1alpha1 "github.com/checkly/checkly-operator/api/checkly/v1alpha1"
38-
//+kubebuilder:scaffold:imports
3939
)
4040

4141
// These tests use Ginkgo (BDD-style Go testing framework). Refer to

0 commit comments

Comments
 (0)