Skip to content

Commit

Permalink
*: simplify backup code radondb#226, radondb#191
Browse files Browse the repository at this point in the history
  • Loading branch information
acekingke committed Sep 18, 2021
1 parent 969e237 commit c3ccf59
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 34 deletions.
8 changes: 4 additions & 4 deletions api/v1alpha1/cluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ type ClusterSpec struct {

// MysqlOpts is the options of MySQL container.
// +optional
// +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"}}}
// +kubebuilder:default:={rootPassword: "", rootHost: "localhost", user: "rdb_usr", password: "RadonDB@123", database: "radondb", initTokuDB: true, resources: {limits: {cpu: "500m", memory: "1Gi"}, requests: {cpu: "100m", memory: "256Mi"}}}
MysqlOpts MysqlOpts `json:"mysqlOpts,omitempty"`

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

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

// Name for new database to create.
// +optional
// +kubebuilder:default:="qingcloud"
// +kubebuilder:default:="radondb"
Database string `json:"database,omitempty"`

// InitTokuDB represents if install tokudb engine.
Expand Down
2 changes: 0 additions & 2 deletions backup/syncer/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ func (s *jobSyncer) updateStatus(job *batchv1.Job) {
// check for completion condition
if cond := jobCondition(batchv1.JobComplete, job); cond != nil {
s.backup.UpdateStatusCondition(v1alpha1.BackupComplete, cond.Status, cond.Reason, cond.Message)

if cond.Status == corev1.ConditionTrue {
s.backup.Status.Completed = true
}
Expand All @@ -91,7 +90,6 @@ func (s *jobSyncer) updateStatus(job *batchv1.Job) {
// check for failed condition
if cond := jobCondition(batchv1.JobFailed, job); cond != nil {
s.backup.UpdateStatusCondition(v1alpha1.BackupFailed, cond.Status, cond.Reason, cond.Message)

if cond.Status == corev1.ConditionTrue {
s.backup.Status.Completed = true
}
Expand Down
2 changes: 1 addition & 1 deletion charts/helm/templates/secrets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ data:
mysql-root-password: {{ randAlphaNum 12 | b64enc | quote }}
{{- end }}
{{- end }}
{{- if and .Values.mysql.mysqlUser (and (ne .Values.mysql.mysqlUser "qc_repl") (ne .Values.mysql.mysqlUser "root")) }}
{{- if and .Values.mysql.mysqlUser (and (ne .Values.mysql.mysqlUser "rdb_repl") (ne .Values.mysql.mysqlUser "root")) }}
{{- if .Values.mysql.mysqlPassword }}
mysql-password: {{ .Values.mysql.mysqlPassword | b64enc | quote }}
{{- else }}
Expand Down
6 changes: 3 additions & 3 deletions charts/helm/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ mysql:
# mysqlRootPassword:
mysqlReplicationPassword: Repl_123

mysqlUser: qingcloud
mysqlPassword: Qing@123
mysqlDatabase: qingcloud
mysqlUser: radondb
mysqlPassword: RadonDB@123
mysqlDatabase: radondb

initTokudb: false
## Additionnal arguments that are passed to the MySQL container.
Expand Down
2 changes: 1 addition & 1 deletion charts/mysql-operator/crds/mysql.radondb.com_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
description: HostName represents the host for which to take backup
type: string
image:
default: radondb/mysql-sidecar:0.1.88
default: radondb/mysql-sidecar:latest
description: To specify the image that will be used for sidecar container.
type: string
required:
Expand Down
12 changes: 6 additions & 6 deletions charts/mysql-operator/crds/mysql.radondb.com_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ spec:
type: string
mysqlOpts:
default:
database: qingcloud
database: radondb
initTokuDB: true
password: Qing@123
password: RadonDB@123
resources:
limits:
cpu: 500m
Expand All @@ -129,11 +129,11 @@ spec:
memory: 256Mi
rootHost: localhost
rootPassword: ""
user: qc_usr
user: rdb_usr
description: MysqlOpts is the options of MySQL container.
properties:
database:
default: qingcloud
default: radondb
description: Name for new database to create.
type: string
initTokuDB:
Expand All @@ -147,7 +147,7 @@ spec:
file.
type: object
password:
default: Qing@123
default: RadonDB@123
description: 'Password for the new user, must be 8~32 characters
long. Only be a combination of uppercase letters, lowercase
letters, numbers or special characters. Special characters are
Expand Down Expand Up @@ -200,7 +200,7 @@ spec:
pattern: ^$|^[A-Za-z0-9@#$%^&*_+\-=]{8,32}$
type: string
user:
default: qc_usr
default: rdb_usr
description: Username of new user to create. Only be a combination
of letters, numbers or underlines. The length can not exceed
26 characters.
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/mysql.radondb.com_backups.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ spec:
description: HostName represents the host for which to take backup
type: string
image:
default: radondb/mysql-sidecar:0.1.88
default: radondb/mysql-sidecar:latest
description: To specify the image that will be used for sidecar container.
type: string
required:
Expand Down
12 changes: 6 additions & 6 deletions config/crd/bases/mysql.radondb.com_clusters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,9 @@ spec:
type: string
mysqlOpts:
default:
database: qingcloud
database: radondb
initTokuDB: true
password: Qing@123
password: RadonDB@123
resources:
limits:
cpu: 500m
Expand All @@ -129,11 +129,11 @@ spec:
memory: 256Mi
rootHost: localhost
rootPassword: ""
user: qc_usr
user: rdb_usr
description: MysqlOpts is the options of MySQL container.
properties:
database:
default: qingcloud
default: radondb
description: Name for new database to create.
type: string
initTokuDB:
Expand All @@ -147,7 +147,7 @@ spec:
file.
type: object
password:
default: Qing@123
default: RadonDB@123
description: 'Password for the new user, must be 8~32 characters
long. Only be a combination of uppercase letters, lowercase
letters, numbers or special characters. Special characters are
Expand Down Expand Up @@ -200,7 +200,7 @@ spec:
pattern: ^$|^[A-Za-z0-9@#$%^&*_+\-=]{8,32}$
type: string
user:
default: qc_usr
default: rdb_usr
description: Username of new user to create. Only be a combination
of letters, numbers or underlines. The length can not exceed
26 characters.
Expand Down
6 changes: 3 additions & 3 deletions config/samples/mysql_v1alpha1_cluster.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ spec:
mysqlOpts:
rootPassword: ""
rootHost: localhost
user: qc_usr
password: Qing@123
database: qingcloud
user: rdb_usr
password: RadonDB@123
database: randondb
initTokuDB: true

# A simple map between string and string.
Expand Down
8 changes: 4 additions & 4 deletions controllers/backup_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ func (r *BackupReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctr
}

// Clear the backup, Just keep historyLimit len
if err = r.clearHistoryJob(ctx, req, backup); err != nil {
if err = r.clearHistoryJob(ctx, req, *backup.Spec.HistoryLimit); err != nil {
return reconcile.Result{}, err
}
return ctrl.Result{}, nil
}

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

for i, job := range finishedBackups {
if int32(i) >= int32(len(finishedBackups))-*backup.Spec.HistoryLimit {
if int32(i) >= int32(len(finishedBackups))-historyLimit {
break
}
if err := r.Delete(ctx, job, client.PropagationPolicy(metav1.DeletePropagationBackground)); client.IgnoreNotFound(err) != nil {
Expand Down Expand Up @@ -155,7 +155,7 @@ func (r *BackupReconciler) updateBackup(savedBackup *apiv1alpha1.Backup, backup
log.Info("update backup object status")
if err := r.Status().Update(context.TODO(), backup.Unwrap()); err != nil {
log.Error(err, fmt.Sprintf("update status backup %s/%s", backup.Name, backup.Namespace),
"backupStatus", backup.Status)
"backupStatus", backup.Status, "saveBackupStatus", savedBackup.Status)
return err
}
}
Expand Down
6 changes: 3 additions & 3 deletions utils/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ const (
XenonPeerPort = 6601

// The name of the MySQL replication user.
ReplicationUser = "qc_repl"
ReplicationUser = "rdb_repl"
// The name of the MySQL metrics user.
MetricsUser = "qc_metrics"
MetricsUser = "rdb_metrics"
// The MySQL user used for operator to connect to the mysql node for configuration.
OperatorUser = "qc_operator"
OperatorUser = "rdb_operator"

// xtrabackup http server user
BackupUser = "sys_backup"
Expand Down

0 comments on commit c3ccf59

Please sign in to comment.