-
Notifications
You must be signed in to change notification settings - Fork 22
/
resource.go
85 lines (66 loc) · 1.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
package natgatewayaddresses
import (
"context"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
infrastructurev1alpha2 "github.com/giantswarm/apiextensions/pkg/apis/infrastructure/v1alpha2"
"github.com/giantswarm/microerror"
"github.com/giantswarm/micrologger"
"github.com/giantswarm/aws-operator/service/controller/controllercontext"
)
const (
Name = "natgatewayaddresses"
)
type Config struct {
Logger micrologger.Logger
Installation string
}
type Resource struct {
logger micrologger.Logger
installation string
}
// New returns a resource to get all EIPs tagged with the control plane
// installation tag. Each EIP is associated with a control plane NAT gateway
// which are used to compute the tenant cluster's security group rules.
func New(config Config) (*Resource, error) {
if config.Logger == nil {
return nil, microerror.Maskf(invalidConfigError, "%T.Logger must not be empty", config)
}
if config.Installation == "" {
return nil, microerror.Maskf(invalidConfigError, "%T.Installation must not be empty", config)
}
r := &Resource{
logger: config.Logger,
installation: config.Installation,
}
return r, nil
}
func (r *Resource) Name() string {
return Name
}
func (r *Resource) addNATGatewayAddressesToContext(ctx context.Context, cr infrastructurev1alpha2.AWSCluster) error {
cc, err := controllercontext.FromContext(ctx)
if err != nil {
return microerror.Mask(err)
}
var natGatewayAddresses []*ec2.Address
{
i := &ec2.DescribeAddressesInput{
Filters: []*ec2.Filter{
{
Name: aws.String("tag:giantswarm.io/installation"),
Values: []*string{
aws.String(r.installation),
},
},
},
}
o, err := cc.Client.ControlPlane.AWS.EC2.DescribeAddresses(i)
if err != nil {
return microerror.Mask(err)
}
natGatewayAddresses = o.Addresses
}
cc.Status.ControlPlane.NATGateway.Addresses = natGatewayAddresses
return nil
}