-
Notifications
You must be signed in to change notification settings - Fork 1.4k
/
pod_identity_association.go
95 lines (79 loc) · 3 KB
/
pod_identity_association.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
86
87
88
89
90
91
92
93
94
95
package get
import (
"context"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/weaveworks/eksctl/pkg/actions/podidentityassociation"
api "github.com/weaveworks/eksctl/pkg/apis/eksctl.io/v1alpha5"
"github.com/weaveworks/eksctl/pkg/ctl/cmdutils"
"github.com/weaveworks/eksctl/pkg/printers"
)
func getPodIdentityAssociationCmd(cmd *cmdutils.Cmd) {
cmd.ClusterConfig = api.NewClusterConfig()
params := &getCmdParams{}
cmd.SetDescription(
"podidentityassociation",
"Get a pod identity association",
"",
"podidentityassociations",
)
pia := &api.PodIdentityAssociation{}
configureGetPodIdentityAssociationCmd(cmd, params, pia)
cmd.CobraCommand.RunE = func(_ *cobra.Command, args []string) error {
if err := cmdutils.NewGetPodIdentityAssociationLoader(cmd, pia).Load(); err != nil {
return err
}
return doGetPodIdentityAssociation(cmd, pia.Namespace, pia.ServiceAccountName, params)
}
}
func doGetPodIdentityAssociation(cmd *cmdutils.Cmd, namespace, serviceAccountName string, params *getCmdParams) error {
cfg := cmd.ClusterConfig
ctx := context.Background()
ctl, err := cmd.NewProviderForExistingCluster(ctx)
if err != nil {
return err
}
if ok, err := ctl.CanOperate(cfg); !ok {
return err
}
summaries, err := podidentityassociation.NewGetter(cfg.Metadata.Name, ctl.AWSProvider.EKS()).
GetPodIdentityAssociations(ctx, namespace, serviceAccountName)
if err != nil {
return err
}
printer, err := printers.NewPrinter(params.output)
if err != nil {
return err
}
if params.output == printers.TableType {
addPodIdentityAssociationSummaryTableColumns(printer.(*printers.TablePrinter))
}
return printer.PrintObjWithKind("podidentityassociations", summaries, cmd.CobraCommand.OutOrStdout())
}
func configureGetPodIdentityAssociationCmd(cmd *cmdutils.Cmd, params *getCmdParams, pia *api.PodIdentityAssociation) {
cmd.FlagSetGroup.InFlagSet("PodIdentityAssociation", func(fs *pflag.FlagSet) {
fs.StringVar(&pia.Namespace, "namespace", "", "Namespace the service account belongs to")
fs.StringVar(&pia.ServiceAccountName, "service-account-name", "", "Name of the service account")
})
cmd.FlagSetGroup.InFlagSet("General", func(fs *pflag.FlagSet) {
cmdutils.AddClusterFlag(fs, cmd.ClusterConfig.Metadata)
cmdutils.AddRegionFlag(fs, &cmd.ProviderConfig)
cmdutils.AddConfigFileFlag(fs, &cmd.ClusterConfigFile)
cmdutils.AddCommonFlagsForGetCmd(fs, ¶ms.chunkSize, ¶ms.output)
cmdutils.AddTimeoutFlag(fs, &cmd.ProviderConfig.WaitTimeout)
})
}
func addPodIdentityAssociationSummaryTableColumns(printer *printers.TablePrinter) {
printer.AddColumn("ASSOCIATION ARN", func(s podidentityassociation.Summary) string {
return s.AssociationARN
})
printer.AddColumn("NAMESPACE", func(s podidentityassociation.Summary) string {
return s.Namespace
})
printer.AddColumn("SERVICE ACCOUNT NAME", func(s podidentityassociation.Summary) string {
return s.ServiceAccountName
})
printer.AddColumn("IAM ROLE ARN", func(s podidentityassociation.Summary) string {
return s.RoleARN
})
}