Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
ROX- 8130: Add WithExtraWatch option. (#22)
  • Loading branch information
porridge committed Sep 5, 2024
commit 991117d986687eb0d68cbfeb1951f3492bb1d50d
23 changes: 23 additions & 0 deletions pkg/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ type Reconciler struct {
selectorPredicate predicate.Predicate
overrideValues map[string]string
skipDependentWatches bool
extraWatchSources []source.Source
maxConcurrentReconciles int
reconcilePeriod time.Duration
waitForDeletionTimeout time.Duration
Expand All @@ -98,6 +99,12 @@ type Reconciler struct {
uninstallAnnotations map[string]annotation.Uninstall
}

type watchDescription struct {
src source.Source
predicates []predicate.Predicate
handler handler.EventHandler
}

// New creates a new Reconciler that reconciles custom resources that define a
// Helm release. New takes variadic Option arguments that are used to configure
// the Reconciler.
Expand Down Expand Up @@ -555,6 +562,16 @@ func WithValueMapper(m values.Mapper) Option {
}
}

// WithExtraWatch is an Option that adds an extra event watch.
// Use this if you want your controller to respond to events other than coming from the primary custom resource,
// the helm release secret, or resources created by your helm chart.
func WithExtraWatch(src source.Source) Option {
return func(r *Reconciler) error {
r.extraWatchSources = append(r.extraWatchSources, src)
return nil
}
}

// WithSelector is an Option that configures the reconciler to creates a
// predicate that is used to filter resources based on the specified selector
func WithSelector(s metav1.LabelSelector) Option {
Expand Down Expand Up @@ -1144,6 +1161,12 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
return err
}

for _, s := range r.extraWatchSources {
if err := c.Watch(s); err != nil {
return err
}
}

if !r.skipDependentWatches {
r.postHooks = append([]hook.PostHook{internalhook.NewDependentResourceWatcher(c, mgr.GetRESTMapper(), mgr.GetCache(), mgr.GetScheme())}, r.postHooks...)
}
Expand Down