Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
lichunzhu committed Aug 12, 2020
1 parent 266b23c commit a46fa12
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 12 deletions.
1 change: 1 addition & 0 deletions cmd/backup-manager/app/cmd/export.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func NewExportCommand() *cobra.Command {
cmd.Flags().StringVar(&bo.Namespace, "namespace", "", "Backup CR's namespace")
cmd.Flags().StringVar(&bo.ResourceName, "backupName", "", "Backup CRD object name")
cmd.Flags().StringVar(&bo.Bucket, "bucket", "", "Bucket in which to store the backup data")
cmd.Flags().BoolVar(&bo.TLSClient, "client-tls", false, "Whether client tls is enabled")
cmd.Flags().StringVar(&bo.StorageType, "storageType", "", "Backend storage type")
return cmd
}
Expand Down
1 change: 1 addition & 0 deletions cmd/backup-manager/app/cmd/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ func NewImportCommand() *cobra.Command {

cmd.Flags().StringVar(&ro.Namespace, "namespace", "", "Restore CR's namespace")
cmd.Flags().StringVar(&ro.ResourceName, "restoreName", "", "Restore CRD object name")
cmd.Flags().BoolVar(&ro.TLSClient, "client-tls", false, "Whether client tls is enabled")
cmd.Flags().StringVar(&ro.BackupPath, "backupPath", "", "The location of the backup")
return cmd
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/backup-manager/app/export/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,7 @@ func (bm *BackupManager) ProcessBackup() error {
var db *sql.DB
var dsn string
err = wait.PollImmediate(constants.PollInterval, constants.CheckTimeout, func() (done bool, err error) {
// TLS is not currently supported
dsn, err = bm.GetDSN(false)
dsn, err = bm.GetDSN(bm.TLSClient)
if err != nil {
klog.Errorf("can't get dsn of tidb cluster %s, err: %s", bm, err)
return false, err
Expand Down
4 changes: 2 additions & 2 deletions cmd/backup-manager/app/import/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ func (rm *RestoreManager) ProcessRestore() error {
var db *sql.DB
var dsn string
err = wait.PollImmediate(constants.PollInterval, constants.CheckTimeout, func() (done bool, err error) {
// TLS is not currently supported
dsn, err = rm.GetDSN(false)
// TODO: for local backend mode, lightning will use both pd and mysql client. We should set both tls configurations in that mode
dsn, err = rm.GetDSN(rm.TLSClient)
if err != nil {
klog.Errorf("can't get dsn of tidb cluster %s, err: %s", rm, err)
return false, err
Expand Down
28 changes: 24 additions & 4 deletions pkg/backup/backup/backup_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,26 @@ func (bm *backupManager) makeExportJob(backup *v1alpha1.Backup) (*batchv1.Job, s
fmt.Sprintf("--storageType=%s", backuputil.GetStorageType(backup.Spec.StorageProvider)),
}

volumeMounts := []corev1.VolumeMount{}
volumes := []corev1.Volume{}
if backup.Spec.From.TLSClientSecretName != nil {
args = append(args, "--client-tls=true")
clientSecretName := *backup.Spec.From.TLSClientSecretName
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "tidb-client-tls",
ReadOnly: true,
MountPath: util.TiDBClientTLSPath,
})
volumes = append(volumes, corev1.Volume{
Name: "tidb-client-tls",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: clientSecretName,
},
},
})
}

serviceAccount := constants.DefaultServiceAccountName
if backup.Spec.ServiceAccount != "" {
serviceAccount = backup.Spec.ServiceAccount
Expand All @@ -218,17 +238,17 @@ func (bm *backupManager) makeExportJob(backup *v1alpha1.Backup) (*batchv1.Job, s
Image: controller.TidbBackupManagerImage,
Args: args,
ImagePullPolicy: corev1.PullIfNotPresent,
VolumeMounts: []corev1.VolumeMount{
VolumeMounts: append([]corev1.VolumeMount{
{Name: label.BackupJobLabelVal, MountPath: constants.BackupRootPath},
},
}, volumeMounts...),
Env: util.AppendEnvIfPresent(envVars, "TZ"),
Resources: backup.Spec.ResourceRequirements,
},
},
RestartPolicy: corev1.RestartPolicyNever,
Affinity: backup.Spec.Affinity,
Tolerations: backup.Spec.Tolerations,
Volumes: []corev1.Volume{
Volumes: append([]corev1.Volume{
{
Name: label.BackupJobLabelVal,
VolumeSource: corev1.VolumeSource{
Expand All @@ -237,7 +257,7 @@ func (bm *backupManager) makeExportJob(backup *v1alpha1.Backup) (*batchv1.Job, s
},
},
},
},
}, volumes...),
},
}

Expand Down
28 changes: 24 additions & 4 deletions pkg/backup/restore/restore_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ func (rm *restoreManager) makeImportJob(restore *v1alpha1.Restore) (*batchv1.Job
fmt.Sprintf("--backupPath=%s", backupPath),
}

volumeMounts := []corev1.VolumeMount{}
volumes := []corev1.Volume{}
if restore.Spec.To.TLSClientSecretName != nil {
args = append(args, "--client-tls=true")
clientSecretName := *restore.Spec.To.TLSClientSecretName
volumeMounts = append(volumeMounts, corev1.VolumeMount{
Name: "tidb-client-tls",
ReadOnly: true,
MountPath: util.TiDBClientTLSPath,
})
volumes = append(volumes, corev1.Volume{
Name: "tidb-client-tls",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: clientSecretName,
},
},
})
}

restoreLabel := label.NewBackup().Instance(restore.GetInstanceName()).RestoreJob().Restore(name)
serviceAccount := constants.DefaultServiceAccountName
if restore.Spec.ServiceAccount != "" {
Expand All @@ -204,17 +224,17 @@ func (rm *restoreManager) makeImportJob(restore *v1alpha1.Restore) (*batchv1.Job
Image: controller.TidbBackupManagerImage,
Args: args,
ImagePullPolicy: corev1.PullIfNotPresent,
VolumeMounts: []corev1.VolumeMount{
VolumeMounts: append([]corev1.VolumeMount{
{Name: label.RestoreJobLabelVal, MountPath: constants.BackupRootPath},
},
}, volumeMounts...),
Env: util.AppendEnvIfPresent(envVars, "TZ"),
Resources: restore.Spec.ResourceRequirements,
},
},
RestartPolicy: corev1.RestartPolicyNever,
Affinity: restore.Spec.Affinity,
Tolerations: restore.Spec.Tolerations,
Volumes: []corev1.Volume{
Volumes: append([]corev1.Volume{
{
Name: label.RestoreJobLabelVal,
VolumeSource: corev1.VolumeSource{
Expand All @@ -223,7 +243,7 @@ func (rm *restoreManager) makeImportJob(restore *v1alpha1.Restore) (*batchv1.Job
},
},
},
},
}, volumes...),
},
}

Expand Down

0 comments on commit a46fa12

Please sign in to comment.