mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-22 19:31:44 +00:00
Merge pull request #81494 from Klaven/remove_awk
Removed awk from kubeadm reset
This commit is contained in:
commit
17a1859370
@ -7,6 +7,8 @@ go_library(
|
||||
"data.go",
|
||||
"preflight.go",
|
||||
"removeetcdmember.go",
|
||||
"unmount.go",
|
||||
"unmount_linux.go",
|
||||
"updateclusterstatus.go",
|
||||
],
|
||||
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/reset",
|
||||
|
@ -20,7 +20,6 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
|
||||
"k8s.io/klog"
|
||||
@ -100,13 +99,10 @@ func absoluteKubeletRunDirectory() (string, error) {
|
||||
klog.Warningf("[reset] Failed to evaluate the %q directory. Skipping its unmount and cleanup: %v\n", kubeadmconstants.KubeletRunDirectory, err)
|
||||
return "", err
|
||||
}
|
||||
|
||||
// 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()
|
||||
err = unmountKubeletDirectory(absoluteKubeletRunDirectory)
|
||||
if err != nil {
|
||||
klog.Warningf("[reset] Failed to unmount mounted directories in %s: %s\n", kubeadmconstants.KubeletRunDirectory, string(umountOutputBytes))
|
||||
klog.Warningf("[reset] Failed to unmount mounted directories in %s \n", kubeadmconstants.KubeletRunDirectory)
|
||||
return "", err
|
||||
}
|
||||
return absoluteKubeletRunDirectory, nil
|
||||
}
|
||||
|
29
cmd/kubeadm/app/cmd/phases/reset/unmount.go
Normal file
29
cmd/kubeadm/app/cmd/phases/reset/unmount.go
Normal file
@ -0,0 +1,29 @@
|
||||
// +build !linux
|
||||
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package phases
|
||||
|
||||
import (
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// unmountKubeletDirectory is a NOOP on all but linux.
|
||||
func unmountKubeletDirectory(absoluteKubeletRunDirectory string) error {
|
||||
klog.Warning("Cannot unmount filesystems on current OS, all mounted file systems will need to be manually unmounted")
|
||||
return nil
|
||||
}
|
46
cmd/kubeadm/app/cmd/phases/reset/unmount_linux.go
Normal file
46
cmd/kubeadm/app/cmd/phases/reset/unmount_linux.go
Normal file
@ -0,0 +1,46 @@
|
||||
// +build linux
|
||||
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package phases
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"k8s.io/klog"
|
||||
)
|
||||
|
||||
// unmountKubeletDirectory unmounts all paths that contain KubeletRunDirectory
|
||||
func unmountKubeletDirectory(absoluteKubeletRunDirectory string) error {
|
||||
raw, err := ioutil.ReadFile("/proc/mounts")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
mounts := strings.Split(string(raw), "\n")
|
||||
for _, mount := range mounts {
|
||||
m := strings.Split(mount, " ")
|
||||
if len(m) < 2 || !strings.HasPrefix(m[1], absoluteKubeletRunDirectory) {
|
||||
continue
|
||||
}
|
||||
if err := syscall.Unmount(m[1], 0); err != nil {
|
||||
klog.Warningf("[reset] Failed to unmount mounted directory in %s: %s", absoluteKubeletRunDirectory, m[1])
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Reference in New Issue
Block a user