forked from onosproject/helmit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
runner.go
134 lines (121 loc) · 3.42 KB
/
runner.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
// Copyright 2019-present Open Networking Foundation.
//
// 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,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package benchmark
import (
"fmt"
"os"
"path"
jobs "github.com/wangxn2015/helmit/pkg/job"
)
// The executor is the entrypoint for benchmark images. It takes the input and environment and runs
// the image in the appropriate context according to the arguments.
// Run runs the benchmark
func Run(config *Config) error {
configValueFiles := make(map[string][]string)
if config.ValueFiles != nil {
for release, valueFiles := range config.ValueFiles {
configReleaseFiles := make([]string, 0)
for _, valueFile := range valueFiles {
configReleaseFiles = append(configReleaseFiles, path.Base(valueFile))
}
configValueFiles[release] = configReleaseFiles
}
}
configExecutable := ""
if config.Executable != "" {
configExecutable = path.Base(config.Executable)
}
configContext := ""
if config.Context != "" {
configContext = path.Base(config.Context)
}
job := &jobs.Job{
Config: config.Config,
JobConfig: &Config{
Config: &jobs.Config{
ID: config.ID,
Namespace: config.Namespace,
ServiceAccount: config.ServiceAccount,
Labels: config.Labels,
Annotations: config.Annotations,
Image: config.Image,
ImagePullPolicy: config.ImagePullPolicy,
Executable: configExecutable,
Context: configContext,
Values: config.Values,
ValueFiles: configValueFiles,
Args: config.Config.Args,
Env: config.Env,
Timeout: config.Timeout,
NoTeardown: config.NoTeardown,
Secrets: config.Config.Secrets,
},
Suite: config.Suite,
Benchmark: config.Benchmark,
Workers: config.Workers,
Parallelism: config.Parallelism,
Iterations: config.Iterations,
Duration: config.Duration,
Args: config.Args,
MaxLatency: config.MaxLatency,
NoTeardown: config.NoTeardown,
},
Type: benchmarkJobType,
}
return jobs.Run(job)
}
// Main runs a test
func Main() {
if err := run(); err != nil {
println("Benchmark failed " + err.Error())
os.Exit(1)
}
os.Exit(0)
}
// run runs a benchmark
func run() error {
config := &Config{}
if err := jobs.Bootstrap(config); err != nil {
return err
}
benchType := getBenchmarkType()
switch benchType {
case benchmarkTypeCoordinator:
return runCoordinator(config)
case benchmarkTypeWorker:
return runWorker(config)
}
return nil
}
// runCoordinator runs a test image in the coordinator context
func runCoordinator(config *Config) error {
coordinator, err := newCoordinator(config)
if err != nil {
return err
}
status, err := coordinator.Run()
if err != nil {
fmt.Println(err)
}
os.Exit(status)
return nil
}
// runWorker runs a test image in the worker context
func runWorker(config *Config) error {
worker, err := newWorker(config)
if err != nil {
return err
}
return worker.Run()
}