Skip to content

Commit fdc464f

Browse files
committed
feat(helm)!: add a runMigrationInPreDeployment value allowing to move chartreuse migration to pre-deployment instead of post-deployment, false by default.
1 parent 138f79d commit fdc464f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+741
-559
lines changed

.dockerignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
bin
2+
documentation
3+
include
4+
kubernetes
5+
lib
6+
other
7+
venv
8+
.*

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.tgz

CHANGELOG.md

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,17 @@
22
## BREAKING CHANGES
33
- helm: move most alembic/eslembic parameters to eslembic and alembic prefix.
44
- Rename most environment variables used by chartreuse.
5+
- Remove pre-deployment job that stop-pods before deployment, since helm 3 will re-start them anyway.
56
## Features
7+
- Chartreuse: add a runMigrationInPreDeployment value allowing to move chartreuse migration to pre-deployment instead of post-deployment, false by default. Note that in such case, a deployment failure may cause new database schema version but old code to be on the environment (you may want to disable helmDefaults.atomic parameter in helmfile.yaml of your project)
8+
- Chartreuse: Allow to keep pods started and not do stop-pods.
9+
- alembic: allow to give additional parameters to alembic.
10+
- eslembic: Split eslembic upgrade to eslembic upgrade and eslembic migrate as a post job
11+
- eslembic: allow to enable eslembic upgrade through `eslembic.upgrade.enabled` value
12+
- helm: Add `additionalEnvironmentVariables` parameter to inject envvars into Chartreuse Pods.
613
- helm: Add support for built-in secret.
714
- helm: delete all roles, serviceaccounts, secrets, configmap after success
8-
- Allow to keep pods started and not do stop-pods.
9-
- alembic: allow to give additional parameters to alembic.
10-
- eslembic: Split eslembic upgrade to eslembic migrate and eslembic upgrade as a post job
11-
- eslembic: allow to disable/enable eslembic upgrade
12-
## Fixes
15+
- helm: delete post-rollback job that is useless with helm 3
1316
- Upgrade to eslembic v6.x.x
1417

1518
# 1.1.0 (2020-03-10)

