Skip to content

Commit 21026b8

Browse files
author
Simon Emms
committed
[installer]: add backup command to in-cluster mysql
1 parent c299a2b commit 21026b8

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

install/installer/pkg/common/common.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package common
66

77
import (
8+
"bytes"
89
"crypto/sha256"
910
"encoding/json"
1011
"fmt"
@@ -613,3 +614,12 @@ func NodeNameEnv(context *RenderContext) []corev1.EnvVar {
613614
},
614615
}}
615616
}
617+
618+
// ToUnescapedJSONString returns the serialized JSON string of an object without escaping any of the characters
619+
func ToUnescapedJSONString(t interface{}) ([]byte, error) {
620+
buffer := &bytes.Buffer{}
621+
encoder := json.NewEncoder(buffer)
622+
encoder.SetEscapeHTML(false)
623+
err := encoder.Encode(t)
624+
return buffer.Bytes(), err
625+
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ var Helm = common.CompositeHelmFunc(
2424
return nil, err
2525
}
2626

27+
backupCmd, err := common.ToUnescapedJSONString([]string{
28+
"/bin/bash",
29+
"-c",
30+
"echo \"hello world\" > /backup/sje.txt",
31+
})
32+
33+
backupSettings, err := helm.KeyFileValue("mysql.primary.podAnnotations.pre\\.hook\\.backup\\.velero\\.io/command", backupCmd)
34+
if err != nil {
35+
return nil, err
36+
}
37+
2738
customization := helm.CustomizeAnnotation([]string{}, "mysql.primary.podAnnotations", cfg, Component, common.TypeMetaDeployment)
2839
customization = helm.CustomizeLabel(customization, "mysql.primary.podLabels", cfg, Component, common.TypeMetaDeployment)
2940
customization = helm.CustomizeAnnotation(customization, "mysql.primary.service.annotations", cfg, Component, common.TypeMetaService)
@@ -58,6 +69,7 @@ var Helm = common.CompositeHelmFunc(
5869
// This is too complex to be sent as a string
5970
FileValues: []string{
6071
primaryAffinityTemplate,
72+
backupSettings,
6173
},
6274
},
6375
}, nil

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,17 @@ 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/timeout: 5m
15+
extraVolumes:
16+
- name: backup
17+
emptyDir: {}
18+
extraVolumeMounts:
19+
- name: backup
20+
mountPath: /backup
21+
# End of backup settings
1122
extraEnvVars:
1223
# We rely on this in our DB implementations: NULL (re-)sets configured columns to be initialized with CURRENT_TIMESTAMP.
1324
# 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 +30,4 @@ mysql:
1930
serviceAccount:
2031
create: false
2132
volumePermissions:
22-
enabled: true
33+
enabled: true

0 commit comments

Comments
 (0)