/
main.go
240 lines (199 loc) · 8.7 KB
/
main.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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
// k8s-tester-clusterloader installs Kubernetes clusterloader tester.
package main
import (
"fmt"
"os"
"time"
"github.com/aws/aws-k8s-tester/client"
"github.com/aws/aws-k8s-tester/k8s-tester/clusterloader"
"github.com/aws/aws-k8s-tester/utils/log"
"github.com/spf13/cobra"
"go.uber.org/zap"
)
var rootCmd = &cobra.Command{
Use: "k8s-tester-clusterloader",
Short: "Kubernetes clusterloader tester",
SuggestFor: []string{"clusterloader"},
}
func init() {
cobra.EnablePrefixMatching = true
}
var (
prompt bool
logLevel string
logOutputs []string
minimumNodes int
kubectlDownloadURL string
kubectlPath string
kubeconfigPath string
)
func init() {
rootCmd.PersistentFlags().BoolVar(&prompt, "prompt", true, "'true' to enable prompt mode")
rootCmd.PersistentFlags().StringVar(&logLevel, "log-level", log.DefaultLogLevel, "Logging level")
rootCmd.PersistentFlags().StringSliceVar(&logOutputs, "log-outputs", []string{"stderr"}, "Additional logger outputs")
rootCmd.PersistentFlags().IntVar(&minimumNodes, "minimum-nodes", clusterloader.DefaultMinimumNodes, "minimum number of Kubernetes nodes required for installing this addon")
rootCmd.PersistentFlags().StringVar(&kubectlDownloadURL, "kubectl-download-url", client.DefaultKubectlDownloadURL(), "kubectl download URL")
rootCmd.PersistentFlags().StringVar(&kubectlPath, "kubectl-path", client.DefaultKubectlPath(), "kubectl path")
rootCmd.PersistentFlags().StringVar(&kubeconfigPath, "kubeconfig-path", "", "KUBECONFIG path")
rootCmd.AddCommand(
newApply(),
newDelete(),
)
}
func main() {
if err := rootCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "k8s-tester-clusterloader failed %v\n", err)
os.Exit(1)
}
os.Exit(0)
}
var (
clusterloaderPath string
clusterloaderDownloadURL string
provider string
runs int
runTimeout time.Duration
testConfigPath string
runFromCluster bool
nodes int
enableExecService bool
nodesPerNamespace int
podsPerNode int
bigGroupSize int
mediumGroupSize int
smallGroupSize int
smallStatefulSetsPerNamespace int
mediumStatefulSetsPerNamespace int
cl2UseHostNetworkPods bool
cl2LoadTestThroughput int
cl2EnablePVS bool
cl2SchedulerThroughputThreshold int
prometheusScrapeKubeProxy bool
enableSystemPodMetrics bool
)
func newApply() *cobra.Command {
cmd := &cobra.Command{
Use: "apply",
Short: "Apply tests",
Run: createApplyFunc,
}
cmd.PersistentFlags().StringVar(&clusterloaderPath, "clusterloader-path", clusterloader.DefaultClusterloaderPath(), "clusterloader path")
cmd.PersistentFlags().StringVar(&clusterloaderDownloadURL, "clusterloader-download-url", clusterloader.DefaultClusterloaderDownloadURL(), "clusterloader download URL")
cmd.PersistentFlags().StringVar(&provider, "provider", clusterloader.DefaultProvider, "clusterloader provider")
cmd.PersistentFlags().IntVar(&runs, "runs", clusterloader.DefaultRuns, "clusterloader runs")
cmd.PersistentFlags().DurationVar(&runTimeout, "run-timeout", clusterloader.DefaultRunTimeout, "clusterloader run timeout")
cmd.PersistentFlags().StringVar(&testConfigPath, "test-config-path", "", "clusterloader test config path")
cmd.PersistentFlags().BoolVar(&runFromCluster, "run-from-cluster", clusterloader.DefaultRunFromCluster, "to run clusterloader2 in cluster")
cmd.PersistentFlags().IntVar(&nodes, "nodes", clusterloader.DefaultNodes, "clusterloader nodes")
cmd.PersistentFlags().BoolVar(&enableExecService, "enable-exec-service", clusterloader.DefaultEnableExecService, "clusterloader enable exec service")
cmd.PersistentFlags().IntVar(&nodesPerNamespace, "nodes-per-namespace", clusterloader.DefaultNodesPerNamespace, "clusterloader nodes per namespace")
cmd.PersistentFlags().IntVar(&podsPerNode, "pods-per-node", clusterloader.DefaultPodsPerNode, "clusterloader pods per node")
cmd.PersistentFlags().IntVar(&bigGroupSize, "big-group-size", clusterloader.DefaultBigGroupSize, "clusterloader big group size")
cmd.PersistentFlags().IntVar(&mediumGroupSize, "medium-group-size", clusterloader.DefaultMediumGroupSize, "clusterloader medium group size")
cmd.PersistentFlags().IntVar(&smallGroupSize, "small-group-size", clusterloader.DefaultSmallGroupSize, "clusterloader small group size")
cmd.PersistentFlags().IntVar(&smallStatefulSetsPerNamespace, "small-stateful-sets-per-namespace", clusterloader.DefaultSmallStatefulSetsPerNamespace, "clusterloader small stateful sets per namespace")
cmd.PersistentFlags().IntVar(&mediumStatefulSetsPerNamespace, "medium-stateful-sets-per-namespace", clusterloader.DefaultMediumStatefulSetsPerNamespace, "clusterloader medium stateful sets per namespace")
cmd.PersistentFlags().BoolVar(&cl2UseHostNetworkPods, "cl2-use-host-network-pods", clusterloader.DefaultCL2UseHostNetworkPods, "clusterloader CL2 use host network pods")
cmd.PersistentFlags().IntVar(&cl2LoadTestThroughput, "cl2-load-test-throughput", clusterloader.DefaultCL2LoadTestThroughput, "clusterloader CL2 load test throughput")
cmd.PersistentFlags().BoolVar(&cl2EnablePVS, "cl2-enable-pvs", clusterloader.DefaultCL2UseHostNetworkPods, "clusterloader CL2 use host network pods")
cmd.PersistentFlags().IntVar(&cl2SchedulerThroughputThreshold, "cl2-scheduler-throughput-threshold", clusterloader.DefaultCL2SchedulerThroughputThreshold, "clusterloader CL2 scheduler throughput threshold")
cmd.PersistentFlags().BoolVar(&prometheusScrapeKubeProxy, "prometheus-scrape-kube-proxy", clusterloader.DefaultPrometheusScrapeKubeProxy, "clusterloader prometheus scrape kube-proxy")
cmd.PersistentFlags().BoolVar(&enableSystemPodMetrics, "enable-system-pod-metrics", clusterloader.DefaultEnableSystemPodMetrics, "clusterloader enable system pod metrics")
return cmd
}
func createApplyFunc(cmd *cobra.Command, args []string) {
lg, logWriter, _, err := log.NewWithStderrWriter(logLevel, logOutputs)
if err != nil {
panic(err)
}
_ = zap.ReplaceGlobals(lg)
cli, err := client.New(&client.Config{
Logger: lg,
KubectlDownloadURL: kubectlDownloadURL,
KubectlPath: kubectlPath,
KubeconfigPath: kubeconfigPath,
})
if err != nil {
lg.Panic("failed to create client", zap.Error(err))
}
cfg := &clusterloader.Config{
Prompt: prompt,
Logger: lg,
LogWriter: logWriter,
MinimumNodes: minimumNodes,
Client: cli,
ClusterloaderPath: clusterloaderPath,
ClusterloaderDownloadURL: clusterloaderDownloadURL,
Provider: provider,
Runs: runs,
RunTimeout: runTimeout,
TestConfigPath: testConfigPath,
RunFromCluster: runFromCluster,
Nodes: nodes,
EnableExecService: enableExecService,
TestOverride: &clusterloader.TestOverride{
Path: clusterloader.DefaultTestOverridePath(),
NodesPerNamespace: nodesPerNamespace,
PodsPerNode: podsPerNode,
BigGroupSize: bigGroupSize,
MediumGroupSize: mediumGroupSize,
SmallGroupSize: smallGroupSize,
SmallStatefulSetsPerNamespace: smallStatefulSetsPerNamespace,
MediumStatefulSetsPerNamespace: mediumStatefulSetsPerNamespace,
CL2UseHostNetworkPods: cl2UseHostNetworkPods,
CL2LoadTestThroughput: cl2LoadTestThroughput,
CL2EnablePVS: cl2EnablePVS,
CL2SchedulerThroughputThreshold: cl2SchedulerThroughputThreshold,
PrometheusScrapeKubeProxy: prometheusScrapeKubeProxy,
EnableSystemPodMetrics: enableSystemPodMetrics,
},
}
if err := cfg.ValidateAndSetDefaults(); err != nil {
fmt.Fprintf(os.Stderr, "failed to validate (%v)\n", err)
os.Exit(1)
}
ts := clusterloader.New(cfg)
if err := ts.Apply(); err != nil {
fmt.Fprintf(os.Stderr, "failed to apply (%v)\n", err)
os.Exit(1)
}
fmt.Printf("\n*********************************\n")
fmt.Printf("'k8s-tester-clusterloader apply' success\n")
}
func newDelete() *cobra.Command {
cmd := &cobra.Command{
Use: "delete",
Short: "Delete resources",
Run: createDeleteFunc,
}
return cmd
}
func createDeleteFunc(cmd *cobra.Command, args []string) {
lg, logWriter, _, err := log.NewWithStderrWriter(logLevel, logOutputs)
if err != nil {
panic(err)
}
_ = zap.ReplaceGlobals(lg)
cli, err := client.New(&client.Config{
Logger: lg,
KubectlDownloadURL: kubectlDownloadURL,
KubectlPath: kubectlPath,
KubeconfigPath: kubeconfigPath,
})
if err != nil {
lg.Panic("failed to create client", zap.Error(err))
}
cfg := &clusterloader.Config{
Prompt: prompt,
Logger: lg,
LogWriter: logWriter,
Client: cli,
}
ts := clusterloader.New(cfg)
if err := ts.Delete(); err != nil {
fmt.Fprintf(os.Stderr, "failed to delete (%v)\n", err)
os.Exit(1)
}
fmt.Printf("\n*********************************\n")
fmt.Printf("'k8s-tester-clusterloader delete' success\n")
}