As part of my applications helm chart I have a Job which runs database migrations. I’ve annotated the job with the hook "helm.sh/hook": pre-install,pre-upgrade
to ensure migrations are ran before the application is deployed. I want to use the same service account and config-map that my application deployment uses, however these resources have not been created at the time the job is executed resulting in the following error:
Warning FailedCreate 8s job-controller Error creating: pods "db-migrate-" is forbidden: error looking up service account dev-platform/platform: serviceaccount "platform" not found
According to the helm installation order the service account and config map should be created before the job. Is the behaviour nullified when running the job as pre-install
?:
apiVersion: batch/v1
kind: Job
metadata:
namespace: dev-platform
name: db-migrate
annotations:
"helm.sh/hook": pre-install,pre-upgrade
"helm.sh/hook-delete-policy": hook-succeeded
spec:
activeDeadlineSeconds: 300
backoffLimit: 1
template:
spec:
# Share platform service account IAM role.
serviceAccountName: {{ .Release.Name }}
securityContext:
fsGroup: 65534 # Allow read permissions of AWS token files for IAM service account token.
restartPolicy: Never
containers:
- name: db-migrate
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- configMapRef:
name: platform-config
- secretRef:
name: platform-secrets
# Overwrite APP_COMMAND variable.
env:
- name: APP_COMMAND
value: migrate
- name: APP_ENVIRONMENT
value: {{ .Values.image.appEnvironment | quote }}