diff --git a/api/checkly/v1alpha1/group_types.go b/api/checkly/v1alpha1/group_types.go index a2b95af..634c223 100644 --- a/api/checkly/v1alpha1/group_types.go +++ b/api/checkly/v1alpha1/group_types.go @@ -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"` diff --git a/config/crd/bases/k8s.checklyhq.com_groups.yaml b/config/crd/bases/k8s.checklyhq.com_groups.yaml index 01aa929..062b578 100644 --- a/config/crd/bases/k8s.checklyhq.com_groups.yaml +++ b/config/crd/bases/k8s.checklyhq.com_groups.yaml @@ -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 diff --git a/external/checkly/group.go b/external/checkly/group.go index 1608b1c..9a3970f 100644 --- a/external/checkly/group.go +++ b/external/checkly/group.go @@ -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) { @@ -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, @@ -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, diff --git a/external/checkly/group_test.go b/external/checkly/group_test.go index b229665..01e0e40 100644 --- a/external/checkly/group_test.go +++ b/external/checkly/group_test.go @@ -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) diff --git a/go.mod b/go.mod index 96b2193..103f4b3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 2210503..4493e09 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/internal/controller/checkly/group_controller.go b/internal/controller/checkly/group_controller.go index c51f27a..5b8385a 100644 --- a/internal/controller/checkly/group_controller.go +++ b/internal/controller/checkly/group_controller.go @@ -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" @@ -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" ) @@ -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, } // ///////////////////////////// diff --git a/internal/controller/checkly/group_controller_test.go b/internal/controller/checkly/group_controller_test.go index d1e50d9..eba8f00 100644 --- a/internal/controller/checkly/group_controller_test.go +++ b/internal/controller/checkly/group_controller_test.go @@ -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() { @@ -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", } @@ -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}, }, } @@ -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 { diff --git a/internal/controller/checkly/suite_test.go b/internal/controller/checkly/suite_test.go index ea9c0b2..1879a1f 100644 --- a/internal/controller/checkly/suite_test.go +++ b/internal/controller/checkly/suite_test.go @@ -22,6 +22,7 @@ import ( "os" "path/filepath" "testing" + //+kubebuilder:scaffold:imports "github.com/checkly/checkly-go-sdk" . "github.com/onsi/ginkgo" @@ -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