/
add-on-config-maps.go
83 lines (73 loc) · 2.7 KB
/
add-on-config-maps.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
package eksconfig
import (
"errors"
"fmt"
"time"
)
// AddOnConfigMaps defines parameters for EKS cluster
// add-on "ConfigMap".
type AddOnConfigMaps 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"`
// CreateTook is the duration that took to create the resource.
CreateTook time.Duration `json:"create-took,omitempty" read-only:"true"`
// CreateTookString is the duration that took to create the resource.
CreateTookString string `json:"create-took-string,omitempty" read-only:"true"`
// DeleteTook is the duration that took to create the resource.
DeleteTook time.Duration `json:"delete-took,omitempty" read-only:"true"`
// DeleteTookString is the duration that took to create the resource.
DeleteTookString string `json:"delete-took-string,omitempty" read-only:"true"`
// Namespace is the namespace to create objects in.
Namespace string `json:"namespace"`
// Objects is the number of "ConfigMap" objects to create.
Objects int `json:"objects"`
// Size is the "ConfigMap" value size in bytes.
Size int `json:"size"`
// CreatedNames is the list of created "ConfigMap" object names.
CreatedNames []string `json:"created-names" read-only:"true"`
// FailThreshold is the number of write failures to allow.
FailThreshold int `json:"fail-threshold"`
}
// EnvironmentVariablePrefixAddOnConfigMaps is the environment variable prefix used for "eksconfig".
const EnvironmentVariablePrefixAddOnConfigMaps = AWS_K8S_TESTER_EKS_PREFIX + "ADD_ON_CONFIG_MAPS_"
// IsEnabledAddOnConfigMaps returns true if "AddOnConfigMaps" is enabled.
// Otherwise, nil the field for "omitempty".
func (cfg *Config) IsEnabledAddOnConfigMaps() bool {
if cfg.AddOnConfigMaps == nil {
return false
}
if cfg.AddOnConfigMaps.Enable {
return true
}
cfg.AddOnConfigMaps = nil
return false
}
func getDefaultAddOnConfigMaps() *AddOnConfigMaps {
return &AddOnConfigMaps{
Enable: false,
Objects: 10,
Size: 10 * 1024, // 10 KB
FailThreshold: 10,
// writes total 300 MB data to etcd
// Objects: 1000,
// Size: 300000, // 0.3 MB
}
}
func (cfg *Config) validateAddOnConfigMaps() error {
if !cfg.IsEnabledAddOnConfigMaps() {
return nil
}
if !cfg.IsEnabledAddOnNodeGroups() && !cfg.IsEnabledAddOnManagedNodeGroups() {
return errors.New("AddOnConfigMaps.Enable true but no node group is enabled")
}
if cfg.AddOnConfigMaps.Namespace == "" {
cfg.AddOnConfigMaps.Namespace = cfg.Name + "-configmaps"
}
if cfg.AddOnConfigMaps.Size > 900000 {
return fmt.Errorf("AddOnConfigMaps.Size limit is 0.9 MB, got %d", cfg.AddOnConfigMaps.Size)
}
return nil
}