Skip to content

Commit 3c359ae

Browse files
committed
Add an option to specify the EKS cluster name
1 parent d2e85fc commit 3c359ae

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

cmd/managed-kubernetes-auditing-toolkit/eks/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"github.com/spf13/cobra"
1010
)
1111

12-
var ignoreEksHostnameCheck bool
12+
var skipEksHostnameCheck bool
1313

1414
func BuildEksSubcommand() *cobra.Command {
1515
eksCommand := &cobra.Command{
@@ -18,7 +18,7 @@ func BuildEksSubcommand() *cobra.Command {
1818
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
1919
figure.NewFigure("mkat", "", true).Print()
2020
println()
21-
if !ignoreEksHostnameCheck && !utils.IsEKS() {
21+
if !skipEksHostnameCheck && !utils.IsEKS() {
2222
return errors.New("you do not seem to be connected to an EKS cluster. Connect to an EKS cluster and try again")
2323
}
2424
clusterName := utils.GetEKSClusterName()
@@ -29,7 +29,7 @@ func BuildEksSubcommand() *cobra.Command {
2929
},
3030
}
3131

32-
eksCommand.PersistentFlags().BoolVarP(&ignoreEksHostnameCheck, "skip-eks-hostname-check", "", false, "Don't check that the hostname of your current API server ends with .eks.amazonaws.com")
32+
eksCommand.PersistentFlags().BoolVarP(&skipEksHostnameCheck, "skip-eks-hostname-check", "", false, "Don't check that the hostname of your current API server ends with .eks.amazonaws.com")
3333
eksCommand.AddCommand(buildEksRoleRelationshipsCommand())
3434
eksCommand.AddCommand(buildEksFindSecretsCommand())
3535
eksCommand.AddCommand(buildTestImdsAccessCommand())

cmd/managed-kubernetes-auditing-toolkit/eks/role_relationships.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
// Command-line arguments
2222
var outputFormat string
2323
var outputFile string
24+
var eksClusterName string
2425

2526
// Output formats
2627
const (
@@ -48,6 +49,10 @@ func buildEksRoleRelationshipsCommand() *cobra.Command {
4849
},
4950
RunE: func(cmd *cobra.Command, args []string) error {
5051
cluster := utils.GetEKSClusterName()
52+
if cluster == "" {
53+
// If we cannot determine the EKS cluster name automatically, give the user a chance to specify it on the CLI
54+
cluster = eksClusterName
55+
}
5156
if cluster == "" {
5257
return errors.New("unable to determine your current EKS cluster name")
5358
}
@@ -57,6 +62,8 @@ func buildEksRoleRelationshipsCommand() *cobra.Command {
5762

5863
eksRoleRelationshipsCommand.Flags().StringVarP(&outputFormat, "output-format", "f", DefaultOutputFormat, "Output format. Supported formats: "+strings.Join(availableOutputFormats, ", "))
5964
eksRoleRelationshipsCommand.Flags().StringVarP(&outputFile, "output-file", "o", "", "Output file. If not specified, output will be printed to stdout.")
65+
eksRoleRelationshipsCommand.Flags().StringVarP(&eksClusterName, "eks-cluster-name", "", "", "When the EKS cluster name cannot be automatically detected from your KubeConfig, specify this argument to pass the EKS cluster name of your current kubectl context")
66+
6067
return eksRoleRelationshipsCommand
6168
}
6269

0 commit comments

Comments
 (0)