mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
kubeadm: fix reset error logging.
This commit is contained in:
parent
0477100f98
commit
68113cacf2
@ -144,7 +144,6 @@ func (r *Reset) Run(out io.Writer) error {
|
||||
}
|
||||
|
||||
func drainAndRemoveNode(removeNode bool) error {
|
||||
|
||||
hostname, err := os.Hostname()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to detect node hostname")
|
||||
@ -156,24 +155,26 @@ func drainAndRemoveNode(removeNode bool) error {
|
||||
|
||||
getNodesCmd := fmt.Sprintf("kubectl --kubeconfig %s get nodes | grep %s", kubeConfigPath, hostname)
|
||||
output, err := exec.Command("sh", "-c", getNodesCmd).Output()
|
||||
if err != nil || len(output) == 0 {
|
||||
if err != nil {
|
||||
// kubeadm shouldn't drain and/or remove the node when it doesn't exist anymore
|
||||
return nil
|
||||
return fmt.Errorf("failed to list nodes: %v", err)
|
||||
}
|
||||
if len(output) == 0 {
|
||||
return fmt.Errorf("list nodes request returned zero entries")
|
||||
}
|
||||
|
||||
fmt.Printf("[reset] Draining node: %q\n", hostname)
|
||||
|
||||
output, err = exec.Command("kubectl", "--kubeconfig", kubeConfigPath, "drain", hostname, "--delete-local-data", "--force", "--ignore-daemonsets").Output()
|
||||
_, err = exec.Command("kubectl", "--kubeconfig", kubeConfigPath, "drain", hostname, "--delete-local-data", "--force", "--ignore-daemonsets").Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to drain node %q [%s]", hostname, output)
|
||||
return fmt.Errorf("failed to drain node %q: %v", hostname, err)
|
||||
}
|
||||
|
||||
if removeNode {
|
||||
fmt.Printf("[reset] Removing node: %q\n", hostname)
|
||||
|
||||
output, err = exec.Command("kubectl", "--kubeconfig", kubeConfigPath, "delete", "node", hostname).Output()
|
||||
_, err = exec.Command("kubectl", "--kubeconfig", kubeConfigPath, "delete", "node", hostname).Output()
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to remove node %q [%s]", hostname, output)
|
||||
return fmt.Errorf("failed to remove node %q: %v", hostname, err)
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user