-
Notifications
You must be signed in to change notification settings - Fork 22
/
resource.go
121 lines (106 loc) · 3.89 KB
/
resource.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
package tccp
import (
"github.com/giantswarm/k8sclient/v7/pkg/k8sclient"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/giantswarm/aws-operator/v14/service/internal/changedetection"
"github.com/giantswarm/aws-operator/v14/service/internal/cloudtags"
"github.com/giantswarm/aws-operator/v14/service/internal/hamaster"
event "github.com/giantswarm/aws-operator/v14/service/internal/recorder"
ctrlClient "sigs.k8s.io/controller-runtime/pkg/client"
)
const (
// Name is the identifier of the resource.
Name = "tccp"
)
const (
// namedIAMCapability is the AWS specific capability necessary to work with
// our Cloud Formation templates. It is required for creating worker policy
// IAM roles.
namedIAMCapability = "CAPABILITY_NAMED_IAM"
)
// Config represents the configuration used to create a new cloudformation
// resource.
type Config struct {
CloudTags cloudtags.Interface
Event event.Interface
CtrlClient ctrlClient.Client
HAMaster hamaster.Interface
K8sClient k8sclient.Interface
Logger micrologger.Logger
APIWhitelist ConfigAPIWhitelist
CIDRBlockAWSCNI string
Detection *changedetection.TCCP
InstallationName string
InstanceMonitoring bool
PublicRouteTables string
Route53Enabled bool
}
// Resource implements the cloudformation resource.
type Resource struct {
cloudtags cloudtags.Interface
event event.Interface
ctrlClient ctrlClient.Client
haMaster hamaster.Interface
k8sClient k8sclient.Interface
logger micrologger.Logger
apiWhitelist ConfigAPIWhitelist
cidrBlockAWSCNI string
detection *changedetection.TCCP
installationName string
instanceMonitoring bool
publicRouteTables string
route53Enabled bool
}
// New creates a new configured cloudformation resource.
func New(config Config) (*Resource, error) {
if config.CloudTags == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.CloudTags must not be empty", config)
}
if config.Detection == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Detection must not be empty", config)
}
if config.Event == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Event must not be empty", config)
}
if config.CtrlClient == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.CtrlClient must not be empty", config)
}
if config.HAMaster == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.HAMaster must not be empty", config)
}
if config.K8sClient == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.K8sClient must not be empty", config)
}
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
if config.APIWhitelist.Private.Enabled && len(config.APIWhitelist.Private.SubnetList) == 0 {
return nil, microerror.Maskf(invalidConfigError, "%T.APIWhitelist.Private.SubnetList must not be empty when %T.APIWhitelist.Private is enabled", config, config)
}
if config.APIWhitelist.Public.Enabled && len(config.APIWhitelist.Public.SubnetList) == 0 {
return nil, microerror.Maskf(invalidConfigError, "%T.APIWhitelist.Public.SubnetList must not be empty when %T.APIWhitelist.Public is enabled", config, config)
}
if config.CIDRBlockAWSCNI == "" {
return nil, microerror.Maskf(invalidConfigError, "%T.CIDRBlockAWSCNI must not be empty", config)
}
r := &Resource{
cloudtags: config.CloudTags,
event: config.Event,
ctrlClient: config.CtrlClient,
haMaster: config.HAMaster,
detection: config.Detection,
k8sClient: config.K8sClient,
logger: config.Logger,
apiWhitelist: config.APIWhitelist,
cidrBlockAWSCNI: config.CIDRBlockAWSCNI,
installationName: config.InstallationName,
instanceMonitoring: config.InstanceMonitoring,
publicRouteTables: config.PublicRouteTables,
route53Enabled: config.Route53Enabled,
}
return r, nil
}
func (r *Resource) Name() string {
return Name
}