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 13 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: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ tests/images/fault-trigger/bin/
tests/images/e2e/tidb-cluster/
tests/images/e2e/tidb-backup/
tests/images/e2e/tidb-operator/
tests/images/stability-test/tidb-cluster/
tests/images/stability-test/tidb-backup/
tests/images/stability-test/tidb-operator/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use a local file for stability testing, please join the manifests folder, just like e2e tests。
tests/images/stability-test/manifests

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are of no use and it will be removed after #499 merged

tests/images/e2e/manifests/
*.tar
tmp/
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ stability-test-build:
$(GO) -ldflags '$(LDFLAGS)' -o tests/images/stability-test/bin/stability-test tests/cmd/stability/*.go

stability-test-docker: stability-test-build
[ -d tests/images/stability-test/tidb-operator ] && rm -r tests/images/stability-test/tidb-operator || true
[ -d tests/images/stability-test/tidb-cluster ] && rm -r tests/images/stability-test/tidb-cluster || true
[ -d tests/images/stability-test/tidb-backup ] && rm -r tests/images/stability-test/tidb-backup || true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto
[ -d tests/images/stability-test/manifests ] && rm -r tests/images/stability-test/manifests || true

cp -r charts/tidb-operator tests/images/stability-test
cp -r charts/tidb-cluster tests/images/stability-test
cp -r charts/tidb-backup tests/images/stability-test
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto
cp -r manifests tests/images/stability-test

docker build -t "${DOCKER_REGISTRY}/pingcap/tidb-operator-stability-test:latest" tests/images/stability-test

stability-test-push: stability-test-docker
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,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 @@ -204,6 +204,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
58 changes: 40 additions & 18 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,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)
CheckTidbMemberAssignedNodes(info *TidbClusterConfig, oldAssignedNodes map[string]string) error
}
Expand Down Expand Up @@ -233,6 +239,7 @@ type TidbClusterConfig struct {

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

func (oi *OperatorConfig) ConfigTLS() *tls.Config {
Expand Down Expand Up @@ -327,6 +334,7 @@ func (oi *OperatorConfig) OperatorHelmSetString(m map[string]string) string {
"scheduler.logLevel": "2",
"controllerManager.replicas": "2",
"scheduler.replicas": "2",
"imagePullPolicy": "Always",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No need to set it to Always

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change the image of scheduler either?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, so it's cannot be Always

}
if oi.SchedulerTag != "" {
set["scheduler.kubeSchedulerImageTag"] = oi.SchedulerTag
Expand All @@ -345,7 +353,7 @@ func (oi *OperatorConfig) OperatorHelmSetString(m map[string]string) string {
func (oa *operatorActions) DeployOperator(info *OperatorConfig) error {
glog.Infof("deploying tidb-operator %s", info.ReleaseName)

if info.Tag != "e2e" {
if info.Tag != "e2e" && info.Tag != "stability" {
xiaojingchen marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If both e2e test and stabililty test do not follow this process, can we delete this logic branch ?

Copy link
Contributor Author

@xiaojingchen xiaojingchen May 24, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can not, this is just to support the branch which still in developer's fork repo, other branches still need to download.

if err := oa.cloneOperatorRepo(); err != nil {
return err
}
Expand Down Expand Up @@ -443,6 +451,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 @@ -471,7 +480,20 @@ 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)
}
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 @@ -734,8 +756,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 @@ -840,8 +861,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 @@ -1847,10 +1867,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 @@ -1868,10 +1885,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 @@ -2068,10 +2082,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 @@ -2379,3 +2390,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
}
93 changes: 92 additions & 1 deletion tests/cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,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 +102,46 @@ func main() {
BatchSize: 1,
RawSize: 1,
},
SubValues: `pd:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For better readability, can we move this string literal to a private const value?

affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: e2e-cluster1
app.kubernetes.io/component: "pd"
topologyKey: "rack"
namespaces:
- e2e-cluster1
tikv:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: e2e-cluster1
app.kubernetes.io/component: "tikv"
topologyKey: "rack"
namespaces:
- e2e-cluster1
tidb:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: e2e-cluster1
app.kubernetes.io/component: "tidb"
topologyKey: "rack"
namespaces:
- e2e-cluster1
`,
EnableConfigMapRollout: true,
PDMaxReplicas: 3,
TiKVGrpcConcurrency: 4,
Expand Down Expand Up @@ -146,6 +185,46 @@ func main() {
BatchSize: 1,
RawSize: 1,
},
SubValues: `pd:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So does this

affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: e2e-cluster2
app.kubernetes.io/component: "pd"
topologyKey: "rack"
namespaces:
- e2e-cluster2
tikv:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: e2e-cluster2
app.kubernetes.io/component: "tikv"
topologyKey: "rack"
namespaces:
- e2e-cluster2
tidb:
affinity:
podAntiAffinity:
preferredDuringSchedulingIgnoredDuringExecution:
- weight: 10
podAffinityTerm:
labelSelector:
matchLabels:
app.kubernetes.io/instance: e2e-cluster2
app.kubernetes.io/component: "tidb"
topologyKey: "rack"
namespaces:
- e2e-cluster2
`,
EnableConfigMapRollout: false,
PDMaxReplicas: 3,
TiKVGrpcConcurrency: 4,
Expand All @@ -158,6 +237,8 @@ func main() {
oa.DumpAllLogs(operatorInfo, clusterInfos)
}()

oa.LabelNodesOrDie()

// deploy operator
if err := oa.CleanOperator(operatorInfo); err != nil {
oa.DumpAllLogs(operatorInfo, nil)
Expand All @@ -184,6 +265,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 @@ -284,6 +370,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
Loading