@@ -61,6 +61,7 @@ const uninstallFinalizer = "uninstall-helm-release"
61
61
type Reconciler struct {
62
62
client client.Client
63
63
actionClientGetter helmclient.ActionClientGetter
64
+ valueTranslator values.Translator
64
65
valueMapper values.Mapper
65
66
eventRecorder record.EventRecorder
66
67
preHooks []hook.PreHook
@@ -362,8 +363,20 @@ func WithPostHook(h hook.PostHook) Option {
362
363
}
363
364
}
364
365
366
+ // WithValueTranslator is an Option that configures a function that translates a
367
+ // custom resource to the values passed to Helm.
368
+ // Use this if you need to customize the logic that translates your custom resource to Helm values.
369
+ func WithValueTranslator (t values.Translator ) Option {
370
+ return func (r * Reconciler ) error {
371
+ r .valueTranslator = t
372
+ return nil
373
+ }
374
+ }
375
+
365
376
// WithValueMapper is an Option that configures a function that maps values
366
- // from a custom resource spec to the values passed to Helm
377
+ // from a custom resource spec to the values passed to Helm.
378
+ // Use this if you want to apply a transformation on the values obtained from your custom resource, before
379
+ // they are passed to Helm.
367
380
func WithValueMapper (m values.Mapper ) Option {
368
381
return func (r * Reconciler ) error {
369
382
r .valueMapper = m
@@ -522,14 +535,15 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (res ctrl.
522
535
}
523
536
524
537
func (r * Reconciler ) getValues (obj * unstructured.Unstructured ) (chartutil.Values , error ) {
525
- crVals , err := internalvalues . FromUnstructured (obj )
538
+ vals , err := r . valueTranslator . Translate (obj )
526
539
if err != nil {
527
540
return chartutil.Values {}, err
528
541
}
542
+ crVals := internalvalues .New (vals )
529
543
if err := crVals .ApplyOverrides (r .overrideValues ); err != nil {
530
544
return chartutil.Values {}, err
531
545
}
532
- vals : = r .valueMapper .Map (crVals .Map ())
546
+ vals = r .valueMapper .Map (crVals .Map ())
533
547
vals , err = chartutil .CoalesceValues (r .chrt , vals )
534
548
if err != nil {
535
549
return chartutil.Values {}, err
@@ -736,6 +750,9 @@ func (r *Reconciler) addDefaults(mgr ctrl.Manager, controllerName string) {
736
750
if r .eventRecorder == nil {
737
751
r .eventRecorder = mgr .GetEventRecorderFor (controllerName )
738
752
}
753
+ if r .valueTranslator == nil {
754
+ r .valueTranslator = internalvalues .DefaultTranslator
755
+ }
739
756
if r .valueMapper == nil {
740
757
r .valueMapper = internalvalues .DefaultMapper
741
758
}
0 commit comments