@@ -44,6 +44,7 @@ import (
44
44
"sigs.k8s.io/controller-runtime/pkg/controller"
45
45
"sigs.k8s.io/controller-runtime/pkg/handler"
46
46
"sigs.k8s.io/controller-runtime/pkg/predicate"
47
+ "sigs.k8s.io/controller-runtime/pkg/predicate"
47
48
ctrlpredicate "sigs.k8s.io/controller-runtime/pkg/predicate"
48
49
"sigs.k8s.io/controller-runtime/pkg/source"
49
50
@@ -81,6 +82,7 @@ type Reconciler struct {
81
82
selectorPredicate predicate.Predicate
82
83
overrideValues map [string ]string
83
84
skipDependentWatches bool
85
+ extraWatches []watchDescription
84
86
maxConcurrentReconciles int
85
87
reconcilePeriod time.Duration
86
88
markFailedAfter time.Duration
@@ -97,6 +99,12 @@ type Reconciler struct {
97
99
uninstallAnnotations map [string ]annotation.Uninstall
98
100
}
99
101
102
+ type watchDescription struct {
103
+ src source.Source
104
+ predicates []predicate.Predicate
105
+ handler handler.EventHandler
106
+ }
107
+
100
108
// New creates a new Reconciler that reconciles custom resources that define a
101
109
// Helm release. New takes variadic Option arguments that are used to configure
102
110
// the Reconciler.
@@ -538,6 +546,22 @@ func WithValueMapper(m values.Mapper) Option {
538
546
}
539
547
}
540
548
549
+ // WithExtraWatch is an Option that adds an extra event watch.
550
+ // Use this if you want your controller to respond to events other than coming from the primary custom resource,
551
+ // the helm release secret, or resources created by your helm chart.
552
+ // The meaning of the arguments is the same as for sigs.k8s.io/controller-runtime/pkg/controller.Controller Watch
553
+ // function.
554
+ func WithExtraWatch (src source.Source , handler handler.EventHandler , predicates ... predicate.Predicate ) Option {
555
+ return func (r * Reconciler ) error {
556
+ r .extraWatches = append (r .extraWatches , watchDescription {
557
+ src : src ,
558
+ predicates : predicates ,
559
+ handler : handler ,
560
+ })
561
+ return nil
562
+ }
563
+ }
564
+
541
565
// WithSelector is an Option that configures the reconciler to creates a
542
566
// predicate that is used to filter resources based on the specified selector
543
567
func WithSelector (s metav1.LabelSelector ) Option {
@@ -1104,6 +1128,12 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
1104
1128
return err
1105
1129
}
1106
1130
1131
+ for _ , w := range r .extraWatches {
1132
+ if err := c .Watch (w .src , w .handler , w .predicates ... ); err != nil {
1133
+ return err
1134
+ }
1135
+ }
1136
+
1107
1137
if ! r .skipDependentWatches {
1108
1138
r .postHooks = append ([]hook.PostHook {internalhook .NewDependentResourceWatcher (c , mgr .GetRESTMapper (), mgr .GetCache (), mgr .GetScheme ())}, r .postHooks ... )
1109
1139
}
0 commit comments