Add creates a new helm operator controller and adds it to the manager
(mgr manager.Manager, options WatchOptions)
| 58 | |
| 59 | // Add creates a new helm operator controller and adds it to the manager |
| 60 | func Add(mgr manager.Manager, options WatchOptions) error { |
| 61 | controllerName := fmt.Sprintf("%v-controller", strings.ToLower(options.GVK.Kind)) |
| 62 | |
| 63 | r := &HelmOperatorReconciler{ |
| 64 | Client: mgr.GetClient(), |
| 65 | EventRecorder: mgr.GetEventRecorderFor(controllerName), |
| 66 | GVK: options.GVK, |
| 67 | ManagerFactory: options.ManagerFactory, |
| 68 | ReconcilePeriod: options.ReconcilePeriod, |
| 69 | OverrideValues: options.OverrideValues, |
| 70 | SuppressOverrideValues: options.SuppressOverrideValues, |
| 71 | DryRunOption: options.DryRunOption, |
| 72 | } |
| 73 | |
| 74 | c, err := controller.New(controllerName, mgr, controller.Options{ |
| 75 | Reconciler: r, |
| 76 | MaxConcurrentReconciles: options.MaxConcurrentReconciles, |
| 77 | }) |
| 78 | if err != nil { |
| 79 | return err |
| 80 | } |
| 81 | |
| 82 | o := &unstructured.Unstructured{} |
| 83 | o.SetGroupVersionKind(options.GVK) |
| 84 | |
| 85 | if err := c.Watch(source.Kind(mgr.GetCache(), client.Object(o), &libhandler.InstrumentedEnqueueRequestForObject[client.Object]{})); err != nil { |
| 86 | return err |
| 87 | } |
| 88 | |
| 89 | if options.WatchDependentResources { |
| 90 | watchDependentResources(mgr, r, c) |
| 91 | } |
| 92 | |
| 93 | log.Info("Watching resource", "apiVersion", options.GVK.GroupVersion(), "kind", |
| 94 | options.GVK.Kind, "reconcilePeriod", options.ReconcilePeriod.String()) |
| 95 | return nil |
| 96 | } |
| 97 | |
| 98 | // watchDependentResources adds a release hook function to the HelmOperatorReconciler |
| 99 | // that adds watches for resources in released Helm charts. |
no test coverage detected