/
add-on-stresser-remote-v2.go
147 lines (128 loc) · 5.68 KB
/
add-on-stresser-remote-v2.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
package eksconfig
import (
"errors"
"time"
"github.com/aws/aws-k8s-tester/pkg/timeutil"
)
type AddOnStresserRemoteV2 struct {
// Enable is 'true' to create this add-on.
Enable bool `json:"enable"`
// Created is true when the resource has been created.
// Used for delete operations.
Created bool `json:"created" read-only:"true"`
TimeFrameCreate timeutil.TimeFrame `json:"time-frame-create" read-only:"true"`
TimeFrameDelete timeutil.TimeFrame `json:"time-frame-delete" read-only:"true"`
// Namespace is the namespace to create objects in.
Namespace string `json:"namespace"`
// RepositoryAccountID is the account ID for tester ECR image.
// e.g. "aws/aws-k8s-tester" for "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/aws/aws-k8s-tester"
RepositoryAccountID string `json:"repository-account-id,omitempty"`
// RepositoryRegion is the ECR repository region to pull from.
RepositoryRegion string `json:"repository-region,omitempty"`
// RepositoryName is the repositoryName for tester ECR image.
// e.g. "aws/aws-k8s-tester" for "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/aws/aws-k8s-tester"
RepositoryName string `json:"repository-name,omitempty"`
// RepositoryImageTag is the image tag for tester ECR image.
// e.g. "latest" for image URI "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/aws/aws-k8s-tester:latest"
RepositoryImageTag string `json:"repository-image-tag,omitempty"`
// RepositoryBusyBoxName is the repositoryName for busybox ECR image.
// e.g. "busybox" for image URI "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/aws/busybox:latest"
RepositoryBusyBoxName string `json:"repository-busybox-name,omitempty"`
// RepositoryBusyBoxImageTag is the image tag for busybox ECR image.
// e.g. "latest" for image URI "[ACCOUNT_ID].dkr.ecr.[REGION].amazonaws.com/aws/busybox:latest"
RepositoryBusyBoxImageTag string `json:"repository-busybox-image-tag,omitempty"`
// Schedule is the cron schedule (e.g. "*/5 * * * *").
Schedule string `json:"schedule"`
// Completes is the desired number of successfully finished pods.
Completes int `json:"completes"`
// Parallels is the the maximum desired number of pods the
// job should run at any given time.
Parallels int `json:"parallels"`
// SuccessfulJobsHistoryLimit is the number of successful finished
// jobs to retain. Defaults to 3.
SuccessfulJobsHistoryLimit int32 `json:"successful-jobs-history-limit"`
// FailedJobsHistoryLimit is the number of failed finished jobs
// to retain. Defaults to 1.
FailedJobsHistoryLimit int32 `json:"failed-jobs-history-limit"`
// ObjectSize is the value size in bytes for write objects.
// If 0, do not write anything.
ObjectSize int `json:"object-size"`
// Duration is the duration to run stress2 testing.
Duration time.Duration `json:"duration,omitempty"`
DurationString string `json:"duration-string,omitempty" read-only:"true"`
// Coroutines is the number of concurrent go routines run per job
Coroutines int `json:"coroutines"`
// Secrets is the number of secrets generated per job
Secrets int `json:"secrets"`
}
// EnvironmentVariablePrefixAddOnStresserRemoteV2 is the environment variable prefix used for "eksconfig".
const EnvironmentVariablePrefixAddOnStresserRemoteV2 = AWS_K8S_TESTER_EKS_PREFIX + "ADD_ON_STRESSER_REMOTE_V2_"
// IsEnabledAddOnStresserRemote returns true if "AddOnStresserRemote" is enabled.
// Otherwise, nil the field for "omitempty".
func (cfg *Config) IsEnabledAddOnStresserRemoteV2() bool {
if cfg.AddOnStresserRemoteV2 == nil {
return false
}
if cfg.AddOnStresserRemoteV2.Enable {
return true
}
cfg.AddOnStresserRemoteV2 = nil
return false
}
func getDefaultAddOnStresserRemoteV2() *AddOnStresserRemoteV2 {
return &AddOnStresserRemoteV2{
Enable: false,
Schedule: "0 */6 * * *", // every 6 hours align with etcd defrag interval
Completes: 10,
Parallels: 10,
SuccessfulJobsHistoryLimit: 3,
FailedJobsHistoryLimit: 1,
ObjectSize: 8, // 8 bytes
Duration: 10 * time.Minute,
Coroutines: 10,
Secrets: 10,
}
}
func (cfg *Config) GetAddOnStresserRemoteV2RepositoryRegion() string {
if !cfg.IsEnabledAddOnStresserRemoteV2() {
return cfg.Region
}
return cfg.AddOnStresserRemoteV2.RepositoryRegion
}
func (cfg *Config) validateAddOnStresserRemoteV2() error {
if !cfg.IsEnabledAddOnStresserRemoteV2() {
return nil
}
if cfg.AddOnStresserRemoteV2.Namespace == "" {
cfg.AddOnStresserRemoteV2.Namespace = cfg.Name + "-stresser-remote-v2"
}
if cfg.AddOnStresserRemoteV2.RepositoryAccountID == "" {
return errors.New("AddOnStresserRemoteV2.RepositoryAccountID empty")
}
if cfg.AddOnStresserRemoteV2.RepositoryRegion == "" {
cfg.AddOnStresserRemoteV2.RepositoryRegion = cfg.Region
}
if cfg.AddOnStresserRemoteV2.RepositoryName == "" {
return errors.New("AddOnStresserRemoteV2.RepositoryName empty")
}
if cfg.AddOnStresserRemoteV2.RepositoryImageTag == "" {
return errors.New("AddOnStresserRemoteV2.RepositoryImageTag empty")
}
if cfg.AddOnStresserRemoteV2.RepositoryBusyBoxName == "" {
return errors.New("AddOnStresserRemoteV2.RepositoryBusyBoxName empty")
}
if cfg.AddOnStresserRemoteV2.RepositoryBusyBoxImageTag == "" {
return errors.New("AddOnStresserRemoteV2.RepositoryBusyBoxImageTag empty")
}
if cfg.AddOnStresserRemoteV2.Duration == time.Duration(0) {
cfg.AddOnStresserRemoteV2.Duration = 10 * time.Minute
}
cfg.AddOnStresserRemoteV2.DurationString = cfg.AddOnStresserRemoteV2.Duration.String()
if cfg.AddOnStresserRemoteV2.Coroutines <= 0 {
cfg.AddOnStresserRemoteV2.Coroutines = 10
}
if cfg.AddOnStresserRemoteV2.Secrets >= 0 {
cfg.AddOnStresserRemoteV2.Secrets = 10
}
return nil
}