@@ -42,6 +42,7 @@ import (
4242 "sigs.k8s.io/controller-runtime/pkg/client"
4343 "sigs.k8s.io/controller-runtime/pkg/controller"
4444 "sigs.k8s.io/controller-runtime/pkg/handler"
45+ "sigs.k8s.io/controller-runtime/pkg/predicate"
4546 "sigs.k8s.io/controller-runtime/pkg/source"
4647
4748 "github.com/joelanford/helm-operator/pkg/annotation"
@@ -76,6 +77,7 @@ type Reconciler struct {
7677 chrt * chart.Chart
7778 overrideValues map [string ]string
7879 skipDependentWatches bool
80+ extraWatches []watchDescription
7981 maxConcurrentReconciles int
8082 reconcilePeriod time.Duration
8183 markFailedAfter time.Duration
@@ -90,6 +92,12 @@ type Reconciler struct {
9092 uninstallAnnotations map [string ]annotation.Uninstall
9193}
9294
95+ type watchDescription struct {
96+ src source.Source
97+ predicates []predicate.Predicate
98+ handler handler.EventHandler
99+ }
100+
93101// New creates a new Reconciler that reconciles custom resources that define a
94102// Helm release. New takes variadic Option arguments that are used to configure
95103// the Reconciler.
@@ -463,6 +471,22 @@ func WithValueMapper(m values.Mapper) Option {
463471 }
464472}
465473
474+ // WithExtraWatch is an Option that adds an extra event watch.
475+ // Use this if you want your controller to respond to events other than coming from the primary custom resource,
476+ // the helm release secret, or resources created by your helm chart.
477+ // The meaning of the arguments is the same as for sigs.k8s.io/controller-runtime/pkg/controller.Controller Watch
478+ // function.
479+ func WithExtraWatch (src source.Source , handler handler.EventHandler , predicates ... predicate.Predicate ) Option {
480+ return func (r * Reconciler ) error {
481+ r .extraWatches = append (r .extraWatches , watchDescription {
482+ src : src ,
483+ predicates : predicates ,
484+ handler : handler ,
485+ })
486+ return nil
487+ }
488+ }
489+
466490// Reconcile reconciles a CR that defines a Helm v3 release.
467491//
468492// - If a release does not exist for this CR, a new release is installed.
@@ -953,6 +977,12 @@ func (r *Reconciler) setupWatches(mgr ctrl.Manager, c controller.Controller) err
953977 return err
954978 }
955979
980+ for _ , w := range r .extraWatches {
981+ if err := c .Watch (w .src , w .handler , w .predicates ... ); err != nil {
982+ return err
983+ }
984+ }
985+
956986 if ! r .skipDependentWatches {
957987 r .postHooks = append ([]hook.PostHook {internalhook .NewDependentResourceWatcher (c , mgr .GetRESTMapper ())}, r .postHooks ... )
958988 }
0 commit comments