crenshaw-dev
crenshaw-dev

Reputation: 8382

How to make pods stick around after helm test

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?

Upvotes: 0

Views: 1514

Answers (2)

Pankaj Yadav
Pankaj Yadav

Reputation: 147

Understanding helm hook resources:

  1. Any resources created by a Helm hook are un-managed Kubernetes objects.
  2. In other words, uninstalling a Helm chart using "helm uninstall" will not remove the underlying resources created by hooks.
  3. A separate deletion policy needs to be defined in the form of annotation if those resources need to be deleted i.e. “helm.sh/hook-delete-policy" annotation to be defined under metadata section in hook definition file.

Three different deletion policies are supported which will decide when to delete the resources:

  1. before-hook-creation : Delete the previous test resource before a new hook is launched
  2. hook-succeeded : Delete the test resource after the hook is successfully executed
  3. hook-failed : Delete the test resource if the hook failed during execution

Important Notes:

  1. If no hook deletion policy annotation is specified, the "before-hook-creation" behaviour is applied by default.
  2. Any helm hook resources including test hook resource that must never be deleted should be annotated with "helm.sh/resource-policy: keep".

I hope this information is useful for someone.

Upvotes: 0

crenshaw-dev
crenshaw-dev

Reputation: 8382

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.

Upvotes: 1

Related Questions