Commit f37b3065 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #50078 from php-coder/fix_useless_cat_usage

Automatic merge from submit-queue Simplify a command for unmounting mounted directories **What this PR does / why we need it**: This PR simplifies a command for unmounting mounted directories. It replaces `cat | awk | grep` by a single `awk` expression. **Special notes for your reviewer**: Link about useless cat/grep usage: http://porkmail.org/era/unix/award.html#grep **Credit**: I saw this code fragment in the Julia Evans (@jvns) [write up](https://jvns.ca/blog/2017/07/30/a-couple-useful-ideas-from-google/). **Release note**: ```release-note NONE ``` CC @simo5
parents 6cbfac2c ae99f10a
......@@ -97,7 +97,7 @@ func (r *Reset) Run(out io.Writer) error {
// Try to unmount mounted directories under /var/lib/kubelet in order to be able to remove the /var/lib/kubelet directory later
fmt.Printf("[reset] Unmounting mounted directories in %q\n", "/var/lib/kubelet")
umountDirsCmd := "cat /proc/mounts | awk '{print $2}' | grep '/var/lib/kubelet' | xargs -r umount"
umountDirsCmd := "awk '$2 ~ path {print $2}' path=/var/lib/kubelet /proc/mounts | xargs -r umount"
umountOutputBytes, err := exec.Command("sh", "-c", umountDirsCmd).Output()
if err != nil {
fmt.Printf("[reset] Failed to unmount mounted directories in /var/lib/kubelet: %s\n", string(umountOutputBytes))
......
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