Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

helm install vs helm uninstall – .Release.IsInstall variable

I am currently using the helm .Release.IsInstall variable https://helm.sh/docs/chart_template_guide/builtin_objects/ in my helm chart. Here’s the snippet of code that I have:

       {{- if .Release.IsInstall }}
       command: [ "python", "main.py", "install"]
       {{- else }}
       command: [ "python", "main.py", "delete"]
       {{- end }}

However regardless of whether I run helm install or helm uninstall it seems as though .Release.IsInstall returns a boolean of true. Basically I am attempting to detect whether the user is doing an install/uninstall. Maybe there is another variable that I should be using instead.

Thanks in advance.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

.Release.IsInstall only works during the installation process. When you’re running helm uninstall, the Helm chart templates aren’t evaluated, so this variable isn’t relevant in that context. Therefore, you can’t use .Release.IsInstall to detect an uninstall operation directly.

Since Helm doesn’t evaluate templates on uninstall, it’s not straightforward to pass different commands for uninstalling using the chart templates.

One common approach to handle this is using Helm pre-uninstall and post-uninstall hooks. You can define specific jobs or pods that run before or after the uninstall process, for example you can use a pre-delete hook to perform actions before the chart is deleted, and post-delete for actions after the chart is deleted.

kind: Job
apiVersion: batch/v1
metadata:
  name: "{{ .Release.Name }}-pre-delete"
  annotations:
    "helm.sh/hook": pre-delete
spec:
  template:
    spec:
      containers:
      - name: pre-delete
        image: python:3.8
        command: ["python", "main.py", "delete"]
      restartPolicy: Never
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading