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

fix(groups): Add group namespace field #22

Merged
merged 1 commit into from
Jul 20, 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: 3 additions & 0 deletions apis/checkly/v1alpha1/apicheck_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ type ApiCheckSpec struct {

// Group determines in which group does the check belong to
Group string `json:"group"`

// GroupNamespace determine in which namespace was the group defined
GroupNamespace string `json:"groupnamespace,omitempty"`
}

// ApiCheckStatus defines the observed state of ApiCheck
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/k8s.checklyhq.com_apichecks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ spec:
description: Group determines in which group does the check belong
to
type: string
groupnamespace:
description: GroupNamespace determine in which namespace was the group
defined
type: string
maxresponsetime:
description: MaxResponseTime determines what the maximum number of
miliseconds can pass before the check fails, default 15000
Expand Down
1 change: 1 addition & 0 deletions config/samples/checkly_v1alpha1_apicheck.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ spec:
frequency: 10 # Default 5
muted: true # Default "false"
group: "group-sample"
groupnamespace: "default" # If not specified, the controller assumes the group is in the same namespace
8 changes: 7 additions & 1 deletion controllers/checkly/apicheck_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ func (r *ApiCheckReconciler) Reconcile(ctx context.Context, req ctrl.Request) (c
// Lookup group ID
// ////////////////////////////
group := &checklyv1alpha1.Group{}
err = r.Get(ctx, types.NamespacedName{Name: apiCheck.Spec.Group, Namespace: apiCheck.Namespace}, group)
var groupNamespace string
if apiCheck.Spec.GroupNamespace == "" {
groupNamespace = apiCheck.Namespace
} else {
groupNamespace = apiCheck.Spec.GroupNamespace
}
err = r.Get(ctx, types.NamespacedName{Name: apiCheck.Spec.Group, Namespace: groupNamespace}, group)
if err != nil {
if errors.IsNotFound(err) {
// The resource has been deleted
Expand Down
27 changes: 27 additions & 0 deletions controllers/checkly/apicheck_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,35 @@ var _ = Describe("ApiCheck Controller", func() {
}
}, timeout, interval).Should(BeTrue())

// Update
groupUpdateNS := "kube-system"
groupUpdate := &checklyv1alpha1.Group{
ObjectMeta: metav1.ObjectMeta{
Name: groupKey.Name,
Namespace: groupUpdateNS,
},
}
Expect(k8sClient.Create(context.Background(), groupUpdate)).Should(Succeed())

apiCheckRaw := &checklyv1alpha1.ApiCheck{}
Expect(k8sClient.Get(context.Background(), key, apiCheckRaw)).Should(Succeed())
apiCheckRaw.Spec.GroupNamespace = groupUpdateNS
Expect(k8sClient.Update(context.Background(), apiCheckRaw)).Should(Succeed())

By("Expecting groupnamespace to change")
Eventually(func() bool {
f := &checklyv1alpha1.ApiCheck{}
err := k8sClient.Get(context.Background(), key, f)
if err == nil && f.Spec.GroupNamespace == groupUpdateNS {
return true
}
return false

}, timeout, interval).Should(BeTrue())

// Delete
Expect(k8sClient.Delete(context.Background(), group)).Should(Succeed())
Expect(k8sClient.Delete(context.Background(), groupUpdate)).Should(Succeed())

By("Expecting to delete successfully")
Eventually(func() error {
Expand Down