Skip to content

Commit aafa0e4

Browse files
author
Simon Emms
committed
[installer]: configure kots to backup in-cluster mysql
1 parent 1613e01 commit aafa0e4

File tree

6 files changed

+74
-21
lines changed

6 files changed

+74
-21
lines changed

install/installer/cmd/testdata/render/customization/output.golden

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7740,6 +7740,10 @@ spec:
77407740
metadata:
77417741
annotations:
77427742
checksum/configuration: f96f510015050d9b0165d12f144f5eca5641c065ccbe9c75e64f58e81a9b3d8c
7743+
backup.velero.io/backup-volumes: backup
7744+
pre.hook.backup.velero.io/command: |
7745+
["/bin/bash", "-c", "mysqldump -u root -p$MYSQL_ROOT_PASSWORD --databases $MYSQL_DATABASE gitpod-sessions -h 127.0.0.1 > /backup/mysqldump.sql"]
7746+
pre.hook.backup.velero.io/timeout: 5m
77437747
labels:
77447748
app.kubernetes.io/name: mysql
77457749
helm.sh/chart: mysql-9.1.2
@@ -7849,13 +7853,17 @@ spec:
78497853
- name: config
78507854
mountPath: /opt/bitnami/mysql/conf/my.cnf
78517855
subPath: my.cnf
7856+
- mountPath: /backup
7857+
name: backup
78527858
volumes:
78537859
- name: config
78547860
configMap:
78557861
name: mysql
78567862
- name: custom-init-scripts
78577863
configMap:
78587864
name: db-init-scripts
7865+
- emptyDir: {}
7866+
name: backup
78597867
volumeClaimTemplates:
78607868
- metadata:
78617869
name: data

install/installer/cmd/testdata/render/external-registry/output.golden

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6831,6 +6831,10 @@ spec:
68316831
metadata:
68326832
annotations:
68336833
checksum/configuration: f96f510015050d9b0165d12f144f5eca5641c065ccbe9c75e64f58e81a9b3d8c
6834+
backup.velero.io/backup-volumes: backup
6835+
pre.hook.backup.velero.io/command: |
6836+
["/bin/bash", "-c", "mysqldump -u root -p$MYSQL_ROOT_PASSWORD --databases $MYSQL_DATABASE gitpod-sessions -h 127.0.0.1 > /backup/mysqldump.sql"]
6837+
pre.hook.backup.velero.io/timeout: 5m
68346838
labels:
68356839
app.kubernetes.io/name: mysql
68366840
helm.sh/chart: mysql-9.1.2
@@ -6940,13 +6944,17 @@ spec:
69406944
- name: config
69416945
mountPath: /opt/bitnami/mysql/conf/my.cnf
69426946
subPath: my.cnf
6947+
- mountPath: /backup
6948+
name: backup
69436949
volumes:
69446950
- name: config
69456951
configMap:
69466952
name: mysql
69476953
- name: custom-init-scripts
69486954
configMap:
69496955
name: db-init-scripts
6956+
- emptyDir: {}
6957+
name: backup
69506958
volumeClaimTemplates:
69516959
- metadata:
69526960
name: data

install/installer/cmd/testdata/render/minimal/output.golden

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7111,6 +7111,10 @@ spec:
71117111
metadata:
71127112
annotations:
71137113
checksum/configuration: f96f510015050d9b0165d12f144f5eca5641c065ccbe9c75e64f58e81a9b3d8c
7114+
backup.velero.io/backup-volumes: backup
7115+
pre.hook.backup.velero.io/command: |
7116+
["/bin/bash", "-c", "mysqldump -u root -p$MYSQL_ROOT_PASSWORD --databases $MYSQL_DATABASE gitpod-sessions -h 127.0.0.1 > /backup/mysqldump.sql"]
7117+
pre.hook.backup.velero.io/timeout: 5m
71147118
labels:
71157119
app.kubernetes.io/name: mysql
71167120
helm.sh/chart: mysql-9.1.2
@@ -7220,13 +7224,17 @@ spec:
72207224
- name: config
72217225
mountPath: /opt/bitnami/mysql/conf/my.cnf
72227226
subPath: my.cnf
7227+
- mountPath: /backup
7228+
name: backup
72237229
volumes:
72247230
- name: config
72257231
configMap:
72267232
name: mysql
72277233
- name: custom-init-scripts
72287234
configMap:
72297235
name: db-init-scripts
7236+
- emptyDir: {}
7237+
name: backup
72307238
volumeClaimTemplates:
72317239
- metadata:
72327240
name: data

