diff --git a/charts/openfga/templates/deployment.yaml b/charts/openfga/templates/deployment.yaml index 5af7dfb..efcbf2c 100644 --- a/charts/openfga/templates/deployment.yaml +++ b/charts/openfga/templates/deployment.yaml @@ -36,7 +36,7 @@ spec: {{- toYaml .Values.podSecurityContext | nindent 8 }} {{ if or (and (has .Values.datastore.engine (list "postgres" "mysql")) .Values.datastore.applyMigrations .Values.datastore.waitForMigrations) .Values.extraInitContainers }} initContainers: - {{- if and (has .Values.datastore.engine (list "postgres" "mysql")) .Values.datastore.applyMigrations .Values.datastore.waitForMigrations }} + {{- if and (has .Values.datastore.engine (list "postgres" "mysql")) .Values.datastore.applyMigrations .Values.datastore.waitForMigrations (eq .Values.datastore.migrationType "job") }} - name: wait-for-migration securityContext: {{- toYaml .Values.securityContext | nindent 12 }} @@ -46,6 +46,44 @@ spec: resources: {{- toYaml .Values.datastore.migrations.resources | nindent 12 }} {{- end }} + {{- if and (has .Values.datastore.engine (list "postgres" "mysql")) (eq .Values.datastore.migrationType "initContainer") }} + - name: migrate-database + securityContext: + {{- toYaml .Values.securityContext | nindent 12 }} + image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}" + args: [ "migrate" ] + env: + {{- if .Values.datastore.engine }} + - name: OPENFGA_DATASTORE_ENGINE + value: "{{ .Values.datastore.engine }}" + {{- end }} + {{- if .Values.datastore.uri }} + - name: OPENFGA_DATASTORE_URI + value: "{{ .Values.datastore.uri }}" + {{- else if .Values.datastore.uriSecret }} + - name: OPENFGA_DATASTORE_URI + valueFrom: + secretKeyRef: + name: "{{ .Values.datastore.uriSecret }}" + key: "uri" + {{- end }} + {{- if .Values.migrate.timeout }} + - name: OPENFGA_TIMEOUT + value: "{{ .Values.migrate.timeout }}" + {{- end }} + {{- with .Values.extraEnvVars }} + {{- toYaml . | nindent 12 }} + {{- end }} + resources: + {{- toYaml .Values.datastore.migrations.resources | nindent 12 }} + {{- with .Values.migrate.extraVolumeMounts }} + volumeMounts: + {{- toYaml . | nindent 12 }} + {{- end }} + {{- if .Values.migrate.sidecars }} + {{- include "common.tplvalues.render" ( dict "value" .Values.migrate.sidecars "context" $) | nindent 8 }} + {{- end }} + {{- end }} {{- with .Values.extraInitContainers }} {{- toYaml . | nindent 8 }} {{- end }} diff --git a/charts/openfga/templates/job.yaml b/charts/openfga/templates/job.yaml index 3ec2595..a7a670d 100644 --- a/charts/openfga/templates/job.yaml +++ b/charts/openfga/templates/job.yaml @@ -1,4 +1,4 @@ -{{- if and (has .Values.datastore.engine (list "postgres" "mysql")) .Values.datastore.applyMigrations -}} +{{- if and (has .Values.datastore.engine (list "postgres" "mysql")) .Values.datastore.applyMigrations (eq .Values.datastore.migrationType "job") -}} apiVersion: batch/v1 kind: Job metadata: diff --git a/charts/openfga/values.schema.json b/charts/openfga/values.schema.json index d002147..fd3ad70 100644 --- a/charts/openfga/values.schema.json +++ b/charts/openfga/values.schema.json @@ -329,9 +329,21 @@ }, "applyMigrations": { "type": "boolean", - "description": "enable/disable the job that runs migrations in the datastore", + "description": "enable/disable the running of migrations in the datastore", "default": true }, + "migrationType": { + "type": [ + "string", + "null" + ], + "description": "how the migrations will be run", + "default": "job", + "enum": [ + "job", + "initContainer" + ] + }, "waitForMigrations": { "type": "boolean", "description": "wait for migrations to complete before starting the server",