@@ -23,12 +23,15 @@ import (
23
23
"strings"
24
24
25
25
"github.com/operator-framework/helm-operator-plugins/internal/flags"
26
- "github.com/operator-framework/helm-operator-plugins/internal/legacy/controller"
27
- "github.com/operator-framework/helm-operator-plugins/internal/legacy/release"
28
26
watches "github.com/operator-framework/helm-operator-plugins/internal/legacy/watches"
29
27
"github.com/operator-framework/helm-operator-plugins/internal/metrics"
30
28
"github.com/operator-framework/helm-operator-plugins/internal/version"
29
+ "github.com/operator-framework/helm-operator-plugins/pkg/annotation"
31
30
helmmgr "github.com/operator-framework/helm-operator-plugins/pkg/manager"
31
+ "github.com/operator-framework/helm-operator-plugins/pkg/reconciler"
32
+ "helm.sh/helm/v3/pkg/chart"
33
+ "helm.sh/helm/v3/pkg/chart/loader"
34
+
32
35
"github.com/spf13/cobra"
33
36
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
34
37
ctrl "sigs.k8s.io/controller-runtime"
@@ -167,30 +170,47 @@ func run(cmd *cobra.Command, f *flags.Flags) {
167
170
os .Exit (1 )
168
171
}
169
172
173
+ // TODO: remove legacy watches and use watches from lib
170
174
ws , err := watches .Load (f .WatchesFile )
171
175
if err != nil {
172
176
log .Error (err , "Failed to create new manager factories." )
173
177
os .Exit (1 )
174
178
}
175
179
176
180
for _ , w := range ws {
177
- // Register the controller with the factory.
178
- err := controller .Add (mgr , controller.WatchOptions {
179
- Namespace : namespace ,
180
- GVK : w .GroupVersionKind ,
181
- ManagerFactory : release .NewManagerFactory (mgr , w .ChartDir ),
182
- ReconcilePeriod : f .ReconcilePeriod ,
183
- WatchDependentResources : * w .WatchDependentResources ,
184
- OverrideValues : w .OverrideValues ,
185
- MaxConcurrentReconciles : f .MaxConcurrentReconciles ,
186
- Selector : w .Selector ,
187
- })
181
+
182
+ // TODO: remove this after modifying watches of hybrid lib.
183
+ cl , err := getChart (w )
188
184
if err != nil {
189
- log .Error (err , "Failed to add manager factory to controller." )
185
+ log .Error (err , "Unable to read chart" )
186
+ os .Exit (1 )
187
+ }
188
+
189
+ r , err := reconciler .New (
190
+ reconciler .WithChart (* cl ),
191
+ reconciler .WithGroupVersionKind (w .GroupVersionKind ),
192
+ reconciler .WithOverrideValues (w .OverrideValues ),
193
+ reconciler .WithSelector (w .Selector ),
194
+ reconciler .SkipDependentWatches (* w .WatchDependentResources ),
195
+ reconciler .WithMaxConcurrentReconciles (f .MaxConcurrentReconciles ),
196
+ reconciler .WithReconcilePeriod (f .ReconcilePeriod ),
197
+ reconciler .WithInstallAnnotations (annotation .DefaultInstallAnnotations ... ),
198
+ reconciler .WithUpgradeAnnotations (annotation .DefaultUpgradeAnnotations ... ),
199
+ reconciler .WithUninstallAnnotations (annotation .DefaultUninstallAnnotations ... ),
200
+ )
201
+ if err != nil {
202
+ log .Error (err , "unable to creste helm reconciler" , "controller" , "Helm" )
203
+ os .Exit (1 )
204
+ }
205
+
206
+ if err := r .SetupWithManager (mgr ); err != nil {
207
+ log .Error (err , "unable to create controller" , "Helm" )
190
208
os .Exit (1 )
191
209
}
210
+ log .Info ("configured watch" , "gvk" , w .GroupVersionKind , "chartDir" , w .ChartDir , "maxConcurrentReconciles" , f .MaxConcurrentReconciles , "reconcilePeriod" , f .ReconcilePeriod )
192
211
}
193
212
213
+ log .Info ("starting manager" )
194
214
// Start the Cmd
195
215
if err = mgr .Start (signals .SetupSignalHandler ()); err != nil {
196
216
log .Error (err , "Manager exited non-zero." )
@@ -219,3 +239,13 @@ func exitIfUnsupported(options manager.Options) {
219
239
os .Exit (1 )
220
240
}
221
241
}
242
+
243
+ // getChart returns the chart from the chartDir passed to the watches file.
244
+ func getChart (w watches.Watch ) (* chart.Chart , error ) {
245
+ c , err := loader .LoadDir (w .ChartDir )
246
+ if err != nil {
247
+ return nil , fmt .Errorf ("failed to load chart dir: %w" , err )
248
+ }
249
+
250
+ return c , nil
251
+ }
0 commit comments