diff --git a/internal/cmd/helm-operator/run/cmd.go b/internal/cmd/helm-operator/run/cmd.go index e909d27cb4c..37b5fb0ab2b 100644 --- a/internal/cmd/helm-operator/run/cmd.go +++ b/internal/cmd/helm-operator/run/cmd.go @@ -194,11 +194,16 @@ func run(cmd *cobra.Command, f *flags.Flags) { } for _, w := range ws { // Register the controller with the factory. + reconcilePeriod := f.ReconcilePeriod.String() // from flag + if w.ReconcilePeriod != "" { + reconcilePeriod = w.ReconcilePeriod // watches takes precedence + } + err := controller.Add(mgr, controller.WatchOptions{ Namespace: namespace, GVK: w.GroupVersionKind, ManagerFactory: release.NewManagerFactory(mgr, w.ChartDir), - ReconcilePeriod: f.ReconcilePeriod, + ReconcilePeriod: reconcilePeriod, WatchDependentResources: *w.WatchDependentResources, OverrideValues: w.OverrideValues, MaxConcurrentReconciles: f.MaxConcurrentReconciles, diff --git a/internal/helm/controller/controller.go b/internal/helm/controller/controller.go index 7b4e44ba303..4c8803733b4 100644 --- a/internal/helm/controller/controller.go +++ b/internal/helm/controller/controller.go @@ -49,7 +49,7 @@ type WatchOptions struct { Namespace string GVK schema.GroupVersionKind ManagerFactory release.ManagerFactory - ReconcilePeriod time.Duration + ReconcilePeriod string WatchDependentResources bool OverrideValues map[string]string MaxConcurrentReconciles int @@ -59,13 +59,17 @@ type WatchOptions struct { // Add creates a new helm operator controller and adds it to the manager func Add(mgr manager.Manager, options WatchOptions) error { controllerName := fmt.Sprintf("%v-controller", strings.ToLower(options.GVK.Kind)) + duration, err := time.ParseDuration(options.ReconcilePeriod) + if err != nil { + return err + } r := &HelmOperatorReconciler{ Client: mgr.GetClient(), EventRecorder: mgr.GetEventRecorderFor(controllerName), GVK: options.GVK, ManagerFactory: options.ManagerFactory, - ReconcilePeriod: options.ReconcilePeriod, + ReconcilePeriod: duration, OverrideValues: options.OverrideValues, } @@ -104,7 +108,7 @@ func Add(mgr manager.Manager, options WatchOptions) error { } log.Info("Watching resource", "apiVersion", options.GVK.GroupVersion(), "kind", - options.GVK.Kind, "namespace", options.Namespace, "reconcilePeriod", options.ReconcilePeriod.String()) + options.GVK.Kind, "namespace", options.Namespace, "reconcilePeriod", duration) return nil } diff --git a/internal/helm/watches/watches.go b/internal/helm/watches/watches.go index e2f43a1d55c..f34de713860 100644 --- a/internal/helm/watches/watches.go +++ b/internal/helm/watches/watches.go @@ -40,6 +40,7 @@ type Watch struct { WatchDependentResources *bool `json:"watchDependentResources,omitempty"` OverrideValues map[string]string `json:"overrideValues,omitempty"` Selector metav1.LabelSelector `json:"selector"` + ReconcilePeriod string `json:"reconcilePeriod"` } // UnmarshalYAML unmarshals an individual watch from the Helm watches.yaml file