-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
addon.go
67 lines (57 loc) · 1.67 KB
/
addon.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
package v1alpha5
import (
"fmt"
"strings"
)
// Addon holds the EKS addon configuration
type Addon struct {
// +required
Name string `json:"name,omitempty"`
// +optional
Version string `json:"version,omitempty"`
// +optional
ServiceAccountRoleARN string `json:"serviceAccountRoleARN,omitempty"`
// list of ARNs of the IAM policies to attach
// +optional
AttachPolicyARNs []string `json:"attachPolicyARNs,omitempty"`
// AttachPolicy holds a policy document to attach
// +optional
AttachPolicy InlineDocument `json:"attachPolicy,omitempty"`
// ARN of the permissions boundary to associate
// +optional
PermissionsBoundary string `json:"permissionsBoundary,omitempty"`
// The metadata to apply to the cluster to assist with categorization and organization.
// Each tag consists of a key and an optional value, both of which you define.
// +optional
Tags map[string]string `json:"tags,omitempty"`
// Force applies the add-on to overwrite an existing add-on
Force bool `json:"-"`
}
func (a Addon) CanonicalName() string {
return strings.ToLower(a.Name)
}
func (a Addon) Validate() error {
if a.Name == "" {
return fmt.Errorf("name required")
}
if err := a.checkOnlyOnePolicyProviderIsSet(); err != nil {
return err
}
return nil
}
func (a Addon) checkOnlyOnePolicyProviderIsSet() error {
setPolicyProviders := 0
if a.AttachPolicy != nil {
setPolicyProviders++
}
if a.AttachPolicyARNs != nil && len(a.AttachPolicyARNs) > 0 {
setPolicyProviders++
}
if a.ServiceAccountRoleARN != "" {
setPolicyProviders++
}
if setPolicyProviders > 1 {
return fmt.Errorf("at most one of serviceAccountRoleARN, attachPolicyARNs and attachPolicy can be specified")
}
return nil
}