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
3 changes: 3 additions & 0 deletions api/checkly/v1alpha1/group_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ type GroupSpec struct {
// 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
Locations []string `json:"locations,omitempty"`

// 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
PrivateLocations []string `json:"privateLocations,omitempty"`

// Activated determines if the created group is muted or not, default false
Activated bool `json:"muted,omitempty"`

Expand Down
7 changes: 7 additions & 0 deletions config/crd/bases/k8s.checklyhq.com_groups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ spec:
description: Activated determines if the created group is muted or
not, default false
type: boolean
privateLocations:
description: 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
items:
type: string
type: array
type: object
status:
description: GroupStatus defines the observed state of Group
Expand Down
22 changes: 15 additions & 7 deletions external/checkly/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,13 @@ import (
)

type Group struct {
Name string
ID int64
Locations []string
Activated bool
AlertChannels []checkly.AlertChannelSubscription
Labels map[string]string
Name string
ID int64
Locations []string
PrivateLocations []string
Activated bool
AlertChannels []checkly.AlertChannelSubscription
Labels map[string]string
}

func checklyGroup(group Group) (check checkly.Group) {
Expand All @@ -54,6 +55,12 @@ func checklyGroup(group Group) (check checkly.Group) {
},
}

locations := []string{}

if len(group.PrivateLocations) != 0 {
checkValueArray(group.Locations, []string{"eu-west-1"})
}

check = checkly.Group{
Name: group.Name,
Activated: true,
Expand All @@ -62,7 +69,8 @@ func checklyGroup(group Group) (check checkly.Group) {
LocalSetupScript: "",
LocalTearDownScript: "",
Concurrency: 2,
Locations: checkValueArray(group.Locations, []string{"eu-west-1"}),
Locations: locations,
PrivateLocations: &group.PrivateLocations,
Tags: tags,
AlertSettings: alertSettings,
UseGlobalAlertSettings: false,
Expand Down
5 changes: 3 additions & 2 deletions external/checkly/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ import "testing"

func TestChecklyGroup(t *testing.T) {
data := Group{
Name: "foo",
Locations: []string{"basement"},
Name: "foo",
Locations: []string{"basement"},
PrivateLocations: []string{"ground-floor"},
}

testData := checklyGroup(data)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ require (
require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/checkly/checkly-go-sdk v1.8.1
github.com/checkly/checkly-go-sdk v1.11.0
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK3
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/checkly/checkly-go-sdk v1.8.1 h1:s8TAlbruie1lxGVdkqwfimMBKnTrjso26yByJI1uoPI=
github.com/checkly/checkly-go-sdk v1.8.1/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
github.com/checkly/checkly-go-sdk v1.11.0 h1:rMlELoLEZNZzxqKLPCeptjBMdDeBcM4eV/NlGK+psik=
github.com/checkly/checkly-go-sdk v1.11.0/go.mod h1:Pd6tBOggAe41NnCU5KwqA8JvD6J20/IctszT2E0AvHo=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down
15 changes: 8 additions & 7 deletions internal/controller/checkly/group_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"fmt"

"github.com/checkly/checkly-go-sdk"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/types"
Expand All @@ -28,7 +29,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/log"

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

// Create internal Check type
internalCheck := external.Group{
Name: group.Name,
Activated: group.Spec.Activated,
Locations: group.Spec.Locations,
AlertChannels: alertChannels,
ID: group.Status.ID,
Labels: group.Labels,
Name: group.Name,
Activated: group.Spec.Activated,
Locations: group.Spec.Locations,
PrivateLocations: group.Spec.PrivateLocations,
AlertChannels: alertChannels,
ID: group.Status.ID,
Labels: group.Labels,
}

// /////////////////////////////
Expand Down
23 changes: 20 additions & 3 deletions internal/controller/checkly/group_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"time"

"github.com/checkly/checkly-go-sdk"
checklyv1alpha1 "github.com/checkly/checkly-operator/api/checkly/v1alpha1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"

checklyv1alpha1 "github.com/checkly/checkly-operator/api/checkly/v1alpha1"
)

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

updatedLocations := []string{"eu-west-2", "eu-west-1"}
updatedPrivateLocations := []string{"ground-floor"}
groupKey := types.NamespacedName{
Name: "test-group",
}
Expand All @@ -64,8 +66,9 @@ var _ = Describe("ApiCheck Controller", func() {
Name: groupKey.Name,
},
Spec: checklyv1alpha1.GroupSpec{
Locations: []string{"eu-west-1"},
AlertChannels: []string{alertChannelKey.Name},
Locations: []string{"eu-west-1"},
PrivateLocations: []string{},
AlertChannels: []string{alertChannelKey.Name},
},
}

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

updated.Spec.PrivateLocations = updatedPrivateLocations
Expect(k8sClient.Update(context.Background(), updated)).Should(Succeed())

By("Expecting update")
Eventually(func() bool {
f := &checklyv1alpha1.Group{}
err := k8sClient.Get(context.Background(), groupKey, f)
if len(f.Spec.PrivateLocations) == 1 && err == nil {
return true
} else {
return false
}
}, timeout, interval).Should(BeTrue())

// Delete group
By("Expecting to delete successfully")
Eventually(func() error {
Expand Down
2 changes: 1 addition & 1 deletion internal/controller/checkly/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"os"
"path/filepath"
"testing"
//+kubebuilder:scaffold:imports

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

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

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