/
get.go
71 lines (54 loc) · 1.59 KB
/
get.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
package fargate_profile
import (
"os"
"github.com/awslabs/eksdemo/pkg/aws"
"github.com/awslabs/eksdemo/pkg/printer"
"github.com/awslabs/eksdemo/pkg/resource"
"github.com/aws/aws-sdk-go-v2/service/eks/types"
)
type Getter struct {
eksClient *aws.EKSClient
}
func NewGetter(eksClient *aws.EKSClient) *Getter {
return &Getter{eksClient}
}
func (g *Getter) Init() {
if g.eksClient == nil {
g.eksClient = aws.NewEKSClient()
}
}
func (g *Getter) Get(name string, output printer.Output, options resource.Options) error {
var profile *types.FargateProfile
var profiles []*types.FargateProfile
var err error
clusterName := options.Common().ClusterName
if name != "" {
profile, err = g.GetProfileByName(name, clusterName)
profiles = []*types.FargateProfile{profile}
} else {
profiles, err = g.GetAllProfiles(clusterName)
}
if err != nil {
return err
}
return output.Print(os.Stdout, NewPrinter(profiles))
}
func (g *Getter) GetAllProfiles(clusterName string) ([]*types.FargateProfile, error) {
profileNames, err := g.eksClient.ListFargateProfiles(clusterName)
profiles := make([]*types.FargateProfile, 0, len(profileNames))
if err != nil {
return nil, err
}
for _, name := range profileNames {
result, err := g.eksClient.DescribeFargateProfile(clusterName, name)
if err != nil {
return nil, err
}
profiles = append(profiles, result)
}
return profiles, nil
}
func (g *Getter) GetProfileByName(name, clusterName string) (*types.FargateProfile, error) {
profile, err := g.eksClient.DescribeFargateProfile(clusterName, name)
return profile, aws.FormatErrorAsMessageOnly(err)
}