install/installer/cmd/testdata/render/statefulset-customization/output.golden

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7123,6 +7123,10 @@ spec:
71237123
metadata:
71247124
annotations:
71257125
checksum/configuration: f96f510015050d9b0165d12f144f5eca5641c065ccbe9c75e64f58e81a9b3d8c
7126+
backup.velero.io/backup-volumes: backup
7127+
pre.hook.backup.velero.io/command: |
7128+
["/bin/bash", "-c", "mysqldump -u root -p$MYSQL_ROOT_PASSWORD --databases $MYSQL_DATABASE gitpod-sessions -h 127.0.0.1 > /backup/mysqldump.sql"]
7129+
pre.hook.backup.velero.io/timeout: 5m
71267130
labels:
71277131
app.kubernetes.io/name: mysql
71287132
helm.sh/chart: mysql-9.1.2
@@ -7232,13 +7236,17 @@ spec:
72327236
- name: config
72337237
mountPath: /opt/bitnami/mysql/conf/my.cnf
72347238
subPath: my.cnf
7239+
- mountPath: /backup
7240+
name: backup
72357241
volumes:
72367242
- name: config
72377243
configMap:
72387244
name: mysql
72397245
- name: custom-init-scripts
72407246
configMap:
72417247
name: db-init-scripts
7248+
- emptyDir: {}
7249+
name: backup
72427250
volumeClaimTemplates:
72437251
- metadata:
72447252
name: data

install/installer/pkg/components/database/incluster/helm.go

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,38 @@ var Helm = common.CompositeHelmFunc(
2424
return nil, err
2525
}
2626