README.md

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Chartreuse is a wrapper around [Alembic](https://alembic.sqlalchemy.org) and [Eslembic](https://gitlab.cayzn.com/wiremind/commons/eslembic) to ease,
44
detect and automate migrations on deployed applications.
5-
5+
66
Chartreuse is made to work as Helm hooks. You need to use Chartreuse a a sub-chart of your project.
77

88
# Install
@@ -27,9 +27,17 @@ upgrade (starting from a version `V`) but the same scenario
2727
applies to applications when installing them for the first time
2828
(consider version `V` to be scratch).
2929

30-
- The diagram has been drawn using the free online software https://draw.io, the
30+
- The diagram has been drawn using the free online software https://draw.io, the
3131
source code is located at `doc/chartreuse_sd.xml`, feel free
3232
to correct it or make it more understandable.
3333

3434
- In the end of an install/upgrade, whatever its state: succeeded or failed, make sure
35-
that the pods were scaled up as expected, if it isn't the case, this should be done manually.
35+
that the pods were scaled up as expected, if it isn't the case, this should be done manually.
36+
37+
# Test
38+
39+
There are three kind of tests:
40+
41+
- Unit tests
42+
- Integration tests: allows to run in a real environment, but still control chartreuse from the inside
43+
- blackbox test: deploy a real Helm Release and test if databases are migrated. Requires the PYPI_PASSWORD_READONLY envvar to be set in order to fetch required eggs to build the test Docker image.

VERSION

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.0.0-dev0
1+
2.0.0-dev13

helm-chart/chartreuse/Chart.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
apiVersion: v1
22
name: chartreuse
3-
version: 2.0.0-dev0
3+
# Note: when setting a development version, please explicitely specify it in e2e test helm chart, otherwise just put *.
4+
version: 2.0.0
45
description: Migrate databases with ease

helm-chart/chartreuse/templates/_helpers.tpl

+50
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,53 @@ Create the name of the service account to use
5454
{{ default "default" .Values.serviceAccount.name }}
5555
{{- end -}}
5656
{{- end -}}
57+
58+
59+
{{- define "chartreuse.alembic.url" -}}
60+
{{ printf "postgresql://%s:%s@%s%s:5432/%s?sslmode=prefer" .Values.alembic.username .Values.alembic.password .Release.Name .Values.alembic.urlSuffix .Values.alembic.database }}
61+
{{- end -}}
62+
63+
{{- define "chartreuse.eslembic.url" -}}
64+
{{ printf "http://%s%s:9200" .Release.Name .Values.eslembic.urlSuffix }}
65+
{{- end -}}
66+
67+
68+
{{- define "chartreuse.annotations" -}}
69+
{{- if .Values.runMigrationInPreDeployment }}
70+
{{- if .Release.IsInstall }}
71+
# No hook: we deploy this job during the initial install, as part of the Helm Release
72+
{{- end }}
73+
{{- if .Release.IsUpgrade }}
74+
# Should be run in pre-upgrade only (not pre-install)
75+
"helm.sh/hook": pre-upgrade
76+
"helm.sh/hook-weight": "1"
77+
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
78+
{{- end }}
79+
{{- else }}
80+
# Should be run in post-install,post-upgrade wherever it is install or upgrade.
81+
"helm.sh/hook": post-install,post-upgrade
82+
"helm.sh/hook-weight": "1"
83+
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
84+
{{- end }}
85+
{{- end -}}
86+
87+
{{- define "chartreuse.annotations.ephemeral" -}}
88+
{{- if .Values.runMigrationInPreDeployment }}
89+
"helm.sh/hook": pre-upgrade
90+
{{- else }}
91+
"helm.sh/hook": post-install,post-upgrade
92+
{{- end }}
93+
"helm.sh/hook-weight": "0"
94+
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded,hook-failed"
95+
{{- end -}}
96+
97+
# Adds suffix -ephemeral if it is a helm hook
98+
{{- define "chartreuse.hook.suffix" -}}
99+
{{- if .Values.runMigrationInPreDeployment -}}
100+
{{- if .Release.IsUpgrade -}}
101+
-ephemeral
102+
{{- end -}}
103+
{{- else -}}
104+
-ephemeral
105+
{{- end -}}
106+
{{- end -}}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
apiVersion: v1
2+
kind: ConfigMap
3+
metadata:
4+
name: {{ template "chartreuse.fullname" . }}-ephemeral
5+
labels:
6+
{{ include "chartreuse.labels" . | indent 4 }}
7+
annotations:
8+
{{ include "chartreuse.annotations.ephemeral" . | indent 4 }}
9+
data:
10+
# Note: Chartreuse expects false values to be empty string (falsy value) and true values to be non-empty string.
11+
{{- if .Values.alembic.allowMigrationFromEmptyDatabase }}
12+
CHARTREUSE_ALEMBIC_ALLOW_MIGRATION_FOR_EMPTY_DATABASE: "1"
13+
{{- else }}
14+
CHARTREUSE_ALEMBIC_ALLOW_MIGRATION_FOR_EMPTY_DATABASE: ""
15+
{{- end }}
16+
17+
{{- if .Values.eslembic.cleanIndex.enabled }}
18+
CHARTREUSE_ESLEMBIC_ENABLE_CLEAN: "1"
19+
{{- else }}
20+
CHARTREUSE_ESLEMBIC_ENABLE_CLEAN: ""
21+
{{- end }}
22+
23+
{{- if .Values.eslembic.migrate.enabled }}
24+
CHARTREUSE_ESLEMBIC_ENABLE_MIGRATE: "1"
25+
{{- else }}
26+
CHARTREUSE_ESLEMBIC_ENABLE_MIGRATE: ""
27+
{{- end }}
28+
29+
{{- if .Values.stopPods }}
30+
CHARTREUSE_ENABLE_STOP_PODS: "1"
31+
{{- else }}
32+
CHARTREUSE_ENABLE_STOP_PODS: ""
33+
{{- end }}
34+
35+
CHARTREUSE_MIGRATE_CONTAINER_IMAGE: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
36+
CHARTREUSE_MIGRATE_IMAGE_PULL_SECRET: "{{ .Values.image.pullSecret }}"
37+
CHARTREUSE_RELEASE_NAME: {{ .Release.Name }}
38+
CHARTREUSE_ALEMBIC_ADDITIONAL_PARAMETERS: "{{ .Values.alembic.additionalParameters }}"
39+
40+
{{- with .Values.additionalEnvironmentVariables }}
41+
{{ toYaml . | indent 2 }}
42+
{{- end }}

helm-chart/chartreuse/templates/confimap.yaml

+10-11
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@ metadata:
44
name: {{ template "chartreuse.fullname" . }}
55
labels:
66
{{ include "chartreuse.labels" . | indent 4 }}
7-
annotations:
8-
"helm.sh/hook": pre-install,pre-upgrade,post-install,post-upgrade,post-rollback
9-
"helm.sh/hook-weight": "0"
10-
"helm.sh/hook-delete-policy": "before-hook-creation,hook-succeeded"
117
data:
12-
# Chartreuse expects false values to be empty string (falsy value) and true values to be non-empty string.
13-
8+
# Note: Chartreuse expects false values to be empty string (falsy value) and true values to be non-empty string.
149
{{- if .Values.alembic.allowMigrationFromEmptyDatabase }}
1510
CHARTREUSE_ALEMBIC_ALLOW_MIGRATION_FOR_EMPTY_DATABASE: "1"
1611
{{- else }}
@@ -23,10 +18,10 @@ data:
2318
CHARTREUSE_ESLEMBIC_ENABLE_CLEAN: ""
2419
{{- end }}
2520

26-
{{- if .Values.eslembic.upgrade.enabled }}
27-
CHARTREUSE_ESLEMBIC_ENABLE_UPGRADE: "1"
21+
{{- if .Values.eslembic.migrate.enabled }}
22+
CHARTREUSE_ESLEMBIC_ENABLE_MIGRATE: "1"
2823
{{- else }}
29-
CHARTREUSE_ESLEMBIC_ENABLE_UPGRADE: ""
24+
CHARTREUSE_ESLEMBIC_ENABLE_MIGRATE: ""
3025
{{- end }}
3126

3227
{{- if .Values.stopPods }}
@@ -35,7 +30,11 @@ data:
3530
CHARTREUSE_ENABLE_STOP_PODS: ""
3631
{{- end }}
3732

38-
CHARTREUSE_POST_UPGRADE_CONTAINER_IMAGE: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
33+
CHARTREUSE_MIGRATE_CONTAINER_IMAGE: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
34+
CHARTREUSE_MIGRATE_IMAGE_PULL_SECRET: "{{ .Values.image.pullSecret }}"
3935
CHARTREUSE_RELEASE_NAME: {{ .Release.Name }}
36+
CHARTREUSE_ALEMBIC_ADDITIONAL_PARAMETERS: "{{ .Values.alembic.additionalParameters }}"
4037

41-
CHARTREUSE_ALEMBIC_ADDITIONAL_PARAMETERS: {{ .Values.alembic.additionalParameters }}
38+
{{- with .Values.additionalEnvironmentVariables }}
39+
{{ toYaml . | indent 2 }}
40+
{{- end }}

helm-chart/chartreuse/templates/job-post-rollback.yaml

-36
This file was deleted.

helm-chart/chartreuse/templates/job-post-upgrade.yaml

-35
This file was deleted.

helm-chart/chartreuse/templates/job-pre-upgrade.yaml

-36
This file was deleted.

0 commit comments

Comments
 (0)