Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add binlog deploy and check process #329

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
delete unnessary step and add scheduled-backup-job check step
shuijing198799 committed Mar 18, 2019
commit 2746c823452fac6c76893551a00b61f62e7e5d2a
47 changes: 22 additions & 25 deletions tests/actions.go
Original file line number Diff line number Diff line change
@@ -49,14 +49,10 @@ func NewOperatorActions(cli versioned.Interface, kubeCli kubernetes.Interface) O

const (
DefaultPollTimeout time.Duration = 10 * time.Minute
DefaultPollInterval time.Duration = 1 * time.Minute
DefaultPollInterval time.Duration = 10 * time.Second
getBackupDirPodName = "get-backup-dir"
)

var (
backupDir string
)

type OperatorActions interface {
DeployOperator(info *OperatorInfo) error
CleanOperator(info *OperatorInfo) error
@@ -81,7 +77,7 @@ type OperatorActions interface {
CleanMonitor(info *TidbClusterInfo) error
ForceDeploy(info *TidbClusterInfo) error
CreateSecret(info *TidbClusterInfo) error
getBackupDir(info *TidbClusterInfo) (string, error)
getBackupDir(info *TidbClusterInfo) (int, error)
}

type FaultTriggerActions interface {
@@ -260,9 +256,10 @@ func (oa *operatorActions) CleanTidbCluster(info *TidbClusterInfo) error {
}
}

_, err := oa.kubeCli.CoreV1().Pods(info.Namespace).Get(getBackupDirPodName, metav1.GetOptions{})
if !errors.IsNotFound(err) {
oa.kubeCli.CoreV1().Pods(info.Namespace).Delete(getBackupDirPodName, &metav1.DeleteOptions{})
err := oa.kubeCli.CoreV1().Pods(info.Namespace).Delete(getBackupDirPodName, &metav1.DeleteOptions{})

if err != nil && !errors.IsNotFound(err) {
return fmt.Errorf("failed to delete dir pod %v", err)
}

setStr := label.New().Instance(info.ClusterName).String()
@@ -860,8 +857,6 @@ func (oa *operatorActions) DeployAdHocBackup(info *TidbClusterInfo) error {
defer func() {
glog.Infof("deploy adhoc backup end cluster[%s] namespace[%s]", info.ClusterName, info.Namespace)
}()
// I need a name for pvc and another name for backupDir,
// But in operator, there are the same
sets := map[string]string{
"clusterName": info.ClusterName,
"name": info.Name,
@@ -918,11 +913,6 @@ func (oa *operatorActions) CheckAdHocBackup(info *TidbClusterInfo) error {
return fmt.Errorf("failed to launch scheduler backup job: %v", err)
}

backupDir, err = oa.getBackupDir(info)
if err != nil {
return fmt.Errorf("failed to get backup dir: %v", err)
}

return nil
}

@@ -1091,8 +1081,8 @@ func (oa *operatorActions) DeployScheduledBackup(info *TidbClusterInfo) error {
defer func() {
glog.Infof("deploy shceduled backup end")
}()
minute := time.Now().Minute()
cron := fmt.Sprintf("'%d * * * *'", (minute+5)%60)

cron := fmt.Sprintf("'*/1 * * * *'")
sets := map[string]string{
"clusterName": info.ClusterName,
"scheduledBackup.create": "true",
@@ -1170,11 +1160,18 @@ func (oa *operatorActions) CheckScheduledBackup(info *TidbClusterInfo) error {
return fmt.Errorf("failed to launch scheduler backup job: %v", err)
}

backupDir, err = oa.getBackupDir(info)
// sleep 1 minute for cronjob
time.Sleep(60 * time.Second)

dirs, err := oa.getBackupDir(info)
if err != nil {
return fmt.Errorf("failed to get backup dir: %v", err)
}

if dirs != 3 {
return fmt.Errorf("scheduler job failed!")
}

return nil
}

@@ -1193,7 +1190,7 @@ func getParentUIDFromJob(j batchv1.Job) (types.UID, bool) {
return controllerRef.UID, true
}

func (oa *operatorActions) getBackupDir(info *TidbClusterInfo) (string, error) {
func (oa *operatorActions) getBackupDir(info *TidbClusterInfo) (int, error) {
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: getBackupDirPodName,
@@ -1237,13 +1234,13 @@ func (oa *operatorActions) getBackupDir(info *TidbClusterInfo) (string, error) {
err := wait.Poll(DefaultPollInterval, DefaultPollTimeout, fn)

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

_, err = oa.kubeCli.CoreV1().Pods(info.Namespace).Create(pod)
if err != nil && !errors.IsAlreadyExists(err) {
glog.Errorf("cluster: [%s/%s] create get backup dir pod failed, error :%v", info.Namespace, info.ClusterName, err)
return "", err
return 0, err
}

fn = func() (bool, error) {
@@ -1257,20 +1254,20 @@ func (oa *operatorActions) getBackupDir(info *TidbClusterInfo) (string, error) {
err = wait.Poll(DefaultPollInterval, DefaultPollTimeout, fn)

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

cmd := fmt.Sprintf("kubectl exec %s -n %s ls /data", getBackupDirPodName, info.Namespace)
glog.Infof(cmd)
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, res)
return "", err
return 0, err
}

dirs := strings.Split(string(res), "\n")
glog.Infof("dirs in pod info name [%s] dir name [%s]", info.Name, strings.Join(dirs, ","))
return strings.TrimSpace(dirs[0]), nil
return len(dirs), nil
}

func (info *TidbClusterInfo) FullName() string {
7 changes: 0 additions & 7 deletions tests/backup/backupcase.go
Original file line number Diff line number Diff line change
@@ -46,12 +46,6 @@ func (bc *BackupCase) Run() error {
return err
}

err = bc.operator.ForceDeploy(bc.desCluster)
if err != nil {
glog.Errorf("cluster:[%s] deploy happen error: %v", bc.desCluster.ClusterName, err)
return err
}

err = bc.operator.CheckTidbClusterStatus(bc.desCluster)
if err != nil {
glog.Errorf("cluster:[%s] deploy faild error: %v", bc.desCluster.ClusterName, err)
@@ -71,7 +65,6 @@ func (bc *BackupCase) Run() error {
}

bc.srcCluster.Name = "demo-scheduled-backup"
bc.desCluster.Name = "demo-scheduled-backup"

err = bc.operator.DeployScheduledBackup(bc.srcCluster)
if err != nil {
12 changes: 6 additions & 6 deletions tests/cmd/e2e/main.go
Original file line number Diff line number Diff line change
@@ -69,9 +69,9 @@ func main() {
Namespace: "tidb",
ClusterName: "demo",
OperatorTag: "master",
PDImage: "pingcap/pd:v2.1.3",
TiKVImage: "pingcap/tikv:v2.1.3",
TiDBImage: "pingcap/tidb:v2.1.3",
PDImage: "pingcap/pd:v2.1.0",
TiKVImage: "pingcap/tikv:v2.1.0",
TiDBImage: "pingcap/tidb:v2.1.0",
StorageClassName: "local-storage",
Password: "admin",
InitSql: initSql,
@@ -97,9 +97,9 @@ func main() {
Namespace: "tidb",
ClusterName: "demo2",
OperatorTag: "master",
PDImage: "pingcap/pd:v2.1.3",
TiKVImage: "pingcap/tikv:v2.1.3",
TiDBImage: "pingcap/tidb:v2.1.3",
PDImage: "pingcap/pd:v2.1.0",
TiKVImage: "pingcap/tikv:v2.1.0",
TiDBImage: "pingcap/tidb:v2.1.0",
StorageClassName: "local-storage",
Password: "admin",
InitSql: initSql,