Skip to content

Commit 6c01a78

Browse files
committed
ROX- 8130: Add WithExtraWatch option. (#22)
1 parent d83cfea commit 6c01a78

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
@@ -81,6 +81,7 @@ type Reconciler struct {
8181
selectorPredicate predicate.Predicate
8282
overrideValues map[string]string
8383
skipDependentWatches bool
84+
extraWatchSources []source.Source
8485
maxConcurrentReconciles int
8586
reconcilePeriod time.Duration
8687
waitForDeletionTimeout time.Duration
@@ -555,6 +556,16 @@ func WithValueMapper(m values.Mapper) Option {
555556
}
556557
}
557558

559+
// WithExtraWatch is an Option that adds an extra event watch.
560+
// Use this if you want your controller to respond to events other than coming from the primary custom resource,
561+
// the helm release secret, or resources created by your helm chart.
562+
func WithExtraWatch(src source.Source) Option {
563+
return func(r *Reconciler) error {
564+
r.extraWatchSources = append(r.extraWatchSources, src)
565+
return nil
566+
}
567+
}
568+
558569
// WithSelector is an Option that configures the reconciler to creates a
559570
// predicate that is used to filter resources based on the specified selector
560571
func WithSelector(s metav1.LabelSelector) Option {
@@ -1144,6 +1155,12 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
11441155
return err
11451156
}
11461157

1158+
for _, s := range r.extraWatchSources {
1159+
if err := c.Watch(s); err != nil {
1160+
return err
1161+
}
1162+
}
1163+
11471164
if !r.skipDependentWatches {
11481165
r.postHooks = append([]hook.PostHook{internalhook.NewDependentResourceWatcher(c, mgr.GetRESTMapper(), mgr.GetCache(), mgr.GetScheme())}, r.postHooks...)
11491166
}

0 commit comments

Comments
 (0)