kubeadm: fix reset error logging.

This commit is contained in:
Paulo Pires 2017-02-02 10:54:18 +00:00
parent 0477100f98
commit 68113cacf2
No known key found for this signature in database
GPG Key ID: F3F6ED5C522EAA71

View File

@ -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)
}
}