Skip to content

Commit 5d66cbb

Browse files
committed
feat(domain): add option to set controller domain
* Add new command line flag for a controller domain * Update docs
1 parent 5366d89 commit 5d66cbb

13 files changed

+102
-58
lines changed

cmd/main.go

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,13 @@ func main() {
5757
var metricsAddr string
5858
var enableLeaderElection bool
5959
var probeAddr string
60+
var controllerDomain string
6061
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
6162
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
6263
flag.BoolVar(&enableLeaderElection, "leader-elect", false,
6364
"Enable leader election for controller manager. "+
6465
"Enabling this will ensure there is only one active controller manager.")
66+
flag.StringVar(&controllerDomain, "controller-domain", "k8s.checklyhq.com", "Domain to use for annotations and finalizers.")
6567
opts := zap.Options{
6668
Development: true,
6769
}
@@ -70,6 +72,8 @@ func main() {
7072

7173
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
7274

75+
setupLog.Info("Controller domain setup", "value", controllerDomain)
76+
7377
mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{
7478
Scheme: scheme,
7579
Metrics: metricsserver.Options{
@@ -107,32 +111,36 @@ func main() {
107111
client.SetAccountId(accountId)
108112

109113
if err = (&networkingcontrollers.IngressReconciler{
110-
Client: mgr.GetClient(),
111-
Scheme: mgr.GetScheme(),
114+
Client: mgr.GetClient(),
115+
Scheme: mgr.GetScheme(),
116+
ControllerDomain: controllerDomain,
112117
}).SetupWithManager(mgr); err != nil {
113118
setupLog.Error(err, "unable to create controller", "controller", "Ingress")
114119
os.Exit(1)
115120
}
116121
if err = (&checklycontrollers.ApiCheckReconciler{
117-
Client: mgr.GetClient(),
118-
Scheme: mgr.GetScheme(),
119-
ApiClient: client,
122+
Client: mgr.GetClient(),
123+
Scheme: mgr.GetScheme(),
124+
ApiClient: client,
125+
ControllerDomain: controllerDomain,
120126
}).SetupWithManager(mgr); err != nil {
121127
setupLog.Error(err, "unable to create controller", "controller", "ApiCheck")
122128
os.Exit(1)
123129
}
124130
if err = (&checklycontrollers.GroupReconciler{
125-
Client: mgr.GetClient(),
126-
Scheme: mgr.GetScheme(),
127-
ApiClient: client,
131+
Client: mgr.GetClient(),
132+
Scheme: mgr.GetScheme(),
133+
ApiClient: client,
134+
ControllerDomain: controllerDomain,
128135
}).SetupWithManager(mgr); err != nil {
129136
setupLog.Error(err, "unable to create controller", "controller", "Group")
130137
os.Exit(1)
131138
}
132139
if err = (&checklycontrollers.AlertChannelReconciler{
133-
Client: mgr.GetClient(),
134-
Scheme: mgr.GetScheme(),
135-
ApiClient: client,
140+
Client: mgr.GetClient(),
141+
Scheme: mgr.GetScheme(),
142+
ApiClient: client,
143+
ControllerDomain: controllerDomain,
136144
}).SetupWithManager(mgr); err != nil {
137145
setupLog.Error(err, "unable to create controller", "controller", "AlertChannel")
138146
os.Exit(1)

config/manager/manager.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ spec:
3232
- /manager
3333
args:
3434
- --leader-elect
35+
- --controller-domain=k8s.checklyhq.com
3536
image: controller:latest
3637
name: manager
3738
env:

docs/README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ If you just want to try out the checkly-operator, you need a local kubernetes in
3939
First we'll download the provided `install.yaml` files, please change the version number accordingly, we might have newer [releases](https://github.com/checkly/checkly-operator/releases) since we've written these docs.
4040

4141
```bash
42-
export CHECKLY_OPERATOR_RELEASE=v1.4.1
42+
export CHECKLY_OPERATOR_RELEASE=v1.7.0
4343
wget "https://github.com/checkly/checkly-operator/releases/download/$CHECKLY_OPERATOR_RELEASE/install-$CHECKLY_OPERATOR_RELEASE.yaml" -O install.yaml
4444
unset CHECKLY_OPERATOR_RELEASE
4545
```
@@ -53,6 +53,12 @@ You can apply the `install.yaml`, this will create the namespace, we need this t
5353
kubectl apply -f install.yaml
5454
```
5555

56+
#### Controller Domain
57+
58+
We're using a domain name for finalizers and annotations, the default value is `k8s.checklyhq.com`, but it can be changed by supplying the `--controller-domain=other.domain.tld` runtime option.
59+
60+
This option allows you to run multiple independent deployments of the operator and each would handle different resources based on the controller domain configuration.
61+
5662
### Create secret
5763

5864
Grab your [checklyhq.com](checklyhq.com) API key and Account ID, [the official docs](https://www.checklyhq.com/docs/integrations/pulumi/#define-your-checkly-account-id-and-api-key) can help you get this information. Substitute the values into the below command:

internal/controller/checkly/alertchannel_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package checkly
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
corev1 "k8s.io/api/core/v1"
2324
"k8s.io/apimachinery/pkg/api/errors"
@@ -36,8 +37,9 @@ import (
3637
// AlertChannelReconciler reconciles a AlertChannel object
3738
type AlertChannelReconciler struct {
3839
client.Client
39-
Scheme *runtime.Scheme
40-
ApiClient checkly.Client
40+
Scheme *runtime.Scheme
41+
ApiClient checkly.Client
42+
ControllerDomain string
4143
}
4244

4345
//+kubebuilder:rbac:groups=k8s.checklyhq.com,resources=alertchannels,verbs=get;list;watch;create;update;patch;delete
@@ -55,7 +57,7 @@ func (r *AlertChannelReconciler) Reconcile(ctx context.Context, req ctrl.Request
5557

5658
logger.Info("Reconciler started")
5759

58-
acFinalizer := "k8s.checklyhq.com/finalizer"
60+
acFinalizer := fmt.Sprintf("%s/finalizer", r.ControllerDomain)
5961

6062
ac := &checklyv1alpha1.AlertChannel{}
6163

internal/controller/checkly/alertchannel_controller_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,11 +115,15 @@ var _ = Describe("ApiCheck Controller", func() {
115115
Eventually(func() bool {
116116
f := &checklyv1alpha1.AlertChannel{}
117117
err := k8sClient.Get(context.Background(), acKey, f)
118-
if len(f.Finalizers) == 1 && err == nil {
119-
return true
120-
} else {
118+
if err != nil {
121119
return false
122120
}
121+
122+
for _, finalizer := range f.Finalizers {
123+
Expect(finalizer).To(Equal("testing.domain.tld/finalizer"), "Finalizer should match")
124+
}
125+
126+
return true
123127
}, timeout, interval).Should(BeTrue())
124128

125129
// Update

internal/controller/checkly/apicheck_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package checkly
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
"k8s.io/apimachinery/pkg/api/errors"
2324
"k8s.io/apimachinery/pkg/runtime"
@@ -35,8 +36,9 @@ import (
3536
// ApiCheckReconciler reconciles a ApiCheck object
3637
type ApiCheckReconciler struct {
3738
client.Client
38-
Scheme *runtime.Scheme
39-
ApiClient checkly.Client
39+
Scheme *runtime.Scheme
40+
ApiClient checkly.Client
41+
ControllerDomain string
4042
}
4143

4244
//+kubebuilder:rbac:groups=k8s.checklyhq.com,resources=apichecks,verbs=get;list;watch;create;update;patch;delete
@@ -56,7 +58,7 @@ type ApiCheckReconciler struct {
5658
func (r *ApiCheckReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
5759
logger := log.FromContext(ctx)
5860

59-
apiCheckFinalizer := "k8s.checklyhq.com/finalizer"
61+
apiCheckFinalizer := fmt.Sprintf("%s/finalizer", r.ControllerDomain)
6062

6163
apiCheck := &checklyv1alpha1.ApiCheck{}
6264

internal/controller/checkly/apicheck_controller_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,11 +117,15 @@ var _ = Describe("ApiCheck Controller", func() {
117117
Eventually(func() bool {
118118
f := &checklyv1alpha1.ApiCheck{}
119119
err := k8sClient.Get(context.Background(), key, f)
120-
if len(f.Finalizers) == 1 && err == nil {
121-
return true
122-
} else {
120+
if err != nil {
123121
return false
124122
}
123+
124+
for _, finalizer := range f.Finalizers {
125+
Expect(finalizer).To(Equal("testing.domain.tld/finalizer"), "Finalizer should match")
126+
}
127+
128+
return true
125129
}, timeout, interval).Should(BeTrue())
126130

127131
// Delete

internal/controller/checkly/group_controller.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package checkly
1818

1919
import (
2020
"context"
21+
"fmt"
2122

2223
"k8s.io/apimachinery/pkg/api/errors"
2324
"k8s.io/apimachinery/pkg/runtime"
@@ -35,8 +36,9 @@ import (
3536
// GroupReconciler reconciles a Group object
3637
type GroupReconciler struct {
3738
client.Client
38-
Scheme *runtime.Scheme
39-
ApiClient checkly.Client
39+
Scheme *runtime.Scheme
40+
ApiClient checkly.Client
41+
ControllerDomain string
4042
}
4143

4244
//+kubebuilder:rbac:groups=k8s.checklyhq.com,resources=groups,verbs=get;list;watch;create;update;patch;delete
@@ -53,7 +55,7 @@ func (r *GroupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl
5355

5456
logger.Info("Reconciler started")
5557

56-
groupFinalizer := "k8s.checklyhq.com/finalizer"
58+
groupFinalizer := fmt.Sprintf("%s/finalizer", r.ControllerDomain)
5759

5860
group := &checklyv1alpha1.Group{}
5961

internal/controller/checkly/group_controller_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,11 +111,15 @@ var _ = Describe("ApiCheck Controller", func() {
111111
Eventually(func() bool {
112112
f := &checklyv1alpha1.Group{}
113113
err := k8sClient.Get(context.Background(), groupKey, f)
114-
if len(f.Finalizers) == 1 && err == nil {
115-
return true
116-
} else {
114+
if err != nil {
117115
return false
118116
}
117+
118+
for _, finalizer := range f.Finalizers {
119+
Expect(finalizer).To(Equal("testing.domain.tld/finalizer"), "Finalizer should match")
120+
}
121+
122+
return true
119123
}, timeout, interval).Should(BeTrue())
120124

121125
// Update

internal/controller/checkly/suite_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,24 +168,29 @@ var _ = BeforeSuite(func() {
168168
http.ListenAndServe(":5555", nil)
169169
}()
170170

171+
testControllerDomain := "testing.domain.tld"
172+
171173
err = (&ApiCheckReconciler{
172-
Client: k8sManager.GetClient(),
173-
Scheme: k8sManager.GetScheme(),
174-
ApiClient: testClient,
174+
Client: k8sManager.GetClient(),
175+
Scheme: k8sManager.GetScheme(),
176+
ApiClient: testClient,
177+
ControllerDomain: testControllerDomain,
175178
}).SetupWithManager(k8sManager)
176179
Expect(err).ToNot(HaveOccurred())
177180

178181
err = (&GroupReconciler{
179-
Client: k8sManager.GetClient(),
180-
Scheme: k8sManager.GetScheme(),
181-
ApiClient: testClient,
182+
Client: k8sManager.GetClient(),
183+
Scheme: k8sManager.GetScheme(),
184+
ApiClient: testClient,
185+
ControllerDomain: testControllerDomain,
182186
}).SetupWithManager(k8sManager)
183187
Expect(err).ToNot(HaveOccurred())
184188

185189
err = (&AlertChannelReconciler{
186-
Client: k8sManager.GetClient(),
187-
Scheme: k8sManager.GetScheme(),
188-
ApiClient: testClient,
190+
Client: k8sManager.GetClient(),
191+
Scheme: k8sManager.GetScheme(),
192+
ApiClient: testClient,
193+
ControllerDomain: testControllerDomain,
189194
}).SetupWithManager(k8sManager)
190195
Expect(err).ToNot(HaveOccurred())
191196

0 commit comments

Comments
 (0)