Skip to content

Commit

Permalink
Allowing default KUBECONFIG ordering
Browse files Browse the repository at this point in the history
This commit aims to make aware `eksctl` of the `KUBECONFIG` environment
variable, especially during cluster creation and kubeconfig retrieval
via the `eksctl utils write-kubeconfig` command.
To avoid conflicts and keep the actual convention, the variable
`DefaultPath` has been declared using a simple _func_ in order to don't
perform an invasive refactoring requested by a switch to function
declaration.
Actually, using the standard library to retrieve the environment
variable and not using the `viper` helper (although already a dependency)
since the `KUBECONFIG` one is considered as a global one, so totally
unbounded from `eksctl`.
Code coverage is going to decrease since during the test suite setup,
the environment variable is evaluated before the execution of tests: to
provide further coverage, the conversion from variable to function has
to be performed, although this requires some changes in the following
files and should be considered and approved by maintainers:
- pkg/ctl/cmdutils/cmdutils.go
- pkg/ctl/create/cluster.go
- pkg/ctl/utils/write_kubeconfig.go
- pkg/utils/kubeconfig/kubeconfig.go

Closes eksctl-io#228
  • Loading branch information
prometherion committed Jan 27, 2020
1 parent 9ca2e3b commit 508989a
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions pkg/utils/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,22 @@ import (
)

// DefaultPath defines the default path
var DefaultPath = clientcmd.RecommendedHomeFile
var DefaultPath = func(env string) string {
if len(env) > 0 {
return env
}
return clientcmd.RecommendedHomeFile
}(os.Getenv(RecommendedConfigPathEnvVar))

const (
// AWSIAMAuthenticator defines the name of the AWS IAM authenticator
AWSIAMAuthenticator = "aws-iam-authenticator"
// HeptioAuthenticatorAWS defines the old name of AWS IAM authenticator
HeptioAuthenticatorAWS = "heptio-authenticator-aws"
// AWSEKSAuthenticator defines the recently added `aws eks get-token` command
AWSEKSAuthenticator = "aws"
AWSEKSAuthenticator = "aws"
// Shadowing the default kubeconfig path environment variable
RecommendedConfigPathEnvVar = clientcmd.RecommendedConfigPathEnvVar
)

// AuthenticatorCommands returns all of authenticator commands
Expand Down

0 comments on commit 508989a

Please sign in to comment.