mirror of
https://github.com/k3s-io/k3s.git
synced 2024-06-07 19:41:36 +00:00
Correctly report and propagate kubeconfig write failures
As seen in issues such as #15 #155 #518 #570 there are situations where k3s will fail to write the kubeconfig file, but reports that it wrote it anyway as the success message is printed unconditionally. Also, secondary actions like setting file mode and creating a symlink are also attempted even if the file was not created. This change skips attempting additional actions, and propagates the failure back upwards. Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
This commit is contained in:
parent
4eb88a2fd3
commit
dfd0f9d1a6
@ -282,8 +282,11 @@ func writeKubeConfig(certs string, config *Config) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err = clientaccess.WriteClientKubeConfig(kubeConfig, url, config.ControlConfig.Runtime.ServerCA, config.ControlConfig.Runtime.ClientAdminCert,
|
if err = clientaccess.WriteClientKubeConfig(kubeConfig, url, config.ControlConfig.Runtime.ServerCA, config.ControlConfig.Runtime.ClientAdminCert,
|
||||||
config.ControlConfig.Runtime.ClientAdminKey); err != nil {
|
config.ControlConfig.Runtime.ClientAdminKey); err == nil {
|
||||||
|
logrus.Infof("Wrote kubeconfig %s", kubeConfig)
|
||||||
|
} else {
|
||||||
logrus.Errorf("Failed to generate kubeconfig: %v", err)
|
logrus.Errorf("Failed to generate kubeconfig: %v", err)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.ControlConfig.KubeConfigMode != "" {
|
if config.ControlConfig.KubeConfigMode != "" {
|
||||||
@ -303,7 +306,6 @@ func writeKubeConfig(certs string, config *Config) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
logrus.Infof("Wrote kubeconfig %s", kubeConfig)
|
|
||||||
if def {
|
if def {
|
||||||
logrus.Infof("Run: %s kubectl", filepath.Base(os.Args[0]))
|
logrus.Infof("Run: %s kubectl", filepath.Base(os.Args[0]))
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user