/
add-on-cw-agent.go
59 lines (51 loc) · 1.68 KB
/
add-on-cw-agent.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
package eksconfig
import (
"errors"
"github.com/aws/aws-k8s-tester/pkg/timeutil"
)
// AddOnCWAgent defines parameters for EKS cluster
// add-on CloudWatch agent.
// Publishes worker nodes logs to:
// - /aws/containerinsights/[CLUSTER-NAME]/performance
type AddOnCWAgent 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"`
}
// EnvironmentVariablePrefixAddOnCWAgent is the environment variable prefix used for "eksconfig".
const EnvironmentVariablePrefixAddOnCWAgent = AWS_K8S_TESTER_EKS_PREFIX + "ADD_ON_CW_AGENT_"
// IsEnabledAddOnCWAgent returns true if "AddOnCWAgent" is enabled.
// Otherwise, nil the field for "omitempty".
func (cfg *Config) IsEnabledAddOnCWAgent() bool {
if cfg.AddOnCWAgent == nil {
return false
}
if cfg.AddOnCWAgent.Enable {
return true
}
cfg.AddOnCWAgent = nil
return false
}
func getDefaultAddOnCWAgent() *AddOnCWAgent {
return &AddOnCWAgent{
Enable: false,
}
}
func (cfg *Config) validateAddOnCWAgent() error {
if !cfg.IsEnabledAddOnCWAgent() {
return nil
}
if !cfg.IsEnabledAddOnNodeGroups() && !cfg.IsEnabledAddOnManagedNodeGroups() {
return errors.New("AddOnCWAgent.Enable true but no node group is enabled")
}
if cfg.AddOnCWAgent.Namespace == "" {
cfg.AddOnCWAgent.Namespace = cfg.Name + "-cw-agent"
}
return nil
}