Skip to content

Commit e51f296

Browse files
committed
Add WithExtraWatch option.
1 parent 6261f25 commit e51f296

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

pkg/reconciler/reconciler.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ type Reconciler struct {
7777
selectorPredicate predicate.Predicate
7878
overrideValues map[string]string
7979
skipDependentWatches bool
80+
extraWatchSources []source.Source
8081
maxConcurrentReconciles int
8182
reconcilePeriod time.Duration
8283
waitForDeletionTimeout time.Duration
@@ -495,6 +496,16 @@ func WithValueMapper(m values.Mapper) Option {
495496
}
496497
}
497498

499+
// WithExtraWatch is an Option that adds an extra event watch.
500+
// Use this if you want your controller to respond to events other than coming from the primary custom resource,
501+
// the helm release secret, or resources created by your helm chart.
502+
func WithExtraWatch(src source.Source) Option {
503+
return func(r *Reconciler) error {
504+
r.extraWatchSources = append(r.extraWatchSources, src)
505+
return nil
506+
}
507+
}
508+
498509
// WithSelector is an Option that configures the reconciler to creates a
499510
// predicate that is used to filter resources based on the specified selector
500511
func WithSelector(s metav1.LabelSelector) Option {
@@ -1015,6 +1026,12 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
10151026
return err
10161027
}
10171028

1029+
for _, s := range r.extraWatchSources {
1030+
if err := c.Watch(s); err != nil {
1031+
return err
1032+
}
1033+
}
1034+
10181035
if !r.skipDependentWatches {
10191036
r.postHooks = append([]hook.PostHook{internalhook.NewDependentResourceWatcher(c, mgr.GetRESTMapper(), mgr.GetCache(), mgr.GetScheme())}, r.postHooks...)
10201037
}

0 commit comments

Comments
 (0)