@@ -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
@@ -80,6 +81,7 @@ type Reconciler struct {
80
81
selectorPredicate predicate.Predicate
81
82
overrideValues map [string ]string
82
83
skipDependentWatches bool
84
+ extraWatches []watchDescription
83
85
maxConcurrentReconciles int
84
86
reconcilePeriod time.Duration
85
87
markFailedAfter time.Duration
@@ -95,6 +97,12 @@ type Reconciler struct {
95
97
uninstallAnnotations map [string ]annotation.Uninstall
96
98
}
97
99
100
+ type watchDescription struct {
101
+ src source.Source
102
+ predicates []predicate.Predicate
103
+ handler handler.EventHandler
104
+ }
105
+
98
106
// New creates a new Reconciler that reconciles custom resources that define a
99
107
// Helm release. New takes variadic Option arguments that are used to configure
100
108
// the Reconciler.
@@ -529,6 +537,22 @@ func WithValueMapper(m values.Mapper) Option {
529
537
}
530
538
}
531
539
540
+ // WithExtraWatch is an Option that adds an extra event watch.
541
+ // Use this if you want your controller to respond to events other than coming from the primary custom resource,
542
+ // the helm release secret, or resources created by your helm chart.
543
+ // The meaning of the arguments is the same as for sigs.k8s.io/controller-runtime/pkg/controller.Controller Watch
544
+ // function.
545
+ func WithExtraWatch (src source.Source , handler handler.EventHandler , predicates ... predicate.Predicate ) Option {
546
+ return func (r * Reconciler ) error {
547
+ r .extraWatches = append (r .extraWatches , watchDescription {
548
+ src : src ,
549
+ predicates : predicates ,
550
+ handler : handler ,
551
+ })
552
+ return nil
553
+ }
554
+ }
555
+
532
556
// WithSelector is an Option that configures the reconciler to creates a
533
557
// predicate that is used to filter resources based on the specified selector
534
558
func WithSelector (s metav1.LabelSelector ) Option {
@@ -1063,6 +1087,12 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
1063
1087
return err
1064
1088
}
1065
1089
1090
+ for _ , w := range r .extraWatches {
1091
+ if err := c .Watch (w .src , w .handler , w .predicates ... ); err != nil {
1092
+ return err
1093
+ }
1094
+ }
1095
+
1066
1096
if ! r .skipDependentWatches {
1067
1097
r .postHooks = append ([]hook.PostHook {internalhook .NewDependentResourceWatcher (c , mgr .GetRESTMapper ())}, r .postHooks ... )
1068
1098
}
0 commit comments