Merge pull request #40855 from apprenda/kubeadm_reset_better_error_logging

Automatic merge from submit-queue

kubeadm: fix reset error logging.

**What this PR does / why we need it**: while investigating https://github.com/kubernetes/kubeadm/issues/142 I realized error logging was misleading. This PR is meant to fix it.

**Special notes for your reviewer**: /cc @luxas 

**Release note**:
```release-note
NONE
```
This commit is contained in:
Kubernetes Submit Queue 2017-02-02 08:55:41 -08:00 committed by GitHub
commit 478c82325c

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