@@ -48,6 +48,7 @@ import (
48
48
"sigs.k8s.io/controller-runtime/pkg/log/zap"
49
49
"sigs.k8s.io/controller-runtime/pkg/manager"
50
50
"sigs.k8s.io/controller-runtime/pkg/reconcile"
51
+ "sigs.k8s.io/controller-runtime/pkg/source"
51
52
"sigs.k8s.io/yaml"
52
53
53
54
"github.com/operator-framework/helm-operator-plugins/internal/sdk/controllerutil"
@@ -59,6 +60,7 @@ import (
59
60
"github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/conditions"
60
61
helmfake "github.com/operator-framework/helm-operator-plugins/pkg/reconciler/internal/fake"
61
62
"github.com/operator-framework/helm-operator-plugins/pkg/values"
63
+ sdkhandler "github.com/operator-framework/operator-lib/handler"
62
64
)
63
65
64
66
// custom is used within the reconciler test suite as underlying type for the GVK scheme.
@@ -1328,6 +1330,43 @@ var _ = Describe("Reconciler", func() {
1328
1330
})
1329
1331
1330
1332
})
1333
+
1334
+ var _ = Describe ("Test custom controller setup" , func () {
1335
+ var (
1336
+ mgr manager.Manager
1337
+ r * Reconciler
1338
+ err error
1339
+ controllerSetupCalled bool
1340
+ )
1341
+ additionalGVK := schema.GroupVersionKind {Group : "example.com" , Version : "v1" , Kind : "SomeOtherKind" }
1342
+ setupController := func (c ControllerSetup ) error {
1343
+ controllerSetupCalled = true
1344
+ u := & unstructured.Unstructured {}
1345
+ u .SetGroupVersionKind (additionalGVK )
1346
+ return c .Watch (& source.Kind {Type : u }, & sdkhandler.InstrumentedEnqueueRequestForObject {})
1347
+ }
1348
+
1349
+ It ("Registering builder setup function for reconciler works" , func () {
1350
+ mgr = getManagerOrFail ()
1351
+ r , err = New (
1352
+ WithGroupVersionKind (gvk ),
1353
+ WithChart (chrt ),
1354
+ WithInstallAnnotations (annotation.InstallDescription {}),
1355
+ WithUpgradeAnnotations (annotation.UpgradeDescription {}),
1356
+ WithUninstallAnnotations (annotation.UninstallDescription {}),
1357
+ WithOverrideValues (map [string ]string {
1358
+ "image.repository" : "custom-nginx" ,
1359
+ }),
1360
+ WithControllerSetupFunc (setupController ),
1361
+ )
1362
+ Expect (err ).To (BeNil ())
1363
+ })
1364
+
1365
+ It ("Setting up reconciler with manager causes custom builder setup to be executed" , func () {
1366
+ Expect (r .SetupWithManager (mgr )).To (Succeed ())
1367
+ Expect (controllerSetupCalled ).To (BeTrue ())
1368
+ })
1369
+ })
1331
1370
})
1332
1371
1333
1372
func getManagerOrFail () manager.Manager {
0 commit comments