/
add-on-csrs-remote.go
151 lines (131 loc) · 6.17 KB
/
add-on-csrs-remote.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
package eksconfig
import (
"errors"
"fmt"
"strings"
"github.com/aws/aws-k8s-tester/pkg/metrics"
"github.com/aws/aws-k8s-tester/pkg/randutil"
"github.com/aws/aws-k8s-tester/pkg/timeutil"
)
// AddOnCSRsRemote defines parameters for EKS cluster
// add-on "CertificateSigningRequest" remote.
// It generates loads from the remote workers (Pod) in the cluster.
// Each worker writes serially with no concurrency.
// Configure "DeploymentReplicas" accordingly to increase the concurrency.
// The main use case is to write a large number of objects to fill up etcd database.
type AddOnCSRsRemote 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"`
// 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"`
// DeploymentReplicas is the number of replicas to create for workers.
// The total number of objects to be created is "DeploymentReplicas" * "Objects".
DeploymentReplicas int32 `json:"deployment-replicas,omitempty"`
// Objects is the number of "CertificateSigningRequest" objects to create.
Objects int `json:"objects"`
// InitialRequestConditionType is the initial CSR condition type
// to simulate CSR condition.
//
// Valid values are:
// "k8s.io/api/certificates/v1beta1.CertificateApproved" == "Approved"
// "k8s.io/api/certificates/v1beta1.CertificateDenied" == "Denied"
// "Random"
// "Pending"
// ""
//
InitialRequestConditionType string `json:"initial-request-condition-type"`
// RequestsWritesJSONPath is the file path to store writes requests in JSON format.
RequestsWritesJSONPath string `json:"requests-writes-json-path" read-only:"true"`
// RequestsWritesSummary is the writes results.
RequestsWritesSummary metrics.RequestsSummary `json:"requests-writes-summary,omitempty" read-only:"true"`
// RequestsWritesSummaryJSONPath is the file path to store writes requests summary in JSON format.
RequestsWritesSummaryJSONPath string `json:"requests-writes-summary-json-path" read-only:"true"`
// RequestsWritesSummaryTablePath is the file path to store writes requests summary in table format.
RequestsWritesSummaryTablePath string `json:"requests-writes-summary-table-path" read-only:"true"`
// RequestsWritesSummaryOutputNamePrefix is the output path name in "/var/log" directory, used in remote worker.
RequestsWritesSummaryOutputNamePrefix string `json:"requests-writes-summary-output-name-prefix"`
}
// EnvironmentVariablePrefixAddOnCSRsRemote is the environment variable prefix used for "eksconfig".
const EnvironmentVariablePrefixAddOnCSRsRemote = AWS_K8S_TESTER_EKS_PREFIX + "ADD_ON_CSRS_REMOTE_"
// IsEnabledAddOnCSRsRemote returns true if "AddOnCSRsRemote" is enabled.
// Otherwise, nil the field for "omitempty".
func (cfg *Config) IsEnabledAddOnCSRsRemote() bool {
if cfg.AddOnCSRsRemote == nil {
return false
}
if cfg.AddOnCSRsRemote.Enable {
return true
}
cfg.AddOnCSRsRemote = nil
return false
}
func getDefaultAddOnCSRsRemote() *AddOnCSRsRemote {
return &AddOnCSRsRemote{
Enable: false,
DeploymentReplicas: 5,
Objects: 10, // 1000 objects generates 5 MB data to etcd
InitialRequestConditionType: "",
RequestsWritesSummaryOutputNamePrefix: "csrs-writes" + randutil.String(10),
}
}
func (cfg *Config) validateAddOnCSRsRemote() error {
if !cfg.IsEnabledAddOnCSRsRemote() {
return nil
}
if !cfg.IsEnabledAddOnNodeGroups() && !cfg.IsEnabledAddOnManagedNodeGroups() {
return errors.New("AddOnCSRsRemote.Enable true but no node group is enabled")
}
if cfg.AddOnCSRsRemote.Namespace == "" {
cfg.AddOnCSRsRemote.Namespace = cfg.Name + "-csrs-remote"
}
if cfg.AddOnCSRsRemote.RepositoryAccountID == "" {
return errors.New("AddOnCSRsRemote.RepositoryAccountID empty")
}
if cfg.AddOnCSRsRemote.RepositoryName == "" {
return errors.New("AddOnCSRsRemote.RepositoryName empty")
}
if cfg.AddOnCSRsRemote.RepositoryImageTag == "" {
return errors.New("AddOnCSRsRemote.RepositoryImageTag empty")
}
if cfg.AddOnCSRsRemote.DeploymentReplicas == 0 {
cfg.AddOnCSRsRemote.DeploymentReplicas = 5
}
if cfg.AddOnCSRsRemote.Objects == 0 {
cfg.AddOnCSRsRemote.Objects = 10
}
switch cfg.AddOnCSRsRemote.InitialRequestConditionType {
case "Approved":
case "Denied":
case "Pending", "":
case "Random":
default:
return fmt.Errorf("unknown AddOnCSRsRemote.InitialRequestConditionType %q", cfg.AddOnCSRsRemote.InitialRequestConditionType)
}
if cfg.AddOnCSRsRemote.RequestsWritesJSONPath == "" {
cfg.AddOnCSRsRemote.RequestsWritesJSONPath = strings.ReplaceAll(cfg.ConfigPath, ".yaml", "") + "-csrs-remote-requests-writes.csv"
}
if cfg.AddOnCSRsRemote.RequestsWritesSummaryJSONPath == "" {
cfg.AddOnCSRsRemote.RequestsWritesSummaryJSONPath = strings.ReplaceAll(cfg.ConfigPath, ".yaml", "") + "-csrs-remote-requests-writes-summary.json"
}
if cfg.AddOnCSRsRemote.RequestsWritesSummaryTablePath == "" {
cfg.AddOnCSRsRemote.RequestsWritesSummaryTablePath = strings.ReplaceAll(cfg.ConfigPath, ".yaml", "") + "-csrs-remote-requests-writes-summary.txt"
}
if cfg.AddOnCSRsRemote.RequestsWritesSummaryOutputNamePrefix == "" {
cfg.AddOnCSRsRemote.RequestsWritesSummaryOutputNamePrefix = "csrs-writes" + randutil.String(10)
}
return nil
}