Does the Helm-operator handle jobs?

12/18/2019

I am interested in migrating my kubernetes deployment appraoch to be operator based. In particular using the Helm operator as we are using helm already.

However in my infrastructure we have a lot of jobs, and wonder how does the helm-operator handle jobs spec ?

How does it delete, or replace running job ? a job spec might not change and we just need to run the job again ? So that would not involve any changes in the CR or helmRelease. ....

I'm puzled.

-- MaatDeamon
kubernetes
kubernetes-helm

1 Answer

12/19/2019

You can control jobs in helm by Chart hooks. Their execution is defined by one of the available hooks, for example:

pre-install- Executes after templates are rendered, but before any resources are created in Kubernetes,

post-install- Executes after all resources are loaded into Kubernetes,

pre-delete- Executes on a deletion request before any resources are deleted from Kubernetes,

post-delete- Executes on a deletion request after all of the release’s resources have been deleted, etc.

Order of job execution can be managed by weight assigned to the job (if they have same weight, they will be executed by name in ascending order). It is declared as a string and can take any value: -5, 0, 5, etc.

There are 3 hook deletion policies, which determine when hook resources are deleted and are defined in annotations field:

before-hook-creation- deletes the previous resource before a new hook is launched- if no deletion policy is defined it is applied as default.

hook-succeeded- deletes the resource after the hook is successfully executed

hook-failed- deletes the resource if the hook failed during execution

Example:

apiVersion: batch/v1
kind: Job
metadata:
  name: my-job
  annotations:
    "helm.sh/hook": pre-install #defines type of the hook
    "helm.sh/hook-weight": "-5" #weight of the hook
    "helm.sh/hook-delete-policy": hook-succeeded #if job finished successfully, resource will be deleted
  #[...]
-- KFC_
Source: StackOverflow