Skip to content

Commit d92010a

Browse files
committed
Adding optional field at key level when fetching values from configmap and secret
Signed-off-by: Tanuj Dwivedi <[email protected]> Signed-off-by: tanujd11 <[email protected]>
1 parent 6f0b7cd commit d92010a

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

controllers/helmrelease_controller.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import (
2323
"strings"
2424
"time"
2525

26+
"github.com/go-logr/logr"
2627
"github.com/hashicorp/go-retryablehttp"
2728
"helm.sh/helm/v3/pkg/chart"
2829
"helm.sh/helm/v3/pkg/chartutil"
@@ -542,6 +543,10 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
542543
return nil, fmt.Errorf("could not find %s '%s'", v.Kind, namespacedName)
543544
}
544545
if data, ok := resource.Data[v.GetValuesKey()]; !ok {
546+
if v.Optional {
547+
(logr.FromContext(ctx)).Info(fmt.Sprintf("could not find optional key %s in %s '%s'", v.GetValuesKey(), v.Kind, namespacedName))
548+
continue
549+
}
545550
return nil, fmt.Errorf("missing key '%s' in %s '%s'", v.GetValuesKey(), v.Kind, namespacedName)
546551
} else {
547552
valuesData = []byte(data)
@@ -575,6 +580,10 @@ func (r *HelmReleaseReconciler) composeValues(ctx context.Context, hr v2.HelmRel
575580
return nil, fmt.Errorf("could not find %s '%s'", v.Kind, namespacedName)
576581
}
577582
if data, ok := resource.Data[v.GetValuesKey()]; !ok {
583+
if v.Optional {
584+
(logr.FromContext(ctx)).Info(fmt.Sprintf("could not find optional key %s in %s '%s'", v.GetValuesKey(), v.Kind, namespacedName))
585+
continue
586+
}
578587
return nil, fmt.Errorf("missing key '%s' in %s '%s'", v.GetValuesKey(), v.Kind, namespacedName)
579588
} else {
580589
valuesData = data

0 commit comments

Comments
 (0)