generated from kyma-project/template-repository
/
loadMountTargets.go
54 lines (46 loc) · 1.54 KB
/
loadMountTargets.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
package nfsinstance
import (
"context"
"fmt"
efsTypes "github.com/aws/aws-sdk-go-v2/service/efs/types"
"github.com/elliotchance/pie/v2"
"github.com/kyma-project/cloud-manager/pkg/composed"
"k8s.io/utils/pointer"
)
func loadMountTargets(ctx context.Context, st composed.State) (error, context.Context) {
logger := composed.LoggerFromCtx(ctx)
state := st.(*State)
if state.efs == nil {
return nil, nil
}
mtList, err := state.awsClient.DescribeMountTargets(ctx, pointer.StringDeref(state.efs.FileSystemId, ""))
if err != nil {
return composed.LogErrorAndReturn(err, "Error loading mount targets", composed.StopWithRequeue, ctx)
}
state.mountTargets = mtList
state.mountTargetSecurityGroups = make(map[string][]string, len(mtList))
for _, mt := range mtList {
mtID := pointer.StringDeref(mt.MountTargetId, "")
sgList, err := state.awsClient.DescribeMountTargetSecurityGroups(ctx, mtID)
if err != nil {
return composed.LogErrorAndReturn(err, "Error loading mount target security groups", composed.StopWithRequeue, ctx)
}
state.mountTargetSecurityGroups[mtID] = sgList
}
logger.
WithValues(
"mountTargets",
fmt.Sprintf("%v", pie.Map(mtList, func(mt efsTypes.MountTargetDescription) string {
mtID := pointer.StringDeref(mt.MountTargetId, "")
return fmt.Sprintf(
"{id:%s, az:%s, ip: %s, sg: %v}",
mtID,
pointer.StringDeref(mt.AvailabilityZoneId, ""),
pointer.StringDeref(mt.IpAddress, ""),
state.mountTargetSecurityGroups[mtID],
)
})),
).
Info("Mount targets loaded")
return nil, nil
}