@@ -132,7 +132,10 @@ func (r *Reconciler) setupAnnotationMaps() {
132132func (r * Reconciler ) SetupWithManager (mgr ctrl.Manager ) error {
133133 controllerName := fmt .Sprintf ("%v-controller" , strings .ToLower (r .gvk .Kind ))
134134
135- r .addDefaults (mgr , controllerName )
135+ if err := r .addDefaults (mgr , controllerName ); err != nil {
136+ return err
137+ }
138+
136139 if ! r .skipPrimaryGVKSchemeRegistration {
137140 r .setupScheme (mgr )
138141 }
@@ -270,33 +273,33 @@ func SkipDependentWatches(skip bool) Option {
270273//
271274// Example for using a custom type for the GVK scheme instead of unstructured.Unstructured:
272275//
273- // // Define custom type for GVK scheme.
274- // //+kubebuilder:object:root=true
275- // type Custom struct {
276- // // [...]
277- // }
276+ // // Define custom type for GVK scheme.
277+ // //+kubebuilder:object:root=true
278+ // type Custom struct {
279+ // // [...]
280+ // }
278281//
279- // // Register custom type along with common meta types in scheme.
280- // scheme := runtime.NewScheme()
281- // scheme.AddKnownTypes(SchemeGroupVersion, &Custom{})
282- // metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
282+ // // Register custom type along with common meta types in scheme.
283+ // scheme := runtime.NewScheme()
284+ // scheme.AddKnownTypes(SchemeGroupVersion, &Custom{})
285+ // metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
283286//
284- // // Create new manager using the controller-runtime, injecting above scheme.
285- // options := ctrl.Options{
286- // Scheme = scheme,
287- // // [...]
288- // }
289- // mgr, err := ctrl.NewManager(config, options)
287+ // // Create new manager using the controller-runtime, injecting above scheme.
288+ // options := ctrl.Options{
289+ // Scheme = scheme,
290+ // // [...]
291+ // }
292+ // mgr, err := ctrl.NewManager(config, options)
290293//
291- // // Create reconciler with generic scheme registration being disabled.
292- // r, err := reconciler.New(
293- // reconciler.WithChart(chart),
294- // reconciler.SkipPrimaryGVKSchemeRegistration(true),
295- // // [...]
296- // )
294+ // // Create reconciler with generic scheme registration being disabled.
295+ // r, err := reconciler.New(
296+ // reconciler.WithChart(chart),
297+ // reconciler.SkipPrimaryGVKSchemeRegistration(true),
298+ // // [...]
299+ // )
297300//
298- // // Setup reconciler with above manager.
299- // err = r.SetupWithManager(mgr)
301+ // // Setup reconciler with above manager.
302+ // err = r.SetupWithManager(mgr)
300303//
301304// By default, skipping of the generic scheme setup is disabled, which means that
302305// unstructured.Unstructured is used for the GVK scheme.
@@ -435,16 +438,16 @@ func WithPostHook(h hook.PostHook) Option {
435438// If you wish to, you can convert the Unstructured that is passed to your Translator to your own
436439// Custom Resource struct like this:
437440//
438- // import "k8s.io/apimachinery/pkg/runtime"
439- // foo := your.Foo{}
440- // if err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &foo); err != nil {
441- // return nil, err
442- // }
443- // // work with the type-safe foo
441+ // import "k8s.io/apimachinery/pkg/runtime"
442+ // foo := your.Foo{}
443+ // if err = runtime.DefaultUnstructuredConverter.FromUnstructured(u.Object, &foo); err != nil {
444+ // return nil, err
445+ // }
446+ // // work with the type-safe foo
444447//
445448// Alternatively, your translator can also work similarly to a Mapper, by accessing the spec with:
446449//
447- // u.Object["spec"].(map[string]interface{})
450+ // u.Object["spec"].(map[string]interface{})
448451func WithValueTranslator (t values.Translator ) Option {
449452 return func (r * Reconciler ) error {
450453 r .valueTranslator = t
@@ -866,15 +869,18 @@ func (r *Reconciler) validate() error {
866869 return nil
867870}
868871
869- func (r * Reconciler ) addDefaults (mgr ctrl.Manager , controllerName string ) {
872+ func (r * Reconciler ) addDefaults (mgr ctrl.Manager , controllerName string ) error {
870873 if r .client == nil {
871874 r .client = mgr .GetClient ()
872875 }
873876 if r .log .GetSink () == nil {
874877 r .log = ctrl .Log .WithName ("controllers" ).WithName ("Helm" )
875878 }
876879 if r .actionClientGetter == nil {
877- actionConfigGetter := helmclient .NewActionConfigGetter (mgr .GetConfig (), mgr .GetRESTMapper (), r .log )
880+ actionConfigGetter , err := helmclient .NewActionConfigGetter (mgr .GetConfig (), mgr .GetRESTMapper (), r .log )
881+ if err != nil {
882+ return fmt .Errorf ("creating action config getter: %w" , err )
883+ }
878884 r .actionClientGetter = helmclient .NewActionClientGetter (actionConfigGetter )
879885 }
880886 if r .eventRecorder == nil {
@@ -886,6 +892,7 @@ func (r *Reconciler) addDefaults(mgr ctrl.Manager, controllerName string) {
886892 if r .valueMapper == nil {
887893 r .valueMapper = internalvalues .DefaultMapper
888894 }
895+ return nil
889896}
890897
891898func (r * Reconciler ) setupScheme (mgr ctrl.Manager ) {
0 commit comments