@@ -43,6 +43,7 @@ import (
43
43
"sigs.k8s.io/controller-runtime/pkg/controller"
44
44
"sigs.k8s.io/controller-runtime/pkg/handler"
45
45
"sigs.k8s.io/controller-runtime/pkg/predicate"
46
+ "sigs.k8s.io/controller-runtime/pkg/predicate"
46
47
ctrlpredicate "sigs.k8s.io/controller-runtime/pkg/predicate"
47
48
"sigs.k8s.io/controller-runtime/pkg/source"
48
49
@@ -79,6 +80,7 @@ type Reconciler struct {
79
80
selectorPredicate predicate.Predicate
80
81
overrideValues map [string ]string
81
82
skipDependentWatches bool
83
+ extraWatches []watchDescription
82
84
maxConcurrentReconciles int
83
85
reconcilePeriod time.Duration
84
86
markFailedAfter time.Duration
@@ -94,6 +96,12 @@ type Reconciler struct {
94
96
uninstallAnnotations map [string ]annotation.Uninstall
95
97
}
96
98
99
+ type watchDescription struct {
100
+ src source.Source
101
+ predicates []predicate.Predicate
102
+ handler handler.EventHandler
103
+ }
104
+
97
105
// New creates a new Reconciler that reconciles custom resources that define a
98
106
// Helm release. New takes variadic Option arguments that are used to configure
99
107
// the Reconciler.
@@ -525,6 +533,22 @@ func WithValueMapper(m values.Mapper) Option {
525
533
}
526
534
}
527
535
536
+ // WithExtraWatch is an Option that adds an extra event watch.
537
+ // Use this if you want your controller to respond to events other than coming from the primary custom resource,
538
+ // the helm release secret, or resources created by your helm chart.
539
+ // The meaning of the arguments is the same as for sigs.k8s.io/controller-runtime/pkg/controller.Controller Watch
540
+ // function.
541
+ func WithExtraWatch (src source.Source , handler handler.EventHandler , predicates ... predicate.Predicate ) Option {
542
+ return func (r * Reconciler ) error {
543
+ r .extraWatches = append (r .extraWatches , watchDescription {
544
+ src : src ,
545
+ predicates : predicates ,
546
+ handler : handler ,
547
+ })
548
+ return nil
549
+ }
550
+ }
551
+
528
552
// WithSelector is an Option that configures the reconciler to creates a
529
553
// predicate that is used to filter resources based on the specified selector
530
554
func WithSelector (s metav1.LabelSelector ) Option {
@@ -1033,6 +1057,12 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
1033
1057
return err
1034
1058
}
1035
1059
1060
+ for _ , w := range r .extraWatches {
1061
+ if err := c .Watch (w .src , w .handler , w .predicates ... ); err != nil {
1062
+ return err
1063
+ }
1064
+ }
1065
+
1036
1066
if ! r .skipDependentWatches {
1037
1067
r .postHooks = append ([]hook.PostHook {internalhook .NewDependentResourceWatcher (c , mgr .GetRESTMapper ())}, r .postHooks ... )
1038
1068
}
0 commit comments