@@ -145,7 +145,10 @@ func (r *Reconciler) setupAnnotationMaps() {
145145func (r * Reconciler ) SetupWithManager (mgr ctrl.Manager ) error {
146146 controllerName := fmt .Sprintf ("%v-controller" , strings .ToLower (r .gvk .Kind ))
147147
148- r .addDefaults (mgr , controllerName )
148+ if err := r .addDefaults (mgr , controllerName ); err != nil {
149+ return err
150+ }
151+
149152 if ! r .skipPrimaryGVKSchemeRegistration {
150153 r .setupScheme (mgr )
151154 }
@@ -294,33 +297,33 @@ func StripManifestFromStatus(strip bool) Option {
294297//
295298// Example for using a custom type for the GVK scheme instead of unstructured.Unstructured:
296299//
297- // // Define custom type for GVK scheme.
298- // //+kubebuilder:object:root=true
299- // type Custom struct {
300- // // [...]
301- // }
300+ // // Define custom type for GVK scheme.
301+ // //+kubebuilder:object:root=true
302+ // type Custom struct {
303+ // // [...]
304+ // }
302305//
303- // // Register custom type along with common meta types in scheme.
304- // scheme := runtime.NewScheme()
305- // scheme.AddKnownTypes(SchemeGroupVersion, &Custom{})
306- // metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
306+ // // Register custom type along with common meta types in scheme.
307+ // scheme := runtime.NewScheme()
308+ // scheme.AddKnownTypes(SchemeGroupVersion, &Custom{})
309+ // metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
307310//
308- // // Create new manager using the controller-runtime, injecting above scheme.
309- // options := ctrl.Options{
310- // Scheme = scheme,
311- // // [...]
312- // }
313- // mgr, err := ctrl.NewManager(config, options)
311+ // // Create new manager using the controller-runtime, injecting above scheme.
312+ // options := ctrl.Options{
313+ // Scheme = scheme,
314+ // // [...]
315+ // }
316+ // mgr, err := ctrl.NewManager(config, options)
314317//
315- // // Create reconciler with generic scheme registration being disabled.
316- // r, err := reconciler.New(
317- // reconciler.WithChart(chart),
318- // reconciler.SkipPrimaryGVKSchemeRegistration(true),
319- // // [...]
320- // )
318+ // // Create reconciler with generic scheme registration being disabled.
319+ // r, err := reconciler.New(
320+ // reconciler.WithChart(chart),
321+ // reconciler.SkipPrimaryGVKSchemeRegistration(true),
322+ // // [...]
323+ // )
321324//
322- // // Setup reconciler with above manager.
323- // err = r.SetupWithManager(mgr)
325+ // // Setup reconciler with above manager.
326+ // err = r.SetupWithManager(mgr)
324327//
325328// By default, skipping of the generic scheme setup is disabled, which means that
326329// unstructured.Unstructured is used for the GVK scheme.
@@ -501,16 +504,16 @@ func WithPostExtension(e extensions.ReconcileExtension) Option {
501504// If you wish to, you can convert the Unstructured that is passed to your Translator to your own
502505// Custom Resource struct like this:
503506//
504- // import "k8s.io/apimachinery/pkg/runtime"
505- // foo := your.Foo{}
506- // if err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &foo); err != nil {
507- // return nil, err
508- // }
509- // // work with the type-safe foo
507+ // import "k8s.io/apimachinery/pkg/runtime"
508+ // foo := your.Foo{}
509+ // if err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &foo); err != nil {
510+ // return nil, err
511+ // }
512+ // // work with the type-safe foo
510513//
511514// Alternatively, your translator can also work similarly to a Mapper, by accessing the spec with:
512515//
513- // u.Object["spec"].(map[string]interface{})
516+ // u.Object["spec"].(map[string]interface{})
514517func WithValueTranslator (t values.Translator ) Option {
515518 return func (r * Reconciler ) error {
516519 r .valueTranslator = t
@@ -995,15 +998,18 @@ func (r *Reconciler) validate() error {
995998 return nil
996999}
9971000
998- func (r * Reconciler ) addDefaults (mgr ctrl.Manager , controllerName string ) {
1001+ func (r * Reconciler ) addDefaults (mgr ctrl.Manager , controllerName string ) error {
9991002 if r .client == nil {
10001003 r .client = mgr .GetClient ()
10011004 }
10021005 if r .log .GetSink () == nil {
10031006 r .log = ctrl .Log .WithName ("controllers" ).WithName ("Helm" )
10041007 }
10051008 if r .actionClientGetter == nil {
1006- actionConfigGetter := helmclient .NewActionConfigGetter (mgr .GetConfig (), mgr .GetRESTMapper (), r .log )
1009+ actionConfigGetter , err := helmclient .NewActionConfigGetter (mgr .GetConfig (), mgr .GetRESTMapper (), r .log )
1010+ if err != nil {
1011+ return fmt .Errorf ("creating action config getter: %w" , err )
1012+ }
10071013 r .actionClientGetter = helmclient .NewActionClientGetter (actionConfigGetter )
10081014 }
10091015 if r .eventRecorder == nil {
@@ -1015,6 +1021,7 @@ func (r *Reconciler) addDefaults(mgr ctrl.Manager, controllerName string) {
10151021 if r .valueMapper == nil {
10161022 r .valueMapper = internalvalues .DefaultMapper
10171023 }
1024+ return nil
10181025}
10191026
10201027func (r * Reconciler ) setupScheme (mgr ctrl.Manager ) {
0 commit comments