-
Notifications
You must be signed in to change notification settings - Fork 22
/
create.go
82 lines (68 loc) · 1.89 KB
/
create.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
package tccpnatgateways
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/giantswarm/microerror"
"github.com/giantswarm/aws-operator/v14/service/controller/controllercontext"
"github.com/giantswarm/aws-operator/v14/service/controller/key"
)
func (r *Resource) EnsureCreated(ctx context.Context, obj interface{}) error {
cr, err := r.toClusterFunc(ctx, obj)
if IsNotFound(err) {
r.logger.Debugf(ctx, "cluster cr not available yet")
r.logger.Debugf(ctx, "canceling resource")
return nil
} else if err != nil {
return microerror.Mask(err)
}
cc, err := controllercontext.FromContext(ctx)
if err != nil {
return microerror.Mask(err)
}
var natgateways []*ec2.NatGateway
{
r.logger.Debugf(ctx, "finding natgateways")
i := &ec2.DescribeNatGatewaysInput{
Filter: []*ec2.Filter{
{
Name: aws.String(fmt.Sprintf("tag:%s", key.TagCluster)),
Values: []*string{
aws.String(key.ClusterID(&cr)),
},
},
{
Name: aws.String(fmt.Sprintf("tag:%s", key.TagStack)),
Values: []*string{
aws.String(key.StackTCCP),
},
},
// ignore NAT gateway in state 'deleting' or 'deleted'
{
Name: aws.String("state"),
Values: []*string{
aws.String("available"),
aws.String("pending"),
},
},
},
}
o, err := cc.Client.TenantCluster.AWS.EC2.DescribeNatGateways(i)
if err != nil {
return microerror.Mask(err)
}
natgateways = o.NatGateways
r.logger.Debugf(ctx, "found natgateways")
}
{
if len(natgateways) < 1 {
r.logger.Debugf(ctx, "did not find natgateways for tenant cluster %#q", key.ClusterID(&cr))
r.logger.Debugf(ctx, "canceling resource")
return nil
}
r.logger.Debugf(ctx, "found %d natgateways for tenant cluster %#q", len(natgateways), key.ClusterID(&cr))
cc.Status.TenantCluster.TCCP.NATGateways = natgateways
}
return nil
}