@@ -35,13 +35,15 @@ func newCmdGetAccountClaim(streams genericclioptions.IOStreams, flags *genericcl
3535 getAccountClaimCmd .Flags ().StringVarP (& ops .output , "output" , "o" , "" , "Output format. One of: json|yaml|jsonpath=...|jsonpath-file=... see jsonpath template [http://kubernetes.io/docs/user-guide/jsonpath]." )
3636 getAccountClaimCmd .Flags ().StringVar (& ops .accountNamespace , "account-namespace" , common .AWSAccountNamespace ,
3737 "The namespace to keep AWS accounts. The default value is aws-account-operator." )
38+ getAccountClaimCmd .Flags ().StringVarP (& ops .accountName , "account" , "a" , "" , "Account CR Name" )
3839 getAccountClaimCmd .Flags ().StringVarP (& ops .accountID , "account-id" , "i" , "" , "AWS account ID" )
3940
4041 return getAccountClaimCmd
4142}
4243
4344// getAccountClaimOptions defines the struct for running get account-claim command
4445type getAccountClaimOptions struct {
46+ accountName string
4547 accountID string
4648 accountNamespace string
4749
@@ -62,8 +64,11 @@ func newGetAccountClaimOptions(streams genericclioptions.IOStreams, flags *gener
6264}
6365
6466func (o * getAccountClaimOptions ) complete (cmd * cobra.Command , _ []string ) error {
65- if o .accountID == "" {
66- return cmdutil .UsageErrorf (cmd , accountIDRequired )
67+ if o .accountID == "" && o .accountName == "" {
68+ return cmdutil .UsageErrorf (cmd , "AWS account ID and Account CR Name cannot be empty at the same time" )
69+ }
70+ if o .accountID != "" && o .accountName != "" {
71+ return cmdutil .UsageErrorf (cmd , "AWS account ID and Account CR Name cannot be set at the same time" )
6772 }
6873
6974 var err error
@@ -85,20 +90,25 @@ func (o *getAccountClaimOptions) run() error {
8590 accountClaimName string
8691 accountClaim awsv1alpha1.AccountClaim
8792 )
88- if err := o .kubeCli .List (ctx , & accounts , & client.ListOptions {
89- Namespace : o .accountNamespace ,
90- }); err != nil {
91- return nil
92- }
9393
94- for _ , a := range accounts .Items {
95- if a .Spec .AwsAccountID == o .accountID {
96- accountCRName = a .Name
97- break
94+ if o .accountName != "" {
95+ accountCRName = o .accountName
96+ } else {
97+ if err := o .kubeCli .List (ctx , & accounts , & client.ListOptions {
98+ Namespace : o .accountNamespace ,
99+ }); err != nil {
100+ return nil
101+ }
102+
103+ for _ , a := range accounts .Items {
104+ if a .Spec .AwsAccountID == o .accountID {
105+ accountCRName = a .Name
106+ break
107+ }
108+ }
109+ if accountCRName == "" {
110+ return fmt .Errorf ("Account matched for AWS Account ID %s not found\n " , o .accountID )
98111 }
99- }
100- if accountCRName == "" {
101- return fmt .Errorf ("Account matched for AWS Account ID %s not found\n " , o .accountID )
102112 }
103113
104114 if err := o .kubeCli .List (ctx , & accountClaims ); err != nil {
0 commit comments