Skip to content

Commit

Permalink
add test mode
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaojingchen committed Jul 4, 2019
1 parent 8c6f549 commit e86fb93
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ spec:
- -tikv-failover-period={{ .Values.controllerManager.tikvFailoverPeriod | default "5m" }}
- -tidb-failover-period={{ .Values.controllerManager.tidbFailoverPeriod | default "5m" }}
- -v={{ .Values.controllerManager.logLevel }}
{{- if .Values.testMode }}
- -test-mode={{ .Values.testMode }}
{{- end}}
env:
- name: NAMESPACE
valueFrom:
Expand Down
1 change: 1 addition & 0 deletions cmd/controller-manager/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func init() {
flag.DurationVar(&pdFailoverPeriod, "pd-failover-period", time.Duration(5*time.Minute), "PD failover period default(5m)")
flag.DurationVar(&tikvFailoverPeriod, "tikv-failover-period", time.Duration(5*time.Minute), "TiKV failover period default(5m)")
flag.DurationVar(&tidbFailoverPeriod, "tidb-failover-period", time.Duration(5*time.Minute), "TiDB failover period")
flag.BoolVar(&controller.TestMode, "test-mode", false, "whether tidb-operator run in test mode")

flag.Parse()
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/controller/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ var (
DefaultStorageClassName string
// ClusterScoped controls whether operator should manage kubernetes cluster wide TiDB clusters
ClusterScoped bool
// TestMode defines whether tidb operator run in test mode, test mode is only open when test
TestMode bool
)

const (
Expand Down
4 changes: 4 additions & 0 deletions pkg/manager/member/tikv_upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,10 @@ func (tku *tikvUpgrader) beginEvictLeader(tc *v1alpha1.TidbCluster, storeID uint
}

func (tku *tikvUpgrader) endEvictLeader(tc *v1alpha1.TidbCluster, ordinal int32) error {
// wait 5 second before delete evict scheduler,it is for auto test can catch these info
if controller.TestMode {
time.Sleep(5 * time.Second)
}
store := tku.getStoreByOrdinal(tc, ordinal)
storeID, err := strconv.ParseUint(store.ID, 10, 64)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions tests/actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ type OperatorConfig struct {
WebhookConfigName string
Context *apimachinery.CertContext
ImagePullPolicy corev1.PullPolicy
TestMode bool
}

type TidbClusterConfig struct {
Expand Down Expand Up @@ -348,6 +349,7 @@ func (oi *OperatorConfig) OperatorHelmSetString(m map[string]string) string {
"controllerManager.replicas": "2",
"scheduler.replicas": "2",
"imagePullPolicy": string(oi.ImagePullPolicy),
"testMode": strconv.FormatBool(oi.TestMode),
}
if oi.SchedulerTag != "" {
set["scheduler.kubeSchedulerImageTag"] = oi.SchedulerTag
Expand Down Expand Up @@ -935,7 +937,7 @@ func (oa *operatorActions) CheckUpgrade(ctx context.Context, info *TidbClusterCo

replicas := tc.Spec.TiKV.Replicas
for i := replicas - 1; i > 0; i-- {
if err := wait.PollImmediate(5*time.Second, 10*time.Minute, func() (done bool, err error) {
if err := wait.PollImmediate(1*time.Second, 10*time.Minute, func() (done bool, err error) {
schedulers, err := pdClient.GetEvictLeaderSchedulers()
if err != nil {
glog.Errorf("failed to get evict leader schedulers, %v", err)
Expand All @@ -959,7 +961,7 @@ func (oa *operatorActions) CheckUpgrade(ctx context.Context, info *TidbClusterCo
return err
}
}
if err := wait.PollImmediate(5*time.Second, 6*time.Minute, func() (done bool, err error) {
if err := wait.PollImmediate(1*time.Second, 6*time.Minute, func() (done bool, err error) {
schedulers, err := pdClient.GetEvictLeaderSchedulers()
if err != nil {
glog.Errorf("failed to get evict leader schedulers, %v", err)
Expand Down
1 change: 1 addition & 0 deletions tests/cmd/e2e/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func main() {
WebhookSecretName: "webhook-secret",
WebhookConfigName: "webhook-config",
ImagePullPolicy: v1.PullIfNotPresent,
TestMode: true,
}

ns := os.Getenv("NAMESPACE")
Expand Down

0 comments on commit e86fb93

Please sign in to comment.