Skip to content

Commit

Permalink
Merge branch 'release-1.0' into automated-cherry-pick-of-pingcap#826-…
Browse files Browse the repository at this point in the history
…upstream-release-1.0
  • Loading branch information
aylei authored Nov 19, 2019
2 parents 15224e4 + 4ed625e commit 4b11f99
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ const (
DefaultPollTimeout time.Duration = 10 * time.Minute
DefaultPollInterval time.Duration = 1 * time.Minute
BackupAndRestorePollTimeOut time.Duration = 60 * time.Minute
getBackupDirPodName = "get-backup-dir"
grafanaUsername = "admin"
grafanaPassword = "admin"
operartorChartName = "tidb-operator"
Expand Down Expand Up @@ -277,6 +276,10 @@ func (tc *TidbClusterConfig) String() string {
return fmt.Sprintf("%s/%s", tc.Namespace, tc.ClusterName)
}

func (tc *TidbClusterConfig) GenerateBackupDirPodName() string {
return fmt.Sprintf("%s-get-backup-dir", tc.ClusterName)
}

func (tc *TidbClusterConfig) BackupHelmSetString(m map[string]string) string {

set := map[string]string{
Expand Down Expand Up @@ -645,7 +648,7 @@ func (oa *operatorActions) CleanTidbCluster(info *TidbClusterConfig) error {
ns, tcName, beforePVNames, afterPVNames)
}

err = oa.kubeCli.CoreV1().Pods(info.Namespace).Delete(getBackupDirPodName, &metav1.DeleteOptions{})
err = oa.kubeCli.CoreV1().Pods(info.Namespace).Delete(info.GenerateBackupDirPodName(), &metav1.DeleteOptions{})
if err != nil && !errors.IsNotFound(err) {
return fmt.Errorf("failed to delete dir pod %v", err)
}
Expand Down Expand Up @@ -2275,15 +2278,16 @@ func getParentUIDFromJob(j batchv1.Job) (types.UID, bool) {

func (oa *operatorActions) getBackupDir(info *TidbClusterConfig) ([]string, error) {
scheduledPvcName := fmt.Sprintf("%s-scheduled-backup", info.ClusterName)
backupDirPodName := info.GenerateBackupDirPodName()
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: getBackupDirPodName,
Name: backupDirPodName,
Namespace: info.Namespace,
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: getBackupDirPodName,
Name: backupDirPodName,
Image: "pingcap/tidb-cloud-backup:20190610",
Command: []string{"sleep", "3000"},
VolumeMounts: []corev1.VolumeMount{
Expand All @@ -2308,7 +2312,7 @@ func (oa *operatorActions) getBackupDir(info *TidbClusterConfig) ([]string, erro
}

fn := func() (bool, error) {
_, err := oa.kubeCli.CoreV1().Pods(info.Namespace).Get(getBackupDirPodName, metav1.GetOptions{})
_, err := oa.kubeCli.CoreV1().Pods(info.Namespace).Get(backupDirPodName, metav1.GetOptions{})
if !errors.IsNotFound(err) {
return false, nil
}
Expand All @@ -2318,7 +2322,7 @@ func (oa *operatorActions) getBackupDir(info *TidbClusterConfig) ([]string, erro
err := wait.Poll(oa.pollInterval, DefaultPollTimeout, fn)

if err != nil {
return nil, fmt.Errorf("failed to delete pod %s", getBackupDirPodName)
return nil, fmt.Errorf("failed to delete pod %s, err: %v", backupDirPodName, err)
}

_, err = oa.kubeCli.CoreV1().Pods(info.Namespace).Create(pod)
Expand All @@ -2328,7 +2332,7 @@ func (oa *operatorActions) getBackupDir(info *TidbClusterConfig) ([]string, erro
}

fn = func() (bool, error) {
pod, err := oa.kubeCli.CoreV1().Pods(info.Namespace).Get(getBackupDirPodName, metav1.GetOptions{})
pod, err := oa.kubeCli.CoreV1().Pods(info.Namespace).Get(backupDirPodName, metav1.GetOptions{})
if err == nil && pod.Status.Phase == corev1.PodRunning {
return true, nil
} else if err != nil && !errors.IsNotFound(err) {
Expand All @@ -2340,10 +2344,10 @@ func (oa *operatorActions) getBackupDir(info *TidbClusterConfig) ([]string, erro
err = wait.Poll(oa.pollInterval, DefaultPollTimeout, fn)

if err != nil {
return nil, fmt.Errorf("failed to create pod %s", getBackupDirPodName)
return nil, fmt.Errorf("failed to create pod %s, err: %v", backupDirPodName, err)
}

cmd := fmt.Sprintf("kubectl exec %s -n %s ls /data", getBackupDirPodName, info.Namespace)
cmd := fmt.Sprintf("kubectl exec %s -n %s ls /data", backupDirPodName, info.Namespace)
res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
if err != nil {
glog.Errorf("cluster:[%s/%s] exec :%s failed,error:%v,result:%s", info.Namespace, info.ClusterName, cmd, err, string(res))
Expand Down

0 comments on commit 4b11f99

Please sign in to comment.