'Helm upgrade - preserve value of an environment variable when if condition is not met

I am doing helm upgrade --install with the --reuse-values option. I want to conditionally update the value of an environment variable if a certain condition is met and if the condition is not met preserve the already existing value. I've tried to achieve that this way:

env:
  - name: RELEASE_DATE
    value: "{{ if eq .Values.config.myCondition "testValue" }}{{ date "2006-01-02T15:04:05" .Release.Time }}{{ end }}"

or

env:
  - name: RELEASE_DATE
    value: "{{ if eq .Values.config.myCondition "testValue" }}{{ date "2006-01-02T15:04:05" .Release.Time }}{{ else }}{{ .Values.someOtherValue }}{{ end }}"

where .Values.someOtherValue is never really existing, or even doing it this way

env:
  {{- if eq .Values.config.deployedService "ftmFrontend" }}
  - name: RELEASE_DATE
    value: "{{ if eq .Values.config.myCondition "testValue" }}{{ date "2006-01-02T15:04:05" .Release.Time }}{{ end }}"
  {{- end }}

I was expecting that if I use a --reuse-values option that the values are going to be kept/preserved if the condition is not met, but instead it always deletes it and leaves it empty. The option does work however, when there is no condition clause and only the value from the chart is referenced. It's only not working if the if statement is used. How can I use if statement and still preserve the value if the condition is not met?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source