Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(tags): Turn all labels into tags #20

Merged
merged 1 commit into from
Jul 19, 2022
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: 2 additions & 1 deletion config/samples/checkly_v1alpha1_apicheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ apiVersion: k8s.checklyhq.com/v1alpha1
kind: ApiCheck
metadata:
name: apicheck-sample
labels:
service: "foo"
spec:
endpoint: "https://foo.bar/baz"
success: "200"
team: qux
frequency: 10 # Default 5
muted: true # Default "false"
group: "group-sample"
2 changes: 2 additions & 0 deletions config/samples/checkly_v1alpha1_group.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: k8s.checklyhq.com/v1alpha1
kind: Group
metadata:
name: group-sample
labels:
environment: "local"
spec:
locations:
- eu-west-1
Expand Down
1 change: 1 addition & 0 deletions controllers/checkly/apicheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func (r *ApiCheckReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
ID: apiCheck.Status.ID,
GroupID: group.Status.ID,
Muted: apiCheck.Spec.Muted,
Labels: apiCheck.Labels,
}

// /////////////////////////////
Expand Down
1 change: 1 addition & 0 deletions controllers/checkly/group_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
Locations: group.Spec.Locations,
AlertChannels: group.Spec.AlertChannels,
ID: group.Status.ID,
Labels: group.Labels,
}

// /////////////////////////////
Expand Down
11 changes: 11 additions & 0 deletions external/checkly/api_common.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ limitations under the License.

package external

import "fmt"

func checkValueString(x string, y string) (value string) {
if x == "" {
value = y
Expand All @@ -42,3 +44,12 @@ func checkValueArray(x []string, y []string) (value []string) {
}
return
}

func getTags(labels map[string]string) (tags []string) {

for k, v := range labels {
tags = append(tags, fmt.Sprintf("%s:%s", k, v))
}

return
}
17 changes: 17 additions & 0 deletions external/checkly/api_common_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,20 @@ func TestCheckValueArray(t *testing.T) {
}

}

func TestGetTags(t *testing.T) {
var data = make(map[string]string)
data["foo"] = "bar"

response := getTags(data)
if len(response) != 1 {
t.Errorf("Expected 1 item, got %d", len(response))
}

for _, v := range response {
if v != "foo:bar" {
t.Errorf("Expected foo:bar, got %s", v)
}
}

}
36 changes: 19 additions & 17 deletions external/checkly/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Check struct {
GroupID int64
ID string
Muted bool
Labels map[string]string
}

func checklyCheck(apiCheck Check) (check checkly.Check, err error) {
Expand All @@ -45,6 +46,10 @@ func checklyCheck(apiCheck Check) (check checkly.Check, err error) {
return
}

tags := getTags(apiCheck.Labels)
tags = append(tags, "checkly-operator")
tags = append(tags, apiCheck.Namespace)

alertSettings := checkly.AlertSettings{
EscalationType: checkly.RunBased,
RunBasedEscalation: checkly.RunBasedEscalation{
Expand All @@ -63,23 +68,20 @@ func checklyCheck(apiCheck Check) (check checkly.Check, err error) {
}

check = checkly.Check{
Name: apiCheck.Name,
Type: checkly.TypeAPI,
Frequency: checkValueInt(apiCheck.Frequency, 5),
DegradedResponseTime: 5000,
MaxResponseTime: checkValueInt(apiCheck.MaxResponseTime, 15000),
Activated: true,
Muted: apiCheck.Muted, // muted for development
ShouldFail: shouldFail,
DoubleCheck: false,
SSLCheck: false,
LocalSetupScript: "",
LocalTearDownScript: "",
Locations: []string{},
Tags: []string{
apiCheck.Namespace,
"checkly-operator",
},
Name: apiCheck.Name,
Type: checkly.TypeAPI,
Frequency: checkValueInt(apiCheck.Frequency, 5),
DegradedResponseTime: 5000,
MaxResponseTime: checkValueInt(apiCheck.MaxResponseTime, 15000),
Activated: true,
Muted: apiCheck.Muted, // muted for development
ShouldFail: shouldFail,
DoubleCheck: false,
SSLCheck: false,
LocalSetupScript: "",
LocalTearDownScript: "",
Locations: []string{},
Tags: tags,
AlertSettings: alertSettings,
UseGlobalAlertSettings: false,
GroupID: apiCheck.GroupID,
Expand Down
26 changes: 14 additions & 12 deletions external/checkly/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,15 @@ type Group struct {
Locations []string
Activated bool
AlertChannels []string
Labels map[string]string
}

func checklyGroup(group Group) (check checkly.Group) {

tags := getTags(group.Labels)
tags = append(tags, "checkly-operator")
tags = append(tags, group.Namespace)

alertSettings := checkly.AlertSettings{
EscalationType: checkly.RunBased,
RunBasedEscalation: checkly.RunBasedEscalation{
Expand All @@ -52,18 +57,15 @@ func checklyGroup(group Group) (check checkly.Group) {
}

check = checkly.Group{
Name: group.Name,
Activated: true,
Muted: false, // muted for development
DoubleCheck: false,
LocalSetupScript: "",
LocalTearDownScript: "",
Concurrency: 2,
Locations: checkValueArray(group.Locations, []string{"eu-west-1"}),
Tags: []string{
group.Namespace,
"checkly-operator",
},
Name: group.Name,
Activated: true,
Muted: false, // muted for development
DoubleCheck: false,
LocalSetupScript: "",
LocalTearDownScript: "",
Concurrency: 2,
Locations: checkValueArray(group.Locations, []string{"eu-west-1"}),
Tags: tags,
AlertSettings: alertSettings,
UseGlobalAlertSettings: false,
AlertChannelSubscriptions: []checkly.AlertChannelSubscription{},
Expand Down