-
Notifications
You must be signed in to change notification settings - Fork 500
/
config.go
129 lines (117 loc) · 5.3 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// Copyright 2019 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// See the License for the specific language governing permissions and
// limitations under the License.
package config
import (
"flag"
"fmt"
"io/ioutil"
"time"
"github.com/pingcap/tidb-operator/tests"
"github.com/pingcap/tidb-operator/tests/e2e/util"
v1 "k8s.io/api/core/v1"
"k8s.io/client-go/tools/clientcmd"
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
cliflag "k8s.io/component-base/cli/flag"
framework "github.com/pingcap/tidb-operator/tests/third_party/k8s"
)
// Global Test configuration.
var TestConfig *tests.Config = tests.NewDefaultConfig()
// RegisterTiDBOperatorFlags registers flags for tidb-operator.
func RegisterTiDBOperatorFlags(flags *flag.FlagSet) {
flags.StringVar(&TestConfig.LogDir, "log-dir", "/logDir", "log directory")
flags.IntVar(&TestConfig.FaultTriggerPort, "fault-trigger-port", 23332, "the http port of fault trigger service")
flags.StringVar(&TestConfig.E2EImage, "e2e-image", "", "e2e image")
flags.BoolVar(&TestConfig.InstallOperator, "install-operator", true, "install a default operator")
flags.BoolVar(&TestConfig.InstallDMMysql, "install-dm-mysql", true, "install mysql and tidb for dm test")
flags.StringVar(&TestConfig.OperatorTag, "operator-tag", "master", "operator tag used to choose charts")
flags.StringVar(&TestConfig.OperatorImage, "operator-image", "pingcap/tidb-operator:latest", "operator image")
flags.Var(cliflag.NewMapStringBool(&TestConfig.OperatorFeatures), "operator-features", "a set of key=value pairs that describe feature gates for operator")
flags.StringVar(&TestConfig.UpgradeOperatorTag, "upgrade-operator-tag", "", "upgrade operator tag used to choose charts")
flags.StringVar(&TestConfig.UpgradeOperatorImage, "upgrade-operator-image", "", "upgrade operator image")
flags.StringVar(&TestConfig.OperatorRepoDir, "operator-repo-dir", "/tidb-operator", "local directory to which tidb-operator cloned")
flags.StringVar(&TestConfig.OperatorRepoUrl, "operator-repo-url", "https://github.com/pingcap/tidb-operator.git", "tidb-operator repo url used")
flags.StringVar(&TestConfig.ChartDir, "chart-dir", "", "chart dir")
flags.BoolVar(&TestConfig.PreloadImages, "preload-images", false, "if set, preload images in the bootstrap of e2e process")
flags.StringVar(&TestConfig.BackupImage, "backup-image", "", "backup image")
flags.BoolVar(&TestConfig.OperatorKiller.Enabled, "operator-killer", false, "whether to enable operator kill")
flags.DurationVar(&TestConfig.OperatorKiller.Interval, "operator-killer-interval", 5*time.Minute, "interval between operator kills")
flags.Float64Var(&TestConfig.OperatorKiller.JitterFactor, "operator-killer-jitter-factor", 1, "factor used to jitter operator kills")
}
func AfterReadingAllFlags() error {
if TestConfig.OperatorRepoDir == "" {
operatorRepo, err := ioutil.TempDir("", "tidb-operator")
if err != nil {
return err
}
TestConfig.OperatorRepoDir = operatorRepo
}
if TestConfig.ChartDir == "" {
chartDir, err := ioutil.TempDir("", "charts")
if err != nil {
return err
}
TestConfig.ChartDir = chartDir
}
if TestConfig.ManifestDir == "" {
manifestDir, err := ioutil.TempDir("", "manifests")
if err != nil {
return err
}
TestConfig.ManifestDir = manifestDir
}
return nil
}
// NewDefaultOperatorConfig creates default operator configuration.
func NewDefaultOperatorConfig(cfg *tests.Config) *tests.OperatorConfig {
features := []string{}
for k, v := range cfg.OperatorFeatures {
t := "false"
if v {
t = "true"
}
features = append(features, fmt.Sprintf("%s=%s", k, t))
}
return &tests.OperatorConfig{
Namespace: "pingcap",
ReleaseName: "operator",
Image: cfg.OperatorImage,
Tag: cfg.OperatorTag,
ControllerManagerReplicas: util.IntPtr(2),
SchedulerImage: "registry.k8s.io/kube-scheduler",
SchedulerReplicas: util.IntPtr(2),
Features: features,
LogLevel: "4",
WebhookServiceName: "webhook-service",
WebhookSecretName: "webhook-secret",
WebhookConfigName: "webhook-config",
ImagePullPolicy: v1.PullIfNotPresent,
TestMode: true,
WebhookEnabled: true,
StsWebhookEnabled: true,
Cabundle: "",
BackupImage: cfg.BackupImage,
StringValues: map[string]string{
"admissionWebhook.failurePolicy.validation": "Fail",
"admissionWebhook.failurePolicy.mutation": "Fail",
},
}
}
func LoadClientRawConfig() (clientcmdapi.Config, error) {
loadingRules := clientcmd.NewDefaultClientConfigLoadingRules()
loadingRules.ExplicitPath = framework.TestContext.KubeConfig
overrides := &clientcmd.ConfigOverrides{ClusterDefaults: clientcmd.ClusterDefaults}
if framework.TestContext.KubeContext != "" {
overrides.CurrentContext = framework.TestContext.KubeContext
}
return clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, overrides).RawConfig()
}