Skip to content

Commit

Permalink
parsing of watches.yaml
Browse files Browse the repository at this point in the history
Signed-off-by: Venkat Ramaraju <[email protected]>
  • Loading branch information
Venkat Ramaraju committed Mar 9, 2022
1 parent a0b2916 commit 3bc5570
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 6 additions & 1 deletion internal/cmd/helm-operator/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 7 additions & 3 deletions internal/helm/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
}

Expand Down Expand Up @@ -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
}

Expand Down
1 change: 1 addition & 0 deletions internal/helm/watches/watches.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3bc5570

Please sign in to comment.