Skip to content

Commit

Permalink
add option for aws role-arn (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
pgier authored Aug 5, 2023
1 parent 4925935 commit 7ad3570
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions cmd/kcloud/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ type AWSCmd struct {
Cluster []string `arg:"" optional:"" name:"region/cluster"`
} `arg:"" name:"region/cluster"`
} `arg:""`
AllRegions bool `short:"a" help:"Search all knows AWS regions instead of just regions found in ~/.aws/config"`
AllRegions bool `short:"a" help:"Search all knows AWS regions instead of just regions found in ~/.aws/config"`
RoleARN string `short:"r" help:"Include a role arn when updating kube config"`
}

func (aws *AWSCmd) Run(ctx *kong.Context) error {
Expand All @@ -35,10 +36,14 @@ func (aws *AWSCmd) Run(ctx *kong.Context) error {
return err
}
if _, ok := awsKnownRegions[region]; !ok {
fmt.Printf("WARNING: unrecognized region %v\n", region)
fmt.Printf("warning: unrecognized region argument '%s'\n", region)
}
return RunCommandAndPrint(awsCmd, "--profile", aws.Profile.Profile, "eks", "--region", region,
"update-kubeconfig", "--name", cluster)
args := []string{"--profile", aws.Profile.Profile, "eks", "--region", region,
"update-kubeconfig", "--name", cluster}
if strings.TrimSpace(aws.RoleARN) != "" {
args = append(args, "--role-arn", strings.TrimSpace(aws.RoleARN))
}
return RunCommandAndPrint(awsCmd, args...)

}

Expand Down Expand Up @@ -120,10 +125,11 @@ func (aws *AWSCmd) AWSListClusters() error {
}

func awsListClustersInRegion(profile string, region string) ([]string, error) {
output, err := RunCommand(awsCmd, "--profile", profile, "eks", "--region", region, "list-clusters")
args := []string{"--profile", profile, "eks", "--region", region, "list-clusters"}
output, err := RunCommand(awsCmd, args...)
if err != nil {
return nil, fmt.Errorf("failed command: %s\n output: %s\n err: %w",
QuoteCommand(awsCmd, "--profile", profile, "eks", "--region", region, "list-clusters"),
QuoteCommand(awsCmd, args...),
strings.TrimSpace(string(output)),
err,
)
Expand Down

0 comments on commit 7ad3570

Please sign in to comment.