Skip to content

Commit 6c209cf

Browse files
committed
mariadb - add a .my.cnf file
This will ease the interaction with the mariadb database. From the pod, one can just type 'mysql' w/o args to interact. Change-Id: I5d01f06a4b3cd9f9f57402e258365be9bb1a2a3d
1 parent 32e2e38 commit 6c209cf

File tree

4 files changed

+33
-12
lines changed

4 files changed

+33
-12
lines changed

cli/cmd/backup.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,22 +158,13 @@ func createMySQLBackup(ns string, backupDir string, kubeClientSet *kubernetes.Cl
158158
// create MariaDB dir
159159
mariaDBBackupDir := backupDir + "/mariadb/"
160160
cliutils.CreateDirectory(mariaDBBackupDir, 0755)
161-
mariadbPass := cliutils.GetSecretValue(ns, kubeClientSet, controllers.MariadbAdminPass)
162-
163-
if mariadbPass == nil {
164-
ctrl.Log.Error(errors.New("MariaDB password is missing"),
165-
"Can not continue. Password in the MariaDB secret is empty!")
166-
os.Exit(1)
167-
}
168161

169162
pod := cliutils.GetPodByName(dbBackupPod, ns, kubeClientSet)
170163

171164
// NOTE: We use option: --single-transaction to avoid error:
172165
// "The user specified as a definer ('mariadb.sys'@'localhost') does not exist" when using LOCK TABLES
173166
backupZuulCMD := []string{
174167
"mysqldump",
175-
"-uroot",
176-
"-p" + *mariadbPass,
177168
"--databases",
178169
"zuul",
179170
"--single-transaction",

controllers/mariadb.go

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ const (
3232
//go:embed static/mariadb/fluentbit/fluent-bit.conf.tmpl
3333
var mariadbFluentBitForwarderConfig string
3434

35+
//go:embed static/mariadb/my.cnf.tmpl
36+
var mariadbMyCNF string
37+
3538
type ZuulDBOpts struct {
3639
Username string
3740
Password string
@@ -169,7 +172,23 @@ func (r *SFController) DBPostInit(configSecret apiv1.Secret) apiv1.Secret {
169172
}
170173

171174
func (r *SFController) DeployMariadb() bool {
172-
r.EnsureSecretUUID(MariadbAdminPass)
175+
adminPassSecret := r.EnsureSecretUUID(MariadbAdminPass)
176+
177+
myCNF, _ := utils.ParseString(mariadbMyCNF,
178+
struct {
179+
MYSQLRootPassword string
180+
}{MYSQLRootPassword: string(adminPassSecret.Data["mariadb-root-password"])})
181+
182+
configSecret := apiv1.Secret{
183+
ObjectMeta: metav1.ObjectMeta{
184+
Name: "mariadb-config-secrets",
185+
Namespace: r.ns,
186+
},
187+
Data: map[string][]byte{
188+
"my.cnf": []byte(myCNF),
189+
},
190+
}
191+
r.EnsureSecret(&configSecret)
173192

174193
sts := r.mkStatefulSet(MariaDBIdent, base.MariaDBImage(), r.getStorageConfOrDefault(r.cr.Spec.MariaDB.DBStorage), apiv1.ReadWriteOnce)
175194

@@ -194,6 +213,12 @@ func (r *SFController) DeployMariadb() bool {
194213
Name: "mariadb-run",
195214
MountPath: "/run/mariadb",
196215
},
216+
{
217+
Name: "mariadb-config-secrets",
218+
SubPath: "my.cnf",
219+
MountPath: "/var/lib/mysql/.my.cnf",
220+
ReadOnly: true,
221+
},
197222
}, volumeMountsStatsExporter...)
198223
sts.Spec.Template.Spec.Containers[0].Env = []apiv1.EnvVar{
199224
base.MkEnvVar("HOME", "/var/lib/mysql"),
@@ -207,10 +232,11 @@ func (r *SFController) DeployMariadb() bool {
207232
sts.Spec.Template.Spec.Containers[0].LivenessProbe = base.MkReadinessTCPProbe(mariadbPort)
208233
sts.Spec.Template.Spec.Volumes = []apiv1.Volume{
209234
base.MkEmptyDirVolume("mariadb-run"),
235+
base.MkVolumeSecret("mariadb-config-secrets", "mariadb-config-secrets"),
210236
}
211237

212238
annotations := map[string]string{
213-
"serial": "3",
239+
"serial": "4",
214240
}
215241
if r.cr.Spec.FluentBitLogForwarding != nil {
216242
fbVolume, fbSidecar := createLogForwarderSidecar(r, annotations)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[client]
2+
user=root
3+
host=localhost
4+
password={{ .MYSQLRootPassword }}

controllers/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func (r *SFUtilContext) ensureSecretFromFunc(name string, getData func() string)
236236
return secret
237237
}
238238

239-
// EnsureSecretUUID ensures a Secret caontaining an UUID
239+
// EnsureSecretUUID ensures a Secret containing an UUID
240240
// This function does not support update
241241
func (r *SFUtilContext) EnsureSecretUUID(name string) apiv1.Secret {
242242
return r.ensureSecretFromFunc(name, utils.NewUUIDString)

0 commit comments

Comments
 (0)