forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 1
/
context.go
107 lines (94 loc) · 2.42 KB
/
context.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
package cluster
import (
"path/filepath"
"strings"
"time"
"github.com/spf13/viper"
)
// ContextType is the root config struct
type ContextType struct {
ClusterLoader struct {
Cleanup bool
Projects []ClusterLoaderType
TuningSets []TuningSetType
}
}
// ClusterLoaderType struct only used for Cluster Loader test config
type ClusterLoaderType struct {
Number int `mapstructure:"num"`
Basename string
Tuning string
Pods []ClusterLoaderObjectType
Templates []ClusterLoaderObjectType
}
// ClusterLoaderObjectType is nested object type for cluster loader struct
type ClusterLoaderObjectType struct {
Total int
Number int `mapstructure:"num"`
Image string
Basename string
File string
Parameters ParameterConfigType
}
// ParameterConfigType contains config parameters for each object
type ParameterConfigType struct {
Run string `mapstructure:"run"`
RouterIP string `mapstructure:"router_ip"`
TargetHost string `mapstructure:"target_host"`
DurationSec int `mapstructure:"duration"`
Megabytes int
}
// TuningSetType is nested type for controlling Cluster Loader deployment pattern
type TuningSetType struct {
Name string
Pods TuningSetObjectType
Templates TuningSetObjectType
}
// TuningSetObjectType is shared struct for Pods & Templates
type TuningSetObjectType struct {
Stepping struct {
StepSize int
Pause time.Duration
Timeout time.Duration
}
RateLimit struct {
Delay time.Duration
}
}
// ConfigContext variable of type ContextType
var ConfigContext ContextType
// PodCount struct keeps HTTP requst counts and state
type PodCount struct {
Started int
Stopped int
Shutdown chan bool
}
// ServiceInfo struct to bundle env data
type ServiceInfo struct {
Name string
IP string
Port int32
}
// TestResult struct contains result data to be saved at end of run
type TestResult struct {
Time time.Duration `json:"time"`
}
// ParseConfig will complete flag parsing as well as viper tasks
func ParseConfig(config string, isFixture bool) error {
// This must be done after common flags are registered, since Viper is a flag option.
if isFixture {
dir, file := filepath.Split(config)
s := strings.Split(file, ".")
viper.SetConfigName(s[0])
viper.AddConfigPath(dir)
} else {
viper.SetConfigName(config)
viper.AddConfigPath(".")
}
err := viper.ReadInConfig()
if err != nil {
return err
}
viper.Unmarshal(&ConfigContext)
return nil
}