generated from kyma-project/template-repository
-
Notifications
You must be signed in to change notification settings - Fork 13
/
findCloudResourceSubnets.go
35 lines (29 loc) · 1.11 KB
/
findCloudResourceSubnets.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
package iprange
import (
"context"
ec2Types "github.com/aws/aws-sdk-go-v2/service/ec2/types"
"github.com/elliotchance/pie/v2"
cloudcontrolv1beta1 "github.com/kyma-project/cloud-manager/api/cloud-control/v1beta1"
"github.com/kyma-project/cloud-manager/pkg/composed"
"github.com/kyma-project/cloud-manager/pkg/kcp/provider/aws/util"
"k8s.io/utils/pointer"
)
func findCloudResourceSubnets(ctx context.Context, st composed.State) (error, context.Context) {
state := st.(*State)
var cloudResourcesSubnets []ec2Types.Subnet
for _, sub := range state.allSubnets {
val := util.GetEc2TagValue(sub.Tags, tagKey)
if len(val) > 0 {
cloudResourcesSubnets = append(cloudResourcesSubnets, sub)
}
}
state.cloudResourceSubnets = cloudResourcesSubnets
state.ObjAsIpRange().Status.Subnets = pie.Map(cloudResourcesSubnets, func(subnet ec2Types.Subnet) cloudcontrolv1beta1.IpRangeSubnet {
return cloudcontrolv1beta1.IpRangeSubnet{
Id: pointer.StringDeref(subnet.SubnetId, ""),
Zone: pointer.StringDeref(subnet.AvailabilityZone, ""),
Range: pointer.StringDeref(subnet.CidrBlock, ""),
}
})
return nil, nil
}