Skip to content

Commit

Permalink
auto migrate on helm upgrade (#33)
Browse files Browse the repository at this point in the history
  • Loading branch information
johnnyaug committed Dec 3, 2020
1 parent c897a74 commit a894942
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 39 deletions.
2 changes: 1 addition & 1 deletion charts/lakefs/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: lakefs
description: A Helm chart for Kubernetes
type: application
version: 0.4.6
version: 0.4.7
appVersion: 0.18.0

home: https://lakefs.io
Expand Down
43 changes: 43 additions & 0 deletions charts/lakefs/templates/_env.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{{- define "lakefs.env" -}}
env:
{{- if .Values.secrets }}
- name: LAKEFS_DATABASE_CONNECTION_STRING
valueFrom:
secretKeyRef:
name: {{ include "lakefs.fullname" . }}
key: database_connection_string
- name: LAKEFS_AUTH_ENCRYPT_SECRET_KEY
valueFrom:
secretKeyRef:
name: {{ include "lakefs.fullname" . }}
key: auth_encrypt_secret_key
{{- else if not .Values.lakefsConfig }}
- name: LAKEFS_DATABASE_CONNECTION_STRING
value: postgres://postgres:password@localhost:5432/postgres?sslmode=disable
- name: LAKEFS_AUTH_ENCRYPT_SECRET_KEY
value: asdjfhjaskdhuioaweyuiorasdsjbaskcbkj
{{- end }}
{{- if not .Values.lakefsConfig }}
- name: LAKEFS_BLOCKSTORE_LOCAL_PATH
value: /lakefs/data
{{- end }}
{{- if .Values.extraEnvVarsSecret }}
envFrom:
- secretRef:
name: {{ .Values.extraEnvVarsSecret }}
{{- end }}
{{- end }}

{{- define "lakefs.volumes" -}}
{{- if not .Values.lakefsConfig }}
- name: {{ .Chart.Name }}-postgredb
- name: {{ .Chart.Name }}-local-data
{{- else }}
- name: config-volume
configMap:
name: {{ include "lakefs.fullname" . }}
items:
- key: config.yaml
path: config.yaml
{{- end }}
{{- end }}
40 changes: 2 additions & 38 deletions charts/lakefs/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,33 +54,7 @@ spec:
- name: {{ .Chart.Name }}-local-data
mountPath: "/lakefs/data"
{{- end }}
env:
{{- if .Values.secrets }}
- name: LAKEFS_DATABASE_CONNECTION_STRING
valueFrom:
secretKeyRef:
name: {{ include "lakefs.fullname" . }}
key: database_connection_string
- name: LAKEFS_AUTH_ENCRYPT_SECRET_KEY
valueFrom:
secretKeyRef:
name: {{ include "lakefs.fullname" . }}
key: auth_encrypt_secret_key
{{- else if not .Values.lakefsConfig }}
- name: LAKEFS_DATABASE_CONNECTION_STRING
value: postgres://postgres:password@localhost:5432/postgres?sslmode=disable
- name: LAKEFS_AUTH_ENCRYPT_SECRET_KEY
value: asdjfhjaskdhuioaweyuiorasdsjbaskcbkj
{{- end }}
{{- if not .Values.lakefsConfig }}
- name: LAKEFS_BLOCKSTORE_LOCAL_PATH
value: /lakefs/data
{{- end }}
{{- if .Values.extraEnvVarsSecret }}
envFrom:
- secretRef:
name: {{ .Values.extraEnvVarsSecret }}
{{- end }}
{{- include "lakefs.env" . | nindent 10 }}
{{- if not .Values.lakefsConfig }}
- name: {{ .Chart.Name }}-postgres
image: postgres:11
Expand All @@ -95,17 +69,7 @@ spec:
name: {{ .Chart.Name }}-postgredb
{{- end }}
volumes:
{{- if not .Values.lakefsConfig }}
- name: {{ .Chart.Name }}-postgredb
- name: {{ .Chart.Name }}-local-data
{{- else }}
- name: config-volume
configMap:
name: {{ include "lakefs.fullname" . }}
items:
- key: config.yaml
path: config.yaml
{{- end }}
{{- include "lakefs.volumes" . | nindent 8 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
Expand Down
29 changes: 29 additions & 0 deletions charts/lakefs/templates/job.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{{- if .Values.lakefsConfig }}
apiVersion: batch/v1
kind: Job
metadata:
name: {{ include "lakefs.fullname" . }}-migrate
labels:
{{- include "lakefs.labels" . | nindent 4 }}
annotations:
"helm.sh/hook": pre-upgrade
"helm.sh/hook-weight": "-1"
"helm.sh/hook-delete-policy": hook-succeeded
spec:
template:
metadata:
name: {{ include "lakefs.fullname" . }}-migrate
spec:
restartPolicy: Never
containers:
- name: lakefs-migration
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
args: [ "migrate", "up", "--config", "/etc/lakefs/config.yaml" ]
volumeMounts:
- name: config-volume
mountPath: /etc/lakefs
{{- include "lakefs.env" . | nindent 10 }}
volumes:
{{- include "lakefs.volumes" . | nindent 8 }}
{{- end }}

0 comments on commit a894942

Please sign in to comment.