mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 19:01:49 +00:00
kubeadm: fix kubeadm reset logic
If /etc/kubeadm/amdin.conf doesn't exist kubeadm reset fails with the error: failed to load admin kubeconfig: open /root/.kube/config: no such file or directory Fixed by properly checking if file exists before using it.
This commit is contained in:
parent
30c7df5cd8
commit
7a8de82dfd
@ -62,8 +62,10 @@ func NewCmdReset(in io.Reader, out io.Writer) *cobra.Command {
|
|||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
kubeConfigFile = cmdutil.FindExistingKubeConfig(kubeConfigFile)
|
kubeConfigFile = cmdutil.FindExistingKubeConfig(kubeConfigFile)
|
||||||
|
if _, err := os.Stat(kubeConfigFile); !os.IsNotExist(err) {
|
||||||
client, err = getClientset(kubeConfigFile, false)
|
client, err = getClientset(kubeConfigFile, false)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
}
|
||||||
|
|
||||||
if criSocketPath == "" {
|
if criSocketPath == "" {
|
||||||
criSocketPath, err = resetDetectCRISocket(client)
|
criSocketPath, err = resetDetectCRISocket(client)
|
||||||
@ -298,11 +300,13 @@ func resetConfigDir(configPathDir, pkiPathDir string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func resetDetectCRISocket(client clientset.Interface) (string, error) {
|
func resetDetectCRISocket(client clientset.Interface) (string, error) {
|
||||||
|
if client != nil {
|
||||||
// first try to connect to the cluster for the CRI socket
|
// first try to connect to the cluster for the CRI socket
|
||||||
cfg, err := configutil.FetchInitConfigurationFromCluster(client, os.Stdout, "reset", false)
|
cfg, err := configutil.FetchInitConfigurationFromCluster(client, os.Stdout, "reset", false)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return cfg.NodeRegistration.CRISocket, nil
|
return cfg.NodeRegistration.CRISocket, nil
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// if this fails, try to detect it
|
// if this fails, try to detect it
|
||||||
return utilruntime.DetectCRISocket()
|
return utilruntime.DetectCRISocket()
|
||||||
|
Loading…
Reference in New Issue
Block a user