Default to exporting a kubecfg, even without credentials

We do log a hint for the user when we have exported an empty kubecfg,
but this now supports the "current cluster" UX.

Issue #9990
This commit is contained in:
Justin SB 2020-10-25 14:21:40 -04:00 committed by John Gardiner Myers
parent a9800bb81e
commit 90133b5cfe
2 changed files with 10 additions and 6 deletions

View File

@ -84,7 +84,10 @@ func (o *UpdateClusterOptions) InitDefaults() {
o.Target = "direct"
o.SSHPublicKey = ""
o.OutDir = ""
o.CreateKubecfg = false
// By default we export a kubecfg, but it doesn't have a static/eternal credential in it any more.
o.CreateKubecfg = true
o.RunTasksOptions.InitDefaults()
}
@ -149,10 +152,6 @@ func RunUpdateCluster(ctx context.Context, f *util.Factory, clusterName string,
return nil, fmt.Errorf("cannot use both --admin and --user")
}
if c.CreateKubecfg && c.admin == 0 && c.user == "" {
return nil, fmt.Errorf("--create-kube-config requires that either --admin or --user is set")
}
if c.admin != 0 && !c.CreateKubecfg {
klog.Info("--admin implies --create-kube-config")
c.CreateKubecfg = true
@ -312,6 +311,7 @@ func RunUpdateCluster(ctx context.Context, f *util.Factory, clusterName string,
firstRun = !hasKubecfg
klog.Infof("Exporting kubecfg for cluster")
// TODO: Another flag?
useKopsAuthenticationPlugin := false
conf, err := kubeconfig.BuildKubecfg(
@ -332,6 +332,10 @@ func RunUpdateCluster(ctx context.Context, f *util.Factory, clusterName string,
if err != nil {
return nil, err
}
if c.admin == 0 && c.user == "" {
klog.Warningf("Exported kubecfg with no user authentication; use --admin, --user or --auth-plugin flags with `kops export kubecfg`")
}
}
if !isDryrun {

View File

@ -27,7 +27,7 @@ kops update cluster [flags]
```
--admin duration[=18h0m0s] Also export a cluster admin user credential with the specified lifetime and add it to the cluster context
--allow-kops-downgrade Allow an older version of kops to update the cluster than last used
--create-kube-config Will control automatically creating the kube config file on your local filesystem
--create-kube-config Will control automatically creating the kube config file on your local filesystem (default true)
-h, --help help for cluster
--internal Use the cluster's internal DNS name. Implies --create-kube-config
--lifecycle-overrides strings comma separated list of phase overrides, example: SecurityGroups=Ignore,InternetGateway=ExistsAndWarnIfChanges