-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extend kubeconfig writer to support global path with merging #80
Conversation
04425e9
to
40eafbd
Compare
@richardcase so I couldn't stop wondering if So I looked at I also looked at |
I've reviewed the |
@errordeveloper - you are right We could refactor to use it directly or change our code to do something similar and call ModifyConfig. I'm happy to do either of these 2 if you want. |
As you pointed out the kops implementation use I wonder if we should refactor our implementation to use a similar approach to kops and take advantage of clientcmd.NewDefaultPathOptions, clientcmd.ModifyConfig and also clientcmd.GetStartingConfig. I also like that they do a delete of the cluster, context and authinfos. Our delete logic is a bit crude at the moment (i.e. only delete an autogenerated config). What do you think? |
So I've missed |
I will refactor based on the above against the |
As discussed I've updated our implementation to use I will raise an issue with kops to support |
@richardcase I'll test this tomorrow and merge |
@@ -23,7 +23,7 @@ func TestCreateNewKubeConfig(t *testing.T) { | |||
"test-context": {AuthInfo: "test-user", Cluster: "test-cluster", Namespace: "test-ns"}}, | |||
} | |||
|
|||
err := kubeconfig.WriteToFile(configFile.Name(), &testConfig, false) | |||
err := kubeconfig.WriteKubeCfg(configFile.Name(), &testConfig, false) |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
c721dd0
to
7639670
Compare
I've spotted a couple of issues, turns out |
@richardcase please take a look @jstrachan FYI |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me.
cmd/eksctl/create.go
Outdated
@@ -79,7 +79,7 @@ func createClusterCmd() *cobra.Command { | |||
|
|||
fs.BoolVar(&writeKubeconfig, "write-kubeconfig", true, "toggle writing of kubeconfig") | |||
fs.BoolVar(&autoKubeconfigPath, "auto-kubeconfig", false, fmt.Sprintf("save kubconfig file by cluster name, e.g. %q", kubeconfig.AutoPath(exampleClusterName))) | |||
fs.StringVar(&kubeconfigPath, "kubeconfig", "", "path to write kubeconfig (incompatible with --auto-kubeconfig)") | |||
fs.StringVar(&kubeconfigPath, "kubeconfig", kubeconfig.DefaultPath, "path to write kubeconfig (incompatible with --auto-kubeconfig)") |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
pkg/utils/kubeconfig/kubeconfig.go
Outdated
// Write will write Kubernetes client configuration to a file. | ||
// If path isn't specified then the path will be determined by client-go. | ||
// If file pointed to by path doesn't exist it will be created. | ||
// If the file already exists then the configuration will be merged with the existing file. | ||
func Write(path string, newConfig *api.Config, setContext bool) error { | ||
func Write(path string, newConfig *api.Config, setContext bool) (string, error) { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
960940a
to
5381234
Compare
When writing the kubeconfig for the new EKS cluster then the following will happen: - If --kubeconfig, --auto-kubeconfig or KUBECONFING env var are NOT set then the default kube config location will be used (~/.kube/conf). - If KUBECONFIG is set then we use this (assuming --kubeconfig and --auto-kubeconfig aren't specified). - if KUBECONFIG is set BUT --kubeconfig or --auto-kubeconfig are specified then KUBECONFIG will be ignored. - if a kubeconfig file already exists then we merge in the new EKS cluster details with the existing file. - If `set-context` is true then the current-context will be set to that of the new EKS cluster. - If `set-context` is false (default) then if we are merging with an existing configuration file with a current-context set then this won't be updated. - If there is no existing configuration file then current-context will be set even if `set-context` is false. Issue #29
A number of changes in relation to the kube configuration file. The setting of current-context defaults to true. Also updated the write-kubeconfig command so that its merges configs as well. Also, when deleting a cluster it will only try and delete an auto-generated config file (otherwise it will warn that you need to do this manually). Issue #29
- rename kubeconf to kubeconfig - use default kubeconfig path directly - remove unecessary method for default path and use client-go instead - other minor cosmetic tweaks
The kubeconfig package has been modified to use `NewDefaultPathOptions` `ModifyConfig` like kops instead of other handcrafted methods. The plan will eventually to be re-use KubeConfBuilder from kops when it supports exec. Issue #29
The method to write the kube configuration file in the `kubeconfig` package has been change from `WriteKubeCfg` to `Write` as its simpler and more readable.
b5f13fa
to
e4aeef5
Compare
- set `--auto-kubeconfig=false` by default - fix default `--kubeconfig` value - pass context to command checker - do not pass `setContext` to client builder - obtain effective filename - remove unused import - improve output messages - use more explicit flag syntax in output message - add missing message in `eksctl utils write-kubeconfig` - clarify kubectl test warning
e4aeef5
to
7e6bf07
Compare
Add support for creating encrypted volume
Incorporates @richardcase's changes from #78.