Unverified Commit c854f72d authored by Kubernetes Prow Robot's avatar Kubernetes Prow Robot Committed by GitHub

Merge pull request #77507 from cuericlee/patch-1

unexpected deleting of contents of mount points due to symbolic link …
parents 89031553 56ce743f
...@@ -279,12 +279,23 @@ func (r *resetData) Run() error { ...@@ -279,12 +279,23 @@ func (r *resetData) Run() error {
// Try to unmount mounted directories under kubeadmconstants.KubeletRunDirectory in order to be able to remove the kubeadmconstants.KubeletRunDirectory directory later // Try to unmount mounted directories under kubeadmconstants.KubeletRunDirectory in order to be able to remove the kubeadmconstants.KubeletRunDirectory directory later
fmt.Printf("[reset] Unmounting mounted directories in %q\n", kubeadmconstants.KubeletRunDirectory) fmt.Printf("[reset] Unmounting mounted directories in %q\n", kubeadmconstants.KubeletRunDirectory)
umountDirsCmd := fmt.Sprintf("awk '$2 ~ path {print $2}' path=%s/ /proc/mounts | xargs -r umount", kubeadmconstants.KubeletRunDirectory)
klog.V(1).Infof("[reset] Executing command %q", umountDirsCmd) // In case KubeletRunDirectory holds a symbolic link, evaluate it
umountOutputBytes, err := exec.Command("sh", "-c", umountDirsCmd).Output() var absoluteKubeletRunDirectory string
absoluteKubeletRunDirectory, err = filepath.EvalSymlinks(kubeadmconstants.KubeletRunDirectory)
if err != nil { if err != nil {
klog.Errorf("[reset] Failed to unmount mounted directories in %s: %s\n", kubeadmconstants.KubeletRunDirectory, string(umountOutputBytes)) klog.Errorf("[reset] Failed to evaluate the %q directory. Skipping its unmount and cleanup: %v", kubeadmconstants.KubeletRunDirectory, err)
} else {
// Only unmount mount points which start with "/var/lib/kubelet" or absolute path of symbolic link, and avoid using empty absoluteKubeletRunDirectory
umountDirsCmd := fmt.Sprintf("awk '$2 ~ path {print $2}' path=%s/ /proc/mounts | xargs -r umount", absoluteKubeletRunDirectory)
klog.V(1).Infof("[reset] Executing command %q", umountDirsCmd)
umountOutputBytes, err := exec.Command("sh", "-c", umountDirsCmd).Output()
if err != nil {
klog.Errorf("[reset] Failed to unmount mounted directories in %s: %s\n", kubeadmconstants.KubeletRunDirectory, string(umountOutputBytes))
} else {
// Only clean absoluteKubeletRunDirectory if umountDirsCmd passed without error
dirsToClean = append(dirsToClean, absoluteKubeletRunDirectory)
}
} }
klog.V(1).Info("[reset] Removing Kubernetes-managed containers") klog.V(1).Info("[reset] Removing Kubernetes-managed containers")
...@@ -292,7 +303,7 @@ func (r *resetData) Run() error { ...@@ -292,7 +303,7 @@ func (r *resetData) Run() error {
klog.Errorf("[reset] Failed to remove containers: %v", err) klog.Errorf("[reset] Failed to remove containers: %v", err)
} }
dirsToClean = append(dirsToClean, []string{kubeadmconstants.KubeletRunDirectory, "/etc/cni/net.d", "/var/lib/dockershim", "/var/run/kubernetes"}...) dirsToClean = append(dirsToClean, []string{"/etc/cni/net.d", "/var/lib/dockershim", "/var/run/kubernetes"}...)
// Then clean contents from the stateful kubelet, etcd and cni directories // Then clean contents from the stateful kubelet, etcd and cni directories
fmt.Printf("[reset] Deleting contents of stateful directories: %v\n", dirsToClean) fmt.Printf("[reset] Deleting contents of stateful directories: %v\n", dirsToClean)
...@@ -317,7 +328,7 @@ func (r *resetData) Run() error { ...@@ -317,7 +328,7 @@ func (r *resetData) Run() error {
If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar) If your cluster was setup to utilize IPVS, run ipvsadm --clear (or similar)
to reset your system's IPVS tables. to reset your system's IPVS tables.
The reset process does not clean your kubeconfig files and you must remove them manually. The reset process does not clean your kubeconfig files and you must remove them manually.
Please, check the contents of the $HOME/.kube/config file. Please, check the contents of the $HOME/.kube/config file.
`) `)
......
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