How to make pods stick around after helm test

1/2/2020

I'd like tests pods to persist after running helm test so that I can inspect the logs.

But in Helm 3, running helm test runs the tests, prints the results (success/failure), and then deletes the pods.

How can I get Helm to keep the pods around after test execution?

-- Michael Crenshaw
kubernetes-helm

1 Answer

1/2/2020

I was using a test Pod that included the "helm.sh/hook-delete-policy": hook-succeeded annotation. Here it is in a lightly-modified version of the test created by helm create:

apiVersion: v1
kind: Pod
metadata:
  name: "{{ include "test-helm-logs.fullname" . }}-test-connection"
  labels:
{{ include "test-helm-logs.labels" . | nindent 4 }}
  annotations:
    "helm.sh/hook": test-success
    "helm.sh/hook-delete-policy": hook-succeeded
spec:
  containers:
    - name: wget
      image: busybox
      command: ['wget']
      args:  ['{{ include "test-helm-logs.fullname" . }}:{{ .Values.service.port }}']
  restartPolicy: Never

Removing the delete annotation allowed the pod to stick around for inspection.

-- Michael Crenshaw
Source: StackOverflow