@@ -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.
@@ -526,6 +534,22 @@ func WithValueMapper(m values.Mapper) Option {
526
534
}
527
535
}
528
536
537
+ // WithExtraWatch is an Option that adds an extra event watch.
538
+ // Use this if you want your controller to respond to events other than coming from the primary custom resource,
539
+ // the helm release secret, or resources created by your helm chart.
540
+ // The meaning of the arguments is the same as for sigs.k8s.io/controller-runtime/pkg/controller.Controller Watch
541
+ // function.
542
+ func WithExtraWatch (src source.Source , handler handler.EventHandler , predicates ... predicate.Predicate ) Option {
543
+ return func (r * Reconciler ) error {
544
+ r .extraWatches = append (r .extraWatches , watchDescription {
545
+ src : src ,
546
+ predicates : predicates ,
547
+ handler : handler ,
548
+ })
549
+ return nil
550
+ }
551
+ }
552
+
529
553
// WithSelector is an Option that configures the reconciler to creates a
530
554
// predicate that is used to filter resources based on the specified selector
531
555
func WithSelector (s metav1.LabelSelector ) Option {
@@ -1056,6 +1080,12 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
1056
1080
return err
1057
1081
}
1058
1082
1083
+ for _ , w := range r .extraWatches {
1084
+ if err := c .Watch (w .src , w .handler , w .predicates ... ); err != nil {
1085
+ return err
1086
+ }
1087
+ }
1088
+
1059
1089
if ! r .skipDependentWatches {
1060
1090
r .postHooks = append ([]hook.PostHook {internalhook .NewDependentResourceWatcher (c , mgr .GetRESTMapper ())}, r .postHooks ... )
1061
1091
}
0 commit comments