Skip to content

Commit e9b949d

Browse files
committed
*: simplify backup code #226, #191
1 parent 969e237 commit e9b949d

File tree

11 files changed

+32
-34
lines changed

11 files changed

+32
-34
lines changed

api/v1alpha1/cluster_types.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type ClusterSpec struct {
4343

4444
// MysqlOpts is the options of MySQL container.
4545
// +optional
46-
// +kubebuilder:default:={rootPassword: "", rootHost: "localhost", user: "qc_usr", password: "Qing@123", database: "qingcloud", initTokuDB: true, resources: {limits: {cpu: "500m", memory: "1Gi"}, requests: {cpu: "100m", memory: "256Mi"}}}
46+
// +kubebuilder:default:={rootPassword: "", rootHost: "localhost", user: "radondb_usr", password: "RadonDB@123", database: "radondb", initTokuDB: true, resources: {limits: {cpu: "500m", memory: "1Gi"}, requests: {cpu: "100m", memory: "256Mi"}}}
4747
MysqlOpts MysqlOpts `json:"mysqlOpts,omitempty"`
4848

4949
// XenonOpts is the options of xenon container.
@@ -101,21 +101,21 @@ type MysqlOpts struct {
101101
// Username of new user to create.
102102
// Only be a combination of letters, numbers or underlines. The length can not exceed 26 characters.
103103
// +optional
104-
// +kubebuilder:default:="qc_usr"
104+
// +kubebuilder:default:="radondb_usr"
105105
// +kubebuilder:validation:Pattern="^[A-Za-z0-9_]{2,26}$"
106106
User string `json:"user,omitempty"`
107107

108108
// Password for the new user, must be 8~32 characters long.
109109
// Only be a combination of uppercase letters, lowercase letters, numbers or special characters.
110110
// Special characters are supported: @#$%^&*_+-=.
111111
// +optional
112-
// +kubebuilder:default:="Qing@123"
112+
// +kubebuilder:default:="RadonDB@123"
113113
// +kubebuilder:validation:Pattern="^[A-Za-z0-9@#$%^&*_+\\-=]{8,32}$"
114114
Password string `json:"password,omitempty"`
115115

116116
// Name for new database to create.
117117
// +optional
118-
// +kubebuilder:default:="qingcloud"
118+
// +kubebuilder:default:="radondb"
119119
Database string `json:"database,omitempty"`
120120

121121
// InitTokuDB represents if install tokudb engine.

backup/syncer/job.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ func (s *jobSyncer) updateStatus(job *batchv1.Job) {
8282
// check for completion condition
8383
if cond := jobCondition(batchv1.JobComplete, job); cond != nil {
8484
s.backup.UpdateStatusCondition(v1alpha1.BackupComplete, cond.Status, cond.Reason, cond.Message)
85-
8685
if cond.Status == corev1.ConditionTrue {
8786
s.backup.Status.Completed = true
8887
}
@@ -91,7 +90,6 @@ func (s *jobSyncer) updateStatus(job *batchv1.Job) {
9190
// check for failed condition
9291
if cond := jobCondition(batchv1.JobFailed, job); cond != nil {
9392
s.backup.UpdateStatusCondition(v1alpha1.BackupFailed, cond.Status, cond.Reason, cond.Message)
94-
9593
if cond.Status == corev1.ConditionTrue {
9694
s.backup.Status.Completed = true
9795
}

charts/helm/templates/secrets.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ data:
1616
mysql-root-password: {{ randAlphaNum 12 | b64enc | quote }}
1717
{{- end }}
1818
{{- end }}
19-
{{- if and .Values.mysql.mysqlUser (and (ne .Values.mysql.mysqlUser "qc_repl") (ne .Values.mysql.mysqlUser "root")) }}
19+
{{- if and .Values.mysql.mysqlUser (and (ne .Values.mysql.mysqlUser "radondb_repl") (ne .Values.mysql.mysqlUser "root")) }}
2020
{{- if .Values.mysql.mysqlPassword }}
2121
mysql-password: {{ .Values.mysql.mysqlPassword | b64enc | quote }}
2222
{{- else }}

charts/helm/values.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ mysql:
3030
# mysqlRootPassword:
3131
mysqlReplicationPassword: Repl_123
3232

33-
mysqlUser: qingcloud
34-
mysqlPassword: Qing@123
35-
mysqlDatabase: qingcloud
33+
mysqlUser: radondb
34+
mysqlPassword: RadonDB@123
35+
mysqlDatabase: radondb
3636

3737
initTokudb: false
3838
## Additionnal arguments that are passed to the MySQL container.

charts/mysql-operator/crds/mysql.radondb.com_backups.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
description: HostName represents the host for which to take backup
4949
type: string
5050
image:
51-
default: radondb/mysql-sidecar:0.1.88
51+
default: radondb/mysql-sidecar:latest
5252
description: To specify the image that will be used for sidecar container.
5353
type: string
5454
required:

charts/mysql-operator/crds/mysql.radondb.com_clusters.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ spec:
117117
type: string
118118
mysqlOpts:
119119
default:
120-
database: qingcloud
120+
database: radondb
121121
initTokuDB: true
122-
password: Qing@123
122+
password: RadonDB@123
123123
resources:
124124
limits:
125125
cpu: 500m
@@ -129,11 +129,11 @@ spec:
129129
memory: 256Mi
130130
rootHost: localhost
131131
rootPassword: ""
132-
user: qc_usr
132+
user: radondb_usr
133133
description: MysqlOpts is the options of MySQL container.
134134
properties:
135135
database:
136-
default: qingcloud
136+
default: radondb
137137
description: Name for new database to create.
138138
type: string
139139
initTokuDB:
@@ -147,7 +147,7 @@ spec:
147147
file.
148148
type: object
149149
password:
150-
default: Qing@123
150+
default: RadonDB@123
151151
description: 'Password for the new user, must be 8~32 characters
152152
long. Only be a combination of uppercase letters, lowercase
153153
letters, numbers or special characters. Special characters are
@@ -200,7 +200,7 @@ spec:
200200
pattern: ^$|^[A-Za-z0-9@#$%^&*_+\-=]{8,32}$
201201
type: string
202202
user:
203-
default: qc_usr
203+
default: radondb_usr
204204
description: Username of new user to create. Only be a combination
205205
of letters, numbers or underlines. The length can not exceed
206206
26 characters.

config/crd/bases/mysql.radondb.com_backups.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ spec:
4848
description: HostName represents the host for which to take backup
4949
type: string
5050
image:
51-
default: radondb/mysql-sidecar:0.1.88
51+
default: radondb/mysql-sidecar:latest
5252
description: To specify the image that will be used for sidecar container.
5353
type: string
5454
required:

config/crd/bases/mysql.radondb.com_clusters.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ spec:
117117
type: string
118118
mysqlOpts:
119119
default:
120-
database: qingcloud
120+
database: radondb
121121
initTokuDB: true
122-
password: Qing@123
122+
password: RadonDB@123
123123
resources:
124124
limits:
125125
cpu: 500m
@@ -129,11 +129,11 @@ spec:
129129
memory: 256Mi
130130
rootHost: localhost
131131
rootPassword: ""
132-
user: qc_usr
132+
user: radondb_usr
133133
description: MysqlOpts is the options of MySQL container.
134134
properties:
135135
database:
136-
default: qingcloud
136+
default: radondb
137137
description: Name for new database to create.
138138
type: string
139139
initTokuDB:
@@ -147,7 +147,7 @@ spec:
147147
file.
148148
type: object
149149
password:
150-
default: Qing@123
150+
default: RadonDB@123
151151
description: 'Password for the new user, must be 8~32 characters
152152
long. Only be a combination of uppercase letters, lowercase
153153
letters, numbers or special characters. Special characters are
@@ -200,7 +200,7 @@ spec:
200200
pattern: ^$|^[A-Za-z0-9@#$%^&*_+\-=]{8,32}$
201201
type: string
202202
user:
203-
default: qc_usr
203+
default: radondb_usr
204204
description: Username of new user to create. Only be a combination
205205
of letters, numbers or underlines. The length can not exceed
206206
26 characters.

config/samples/mysql_v1alpha1_cluster.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ spec:
1616
mysqlOpts:
1717
rootPassword: ""
1818
rootHost: localhost
19-
user: qc_usr
20-
password: Qing@123
21-
database: qingcloud
19+
user: radondb_usr
20+
password: RadonDB@123
21+
database: randondb
2222
initTokuDB: true
2323

2424
# A simple map between string and string.

controllers/backup_controller.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,14 @@ func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
9191
}
9292

9393
// Clear the backup, Just keep historyLimit len
94-
if err = r.clearHistoryJob(ctx, req, backup); err != nil {
94+
if err = r.clearHistoryJob(ctx, req, *backup.Spec.HistoryLimit); err != nil {
9595
return reconcile.Result{}, err
9696
}
9797
return ctrl.Result{}, nil
9898
}
9999

100100
// Clear the History finished Jobs over HistoryLimit.
101-
func (r *BackupReconciler) clearHistoryJob(ctx context.Context, req ctrl.Request, backup *backup.Backup) error {
101+
func (r *BackupReconciler) clearHistoryJob(ctx context.Context, req ctrl.Request, historyLimit int32) error {
102102
log := log.Log.WithName("controllers").WithName("Backup")
103103
backups := batchv1.JobList{}
104104
labelSet := labels.Set{"Type": utils.BackupJobTypeName}
@@ -123,7 +123,7 @@ func (r *BackupReconciler) clearHistoryJob(ctx context.Context, req ctrl.Request
123123
})
124124

125125
for i, job := range finishedBackups {
126-
if int32(i) >= int32(len(finishedBackups))-*backup.Spec.HistoryLimit {
126+
if int32(i) >= int32(len(finishedBackups))-historyLimit {
127127
break
128128
}
129129
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil {
@@ -155,7 +155,7 @@ func (r *BackupReconciler) updateBackup(savedBackup *apiv1alpha1.Backup, backup
155155
log.Info("update backup object status")
156156
if err := r.Status().Update(context.TODO(), backup.Unwrap()); err != nil {
157157
log.Error(err, fmt.Sprintf("update status backup %s/%s", backup.Name, backup.Namespace),
158-
"backupStatus", backup.Status)
158+
"backupStatus", backup.Status, "saveBackupStatus", savedBackup.Status)
159159
return err
160160
}
161161
}

0 commit comments

Comments
 (0)