27+
customization := make([]string, 0)
28+
customization = helm.CustomizeAnnotation(customization, "mysql.primary.podAnnotations", cfg, Component, common.TypeMetaStatefulSet)
29+
customization = helm.CustomizeLabel(customization, "mysql.primary.podLabels", cfg, Component, common.TypeMetaStatefulSet)
30+
customization = helm.CustomizeAnnotation(customization, "mysql.primary.service.annotations", cfg, Component, common.TypeMetaService)
31+
2732
return &common.HelmConfig{
2833
Enabled: true,
2934
Values: &values.Options{
30-
Values: []string{
31-
helm.KeyValue("mysql.auth.existingSecret", SQLPasswordName),
32-
helm.KeyValue("mysql.auth.database", Database),
33-
helm.KeyValue("mysql.auth.username", Username),
34-
helm.KeyValue("mysql.initdbScriptsConfigMap", SQLInitScripts),
35-
helm.KeyValue("mysql.serviceAccount.name", Component),
36-
helm.ImagePullSecrets("mysql.image.pullSecrets", cfg),
37-
helm.KeyValue("mysql.image.registry", ""),
38-
helm.KeyValue("mysql.image.repository", cfg.RepoName(common.ThirdPartyContainerRepo(cfg.Config.Repository, common.DockerRegistryURL), "bitnami/mysql")),
39-
helm.ImagePullSecrets("mysql.metrics.image.pullSecrets", cfg),
40-
helm.KeyValue("mysql.metrics.image.registry", ""),
41-
helm.KeyValue("mysql.metrics.image.repository", cfg.RepoName(common.ThirdPartyContainerRepo(cfg.Config.Repository, common.DockerRegistryURL), "bitnami/mysqld-exporter")),
42-
helm.ImagePullSecrets("mysql.volumePermissions.image.pullSecrets", cfg),
43-
helm.KeyValue("mysql.volumePermissions.image.pullPolicy", "IfNotPresent"),
44-
helm.KeyValue("mysql.volumePermissions.image.registry", ""),
45-
helm.KeyValue("mysql.volumePermissions.image.repository", cfg.RepoName(common.ThirdPartyContainerRepo(cfg.Config.Repository, common.DockerRegistryURL), "bitnami/bitnami-shell")),
35+
Values: append(
36+
[]string{
37+
helm.KeyValue("mysql.auth.existingSecret", SQLPasswordName),
38+
helm.KeyValue("mysql.auth.database", Database),
39+
helm.KeyValue("mysql.auth.username", Username),
40+
helm.KeyValue("mysql.initdbScriptsConfigMap", SQLInitScripts),
41+
helm.KeyValue("mysql.serviceAccount.name", Component),
42+
helm.ImagePullSecrets("mysql.image.pullSecrets", cfg),
43+
helm.KeyValue("mysql.image.registry", ""),
44+
helm.KeyValue("mysql.image.repository", cfg.RepoName(common.ThirdPartyContainerRepo(cfg.Config.Repository, common.DockerRegistryURL), "bitnami/mysql")),
45+
helm.ImagePullSecrets("mysql.metrics.image.pullSecrets", cfg),
46+
helm.KeyValue("mysql.metrics.image.registry", ""),
47+
helm.KeyValue("mysql.metrics.image.repository", cfg.RepoName(common.ThirdPartyContainerRepo(cfg.Config.Repository, common.DockerRegistryURL), "bitnami/mysqld-exporter")),
48+
helm.ImagePullSecrets("mysql.volumePermissions.image.pullSecrets", cfg),
49+
helm.KeyValue("mysql.volumePermissions.image.pullPolicy", "IfNotPresent"),
50+
helm.KeyValue("mysql.volumePermissions.image.registry", ""),
51+
helm.KeyValue("mysql.volumePermissions.image.repository", cfg.RepoName(common.ThirdPartyContainerRepo(cfg.Config.Repository, common.DockerRegistryURL), "bitnami/bitnami-shell")),
4652

47-
// improve start time
48-
helm.KeyValue("mysql.primary.startupProbe.enabled", "false"),
49-
helm.KeyValue("mysql.primary.livenessProbe.initialDelaySeconds", "30"),
50-
},
53+
// improve start time
54+
helm.KeyValue("mysql.primary.startupProbe.enabled", "false"),
55+
helm.KeyValue("mysql.primary.livenessProbe.initialDelaySeconds", "30"),
56+
},
57+
customization...,
58+
),
5159
// This is too complex to be sent as a string
5260
FileValues: []string{
5361
primaryAffinityTemplate,

install/installer/third_party/charts/mysql/values.yaml

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,19 @@ mysql:
88
# We switched to the specific version because "5.7" was broken at least once
99
tag: 5.7.34-debian-10-r55
1010
primary:
11+
# Backup settings
12+
podAnnotations:
13+
backup.velero.io/backup-volumes: backup
14+
pre.hook.backup.velero.io/command: |
15+
["/bin/bash", "-c", "mysqldump -u root -p$MYSQL_ROOT_PASSWORD --databases $MYSQL_DATABASE gitpod-sessions -h 127.0.0.1 > /backup/mysqldump.sql"]
16+
pre.hook.backup.velero.io/timeout: 5m
17+
extraVolumes:
18+
- name: backup
19+
emptyDir: {}
20+
extraVolumeMounts:
21+
- name: backup
22+
mountPath: /backup
23+
# End of backup settings
1124
extraEnvVars:
1225
# We rely on this in our DB implementations: NULL (re-)sets configured columns to be initialized with CURRENT_TIMESTAMP.
1326
# OFF is the default as documented [here](https://dev.mysql.com/doc/refman/5.7/en/server-system-variables.html#sysvar_explicit_defaults_for_timestamp) (we also see this in GCP), but not for this chart.
@@ -19,4 +32,4 @@ mysql:
1932
serviceAccount:
2033
create: false
2134
volumePermissions:
22-
enabled: true
35+
enabled: true

0 commit comments

Comments
 (0)