Commit 53b27ef1 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #36474 from bruceauyeung/branch-failure-check-on-umount-when-kubeadm-reset

Automatic merge from submit-queue add failure check on umount when kubeadm reset, and on service stop **What this PR does / why we need it**: before this PR, `umount` will exit with code `123` if `grep` does not match anything `xargs` has an option: >-r, --no-run-if-empty If the standard input does not contain any nonblanks, do not run the command. Normally, the command is run once even if there is no input. This option is a GNU extension. 1. this PR add `-r` option to `xargs` , so `umount` will not execute and exit with code `0` correctly while `grep` does not match anything. 2. this PR add failure check on umount. for example, if the directory to be umount is busy, a error message will be printed: >failed to unmount directories in /var/lib/kubelet, umount: /var/lib/kubelet/foo/bar: target is busy (In some cases useful info about processes that use the device is found by lsof(8) or fuser(1).) 3. add failure check on kubelet service stop. Signed-off-by: 's avatarbruceauyeung <ouyang.qinhua@zte.com.cn>
parents edefe66c 06a6ec21
...@@ -124,12 +124,17 @@ func (r *Reset) Run(out io.Writer) error { ...@@ -124,12 +124,17 @@ func (r *Reset) Run(out io.Writer) error {
fmt.Printf("%v", err) fmt.Printf("%v", err)
} else { } else {
fmt.Printf("Stopping the %s service...\n", serviceToStop) fmt.Printf("Stopping the %s service...\n", serviceToStop)
initSystem.ServiceStop(serviceToStop) if err := initSystem.ServiceStop(serviceToStop); err != nil {
fmt.Printf("failed to stop the %s service", serviceToStop)
}
} }
fmt.Printf("Unmounting directories in /var/lib/kubelet...\n") fmt.Printf("Unmounting directories in /var/lib/kubelet...\n")
// Don't check for errors here, since umount will return a non-zero exit code if there is no directories to umount umountDirsCmd := "cat /proc/mounts | awk '{print $2}' | grep '/var/lib/kubelet' | xargs -r umount"
exec.Command("sh", "-c", "cat /proc/mounts | awk '{print $2}' | grep '/var/lib/kubelet' | xargs umount").Run() umountOutputBytes, err := exec.Command("sh", "-c", umountDirsCmd).Output()
if err != nil {
fmt.Printf("failed to unmount directories in /var/lib/kubelet, %s", string(umountOutputBytes))
}
resetConfigDir("/etc/kubernetes/") resetConfigDir("/etc/kubernetes/")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment