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 pods disaster tolerance and data regions disaster tolerance test cases #497

Merged
merged 35 commits into from
May 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
ca0a52b
support affinity
xiaojingchen May 9, 2019
2a3acc3
change user guide
xiaojingchen May 10, 2019
6991bd8
Merge branch 'master' into set-affinity-direactly
xiaojingchen May 13, 2019
dc8226b
add DR testcase
xiaojingchen May 14, 2019
bb9026e
run stability without download charts
xiaojingchen May 15, 2019
df11143
change makefile
xiaojingchen May 15, 2019
341186e
fix some bugs
xiaojingchen May 16, 2019
972a468
add comment
xiaojingchen May 16, 2019
9519cb9
add case to e2e
xiaojingchen May 16, 2019
eafe7fd
change operator's imagePullPolicy
xiaojingchen May 16, 2019
165b70d
Merge branch 'master' into add-DR-test
xiaojingchen May 22, 2019
3f533b1
remove confilct
xiaojingchen May 22, 2019
d774f87
Merge branch 'master' into add-DR-test
xiaojingchen May 23, 2019
b960eb7
address comment
xiaojingchen May 24, 2019
cb8bf30
address comment
xiaojingchen May 24, 2019
438b57d
address comment
xiaojingchen May 24, 2019
3b943c7
address comment
xiaojingchen May 24, 2019
619a9d3
Merge branch 'master' into add-DR-test
xiaojingchen May 24, 2019
56c23b4
remove charts from stability image
xiaojingchen May 24, 2019
1fdea7c
Merge branch 'master' into add-DR-test
xiaojingchen May 27, 2019
a8ec562
Merge branch 'master' into add-DR-test
xiaojingchen May 27, 2019
4432e87
Merge branch 'master' into add-DR-test
xiaojingchen May 27, 2019
741d3b0
Merge branch 'add-DR-test' of https://github.com/xiaojingchen/tidb-op…
xiaojingchen May 27, 2019
4bfb345
Merge branch 'master' into add-DR-test
xiaojingchen May 27, 2019
5d42e70
Merge branch 'master' into add-DR-test
xiaojingchen May 28, 2019
ab7e57d
Merge branch 'master' into add-DR-test
xiaojingchen May 28, 2019
b6cf442
fix e2e.yaml
xiaojingchen May 28, 2019
35d5c78
fix bug
xiaojingchen May 28, 2019
c8eaf91
remove initSql
xiaojingchen May 28, 2019
7d198a5
Merge branch 'master' into add-DR-test
xiaojingchen May 29, 2019
1558c31
change image name
xiaojingchen May 29, 2019
fe782e7
Merge branch 'add-DR-test' of https://github.com/xiaojingchen/tidb-op…
xiaojingchen May 29, 2019
106e8e5
Merge branch 'master' into add-DR-test
xiaojingchen May 29, 2019
1d82ff6
Merge branch 'add-DR-test' of https://github.com/xiaojingchen/tidb-op…
xiaojingchen May 29, 2019
7e1e470
Merge branch 'master' into add-DR-test
xiaojingchen May 30, 2019
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
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ require (
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e // indirect
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273 // indirect
github.com/renstrom/dedent v1.1.0 // indirect
github.com/robfig/cron v1.1.0 // indirect
github.com/robfig/cron v1.1.0
github.com/russross/blackfriday v1.5.2+incompatible // indirect
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/sirupsen/logrus v1.0.6
Expand All @@ -87,6 +87,7 @@ require (
github.com/uber/jaeger-lib v2.0.0+incompatible // indirect
github.com/ugorji/go v1.1.1 // indirect
github.com/unrolled/render v0.0.0-20180807193321-4206df6ff701 // indirect
github.com/urfave/negroni v1.0.0 // indirect
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 // indirect
go.uber.org/atomic v1.3.2 // indirect
go.uber.org/multierr v1.1.0 // indirect
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ github.com/ugorji/go v1.1.1 h1:gmervu+jDMvXTbcHQ0pd2wee85nEoE0BsVyEuzkfK8w=
github.com/ugorji/go v1.1.1/go.mod h1:hnLbHMwcvSihnDhEfx2/BzKp2xb0Y+ErdfYcrs9tkJQ=
github.com/unrolled/render v0.0.0-20180807193321-4206df6ff701 h1:BJ/T25enw0WcbWqV132hGXRQdqCqe9XBzqh4AWVH7Bc=
github.com/unrolled/render v0.0.0-20180807193321-4206df6ff701/go.mod h1:tu82oB5W2ykJRVioYsB+IQKcft7ryBr7w12qMBUPyXg=
github.com/urfave/negroni v1.0.0/go.mod h1:Meg73S6kFm/4PpbYdq35yYWoCZ9mS/YSx+lKnmiohz4=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs=
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
Expand Down
59 changes: 40 additions & 19 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@ type OperatorActions interface {
EmitEvent(info *TidbClusterConfig, msg string)
BackupRestore(from, to *TidbClusterConfig) error
BackupRestoreOrDie(from, to *TidbClusterConfig)
LabelNodes() error
LabelNodesOrDie()
CheckDisasterTolerance(info *TidbClusterConfig) error
CheckDisasterToleranceOrDie(info *TidbClusterConfig)
CheckDataRegionDisasterTolerance(info *TidbClusterConfig) error
CheckDataRegionDisasterToleranceOrDie(info *TidbClusterConfig)
GetTidbMemberAssignedNodes(info *TidbClusterConfig) (map[string]string, error)
GetTidbMemberAssignedNodesOrDie(info *TidbClusterConfig) map[string]string
CheckTidbMemberAssignedNodes(info *TidbClusterConfig, oldAssignedNodes map[string]string) error
Expand Down Expand Up @@ -219,7 +225,6 @@ type TidbClusterConfig struct {
TiDBImage string
StorageClassName string
Password string
InitSQL string
RecordCount string
InsertBatchSize string
Resources map[string]string
Expand All @@ -242,6 +247,7 @@ type TidbClusterConfig struct {

BlockWriteConfig blockwriter.Config
GrafanaClient *metrics.Client
SubValues string
}

func (oi *OperatorConfig) ConfigTLS() *tls.Config {
Expand Down Expand Up @@ -292,7 +298,6 @@ func (tc *TidbClusterConfig) TidbClusterHelmSetString(m map[string]string) strin
"tikv.image": tc.TiKVImage,
"tidb.image": tc.TiDBImage,
"tidb.passwordSecretName": tc.InitSecretName,
"tidb.initSql": tc.InitSQL,
"monitor.create": strconv.FormatBool(tc.Monitor),
"enableConfigMapRollout": strconv.FormatBool(tc.EnableConfigMapRollout),
"pd.preStartScript": tc.PDPreStartScript,
Expand Down Expand Up @@ -456,6 +461,7 @@ func (oa *operatorActions) UpgradeOperator(info *OperatorConfig) error {
--set operatorImage=%s`,
info.ReleaseName, oa.operatorChartPath(info.Tag),
info.Image)

res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
if err != nil {
return fmt.Errorf("failed to upgrade operator to: %s, %v, %s", info.Image, err, string(res))
Expand Down Expand Up @@ -484,7 +490,22 @@ func (oa *operatorActions) DeployTidbCluster(info *TidbClusterConfig) error {

cmd := fmt.Sprintf("helm install %s --name %s --namespace %s --set-string %s",
oa.tidbClusterChartPath(info.OperatorTag), info.ClusterName, info.Namespace, info.TidbClusterHelmSetString(nil))
glog.Infof(cmd)
if strings.TrimSpace(info.SubValues) != "" {
subVaulesPath := fmt.Sprintf("%s/%s.yaml", oa.tidbClusterChartPath(info.OperatorTag), info.ClusterName)
svFile, err := os.Create(subVaulesPath)
if err != nil {
return err
}
defer svFile.Close()
_, err = svFile.WriteString(info.SubValues)
if err != nil {
return err
}

cmd = fmt.Sprintf(" %s --values %s", cmd, subVaulesPath)
}
glog.Info(cmd)

if res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput(); err != nil {
return fmt.Errorf("failed to deploy tidbcluster: %s/%s, %v, %s",
info.Namespace, info.ClusterName, err, string(res))
Expand Down Expand Up @@ -762,8 +783,7 @@ func (oa *operatorActions) ScaleTidbCluster(info *TidbClusterConfig) error {
oa.EmitEvent(info, fmt.Sprintf("ScaleTidbCluster to pd: %s, tikv: %s, tidb: %s",
info.Args["pd.replicas"], info.Args["tikv.replicas"], info.Args["tidb.replicas"]))

cmd := fmt.Sprintf("helm upgrade %s %s --set-string %s",
info.ClusterName, oa.tidbClusterChartPath(info.OperatorTag), info.TidbClusterHelmSetString(nil))
cmd := oa.getHelmUpgradeClusterCmd(info, nil)
glog.Info("[SCALE] " + cmd)
res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -868,8 +888,7 @@ func (oa *operatorActions) UpgradeTidbCluster(info *TidbClusterConfig) error {
return pingcapErrors.Wrapf(err, "failed to add annotation to [%s/%s]", info.Namespace, info.ClusterName)
}

cmd := fmt.Sprintf("helm upgrade %s %s --set-string %s",
info.ClusterName, oa.tidbClusterChartPath(info.OperatorTag), info.TidbClusterHelmSetString(nil))
cmd := oa.getHelmUpgradeClusterCmd(info, nil)
glog.Info("[UPGRADE] " + cmd)
res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -1875,10 +1894,7 @@ func (oa *operatorActions) DeployScheduledBackup(info *TidbClusterConfig) error
"scheduledBackup.secretName": info.BackupSecretName,
}

setString := info.TidbClusterHelmSetString(sets)

cmd := fmt.Sprintf("helm upgrade %s %s --set-string %s",
info.ClusterName, oa.tidbClusterChartPath(info.OperatorTag), setString)
cmd := oa.getHelmUpgradeClusterCmd(info, sets)

glog.Infof("scheduled-backup delploy [%s]", cmd)
res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
Expand All @@ -1896,10 +1912,7 @@ func (oa *operatorActions) disableScheduledBackup(info *TidbClusterConfig) error
"scheduledBackup.create": "false",
}

setString := info.TidbClusterHelmSetString(sets)

cmd := fmt.Sprintf("helm upgrade %s %s --set-string %s",
info.ClusterName, oa.tidbClusterChartPath(info.OperatorTag), setString)
cmd := oa.getHelmUpgradeClusterCmd(info, sets)

res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -2096,10 +2109,7 @@ func (oa *operatorActions) DeployIncrementalBackup(from *TidbClusterConfig, to *
"binlog.drainer.ignoreSchemas": "",
}

setString := from.TidbClusterHelmSetString(sets)

cmd := fmt.Sprintf("helm upgrade %s %s --set-string %s",
from.ClusterName, oa.tidbClusterChartPath(from.OperatorTag), setString)
cmd := oa.getHelmUpgradeClusterCmd(from, sets)
glog.Infof(cmd)
res, err := exec.Command("/bin/sh", "-c", cmd).CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -2410,3 +2420,14 @@ func (oa *operatorActions) EventWorker() {
ce.events = retryEvents
}
}

func (oa *operatorActions) getHelmUpgradeClusterCmd(info *TidbClusterConfig, set map[string]string) string {
cmd := fmt.Sprintf("helm upgrade %s %s --set-string %s",
info.ClusterName, oa.tidbClusterChartPath(info.OperatorTag), info.TidbClusterHelmSetString(set))
if strings.TrimSpace(info.SubValues) != "" {
subVaulesPath := fmt.Sprintf("%s/%s.yaml", oa.tidbClusterChartPath(info.OperatorTag), info.ClusterName)
cmd = fmt.Sprintf(" %s --values %s", cmd, subVaulesPath)
}

return cmd
}
19 changes: 17 additions & 2 deletions tests/cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ package main

import (
"fmt"
"k8s.io/api/core/v1"
_ "net/http/pprof"
"time"

"k8s.io/api/core/v1"

"github.com/golang/glog"
"github.com/jinzhu/copier"
"github.com/pingcap/tidb-operator/tests"
Expand All @@ -32,7 +33,6 @@ func main() {
defer logs.FlushLogs()

conf := tests.ParseConfigOrDie()
conf.ChartDir = "/charts"
conf.ManifestDir = "/manifests"

cli, kubeCli := client.NewCliOrDie()
Expand Down Expand Up @@ -103,6 +103,7 @@ func main() {
BatchSize: 1,
RawSize: 1,
},
SubValues: tests.GetAffinityConfigOrDie(name1, name1),
EnableConfigMapRollout: true,
PDMaxReplicas: 3,
TiKVGrpcConcurrency: 4,
Expand Down Expand Up @@ -145,6 +146,7 @@ func main() {
BatchSize: 1,
RawSize: 1,
},
SubValues: tests.GetAffinityConfigOrDie(name2, name2),
EnableConfigMapRollout: false,
PDMaxReplicas: 3,
TiKVGrpcConcurrency: 4,
Expand All @@ -167,13 +169,16 @@ func main() {
"pd.replicas": "1",
"discovery.image": conf.OperatorImage,
},
SubValues: tests.GetAffinityConfigOrDie(name3, name2),
},
}

defer func() {
oa.DumpAllLogs(operatorInfo, clusterInfos)
}()

oa.LabelNodesOrDie()

// deploy operator
if err := oa.CleanOperator(operatorInfo); err != nil {
oa.DumpAllLogs(operatorInfo, nil)
Expand All @@ -200,6 +205,11 @@ func main() {
}
}

// check disaster tolerance
for _, clusterInfo := range clusterInfos {
oa.CheckDisasterToleranceOrDie(clusterInfo)
}

for _, clusterInfo := range clusterInfos {
go oa.BeginInsertDataToOrDie(clusterInfo)
}
Expand Down Expand Up @@ -300,6 +310,11 @@ func main() {
}
}

// check data regions disaster tolerance
for _, clusterInfo := range clusterInfos {
oa.CheckDataRegionDisasterToleranceOrDie(clusterInfo)
}

// backup and restore
backupClusterInfo := clusterInfos[0]
restoreClusterInfo := &tests.TidbClusterConfig{}
Expand Down
19 changes: 18 additions & 1 deletion tests/cmd/stability/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ package main

import (
"fmt"
"k8s.io/api/core/v1"
"net/http"
_ "net/http/pprof"
"strconv"
"time"

"k8s.io/api/core/v1"

"github.com/golang/glog"
"github.com/jinzhu/copier"
"github.com/pingcap/tidb-operator/tests"
Expand Down Expand Up @@ -104,6 +105,8 @@ func main() {
PDLogLevel: "info",
EnableConfigMapRollout: true,
}
cluster1.SubValues = tests.GetAffinityConfigOrDie(cluster1.ClusterName, cluster1.Namespace)

cluster2 := &tests.TidbClusterConfig{
Namespace: clusterName2,
ClusterName: clusterName2,
Expand Down Expand Up @@ -143,6 +146,7 @@ func main() {
PDLogLevel: "info",
EnableConfigMapRollout: false,
}
cluster2.SubValues = tests.GetAffinityConfigOrDie(cluster2.ClusterName, cluster2.Namespace)

// cluster backup and restore
clusterBackupFrom := cluster1
Expand Down Expand Up @@ -173,6 +177,8 @@ func main() {
})
go c.Start()

oa.LabelNodesOrDie()

fn := func() {
run(oa, fta, conf, operatorCfg, allClusters, cluster1, cluster2,
onePDCluster, upgardeTiDBVersions, clusterRestoreTo, clusterBackupFrom)
Expand Down Expand Up @@ -212,6 +218,10 @@ func run(oa tests.OperatorActions,

oa.CleanTidbClusterOrDie(onePDCluster)

// check disaster tolerance
oa.CheckDisasterToleranceOrDie(cluster1)
oa.CheckDisasterToleranceOrDie(cluster2)

go oa.BeginInsertDataToOrDie(cluster1)
go oa.BeginInsertDataToOrDie(cluster2)
defer oa.StopInsertDataTo(cluster1)
Expand Down Expand Up @@ -280,6 +290,13 @@ func run(oa tests.OperatorActions,
oa.UpgradeTidbClusterOrDie(cluster2)
oa.CheckTidbClusterStatusOrDie(cluster2)

// after upgrade cluster, clean webhook
oa.CleanWebHookAndService(operatorCfg)

// check data regions disaster tolerance
oa.CheckDataRegionDisasterToleranceOrDie(cluster1)
oa.CheckDataRegionDisasterToleranceOrDie(cluster2)

// deploy and check cluster restore
oa.DeployTidbClusterOrDie(clusterRestoreTo)
oa.CheckTidbClusterStatusOrDie(clusterRestoreTo)
Expand Down
11 changes: 7 additions & 4 deletions tests/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func NewConfig() (*Config, error) {
flag.StringVar(&cfg.OperatorTag, "operator-tag", "master", "operator tag used to choose charts")
flag.StringVar(&cfg.OperatorImage, "operator-image", "pingcap/tidb-operator:latest", "operator image")
flag.StringVar(&cfg.OperatorRepoDir, "operator-repo-dir", "/tidb-operator", "local directory to which tidb-operator cloned")
flag.StringVar(&cfg.ChartDir, "chart-dir", "", "chart dir")
flag.StringVar(&slack.WebhookURL, "slack-webhook-url", "", "slack webhook url")
flag.Parse()

Expand All @@ -91,11 +92,13 @@ func NewConfig() (*Config, error) {
}
cfg.OperatorRepoDir = operatorRepo

chartDir, err := ioutil.TempDir("", "charts")
if err != nil {
return nil, err
if strings.TrimSpace(cfg.ChartDir) == "" {
chartDir, err := ioutil.TempDir("", "charts")
if err != nil {
return nil, err
}
cfg.ChartDir = chartDir
}
cfg.ChartDir = chartDir

manifestDir, err := ioutil.TempDir("", "manifests")
if err != nil {
Expand Down
Loading