Use pre upgrade .Values in if conditions in pre-upgrade hook - Helm chart

5/27/2019

I want to know if it is possible to evaluate {{- If .Values.config }} and fail in a pre-upgrade hook if config is not set, which it shouldn't exist in the chart previous to the upgrade, but is part of the new chart version values.yaml.

This is because the upgrade hooks should only run if that value didn't exist, otherwise it means is already upgraded. Currently when evaluating .Values.config in the pre-upgrade hook it returns the new .Values even though the chart is in the process of being upgraded.

This I would think it should fail but it doesn't

{{- if .Values.config }}
{{ fail "Already upgraded" }}
{{- else }}
apiVersion: v1
kind: PersistentVolumeClaim
metadata:
  name: "dbdump"
  annotations:
    "helm.sh/hook": pre-upgrade
    "helm.sh/hook-weight": "-1"
    "helm.sh/hook-delete-policy": keep
    "helm.sh/resource-policy": keep

thanks for your help

-- lulu
kubernetes
kubernetes-helm

0 Answers