File tree Expand file tree Collapse file tree 4 files changed +80
-7
lines changed
cmd/kubeadm/app/cmd/phases/reset Expand file tree Collapse file tree 4 files changed +80
-7
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ go_library(
7
7
"data.go" ,
8
8
"preflight.go" ,
9
9
"removeetcdmember.go" ,
10
+ "unmount.go" ,
11
+ "unmount_linux.go" ,
10
12
"updateclusterstatus.go" ,
11
13
],
12
14
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/reset" ,
Original file line number Diff line number Diff line change @@ -20,7 +20,6 @@ import (
20
20
"errors"
21
21
"fmt"
22
22
"os"
23
- "os/exec"
24
23
"path/filepath"
25
24
26
25
"k8s.io/klog"
@@ -100,13 +99,10 @@ func absoluteKubeletRunDirectory() (string, error) {
100
99
klog .Warningf ("[reset] Failed to evaluate the %q directory. Skipping its unmount and cleanup: %v\n " , kubeadmconstants .KubeletRunDirectory , err )
101
100
return "" , err
102
101
}
103
-
104
- // Only unmount mount points which start with "/var/lib/kubelet" or absolute path of symbolic link, and avoid using empty absoluteKubeletRunDirectory
105
- umountDirsCmd := fmt .Sprintf ("awk '$2 ~ path {print $2}' path=%s/ /proc/mounts | xargs -r umount" , absoluteKubeletRunDirectory )
106
- klog .V (1 ).Infof ("[reset] Executing command %q" , umountDirsCmd )
107
- umountOutputBytes , err := exec .Command ("sh" , "-c" , umountDirsCmd ).Output ()
102
+ err = unmountKubeletDirectory (absoluteKubeletRunDirectory )
108
103
if err != nil {
109
- klog .Warningf ("[reset] Failed to unmount mounted directories in %s: %s\n " , kubeadmconstants .KubeletRunDirectory , string (umountOutputBytes ))
104
+ klog .Warningf ("[reset] Failed to unmount mounted directories in %s \n " , kubeadmconstants .KubeletRunDirectory )
105
+ return "" , err
110
106
}
111
107
return absoluteKubeletRunDirectory , nil
112
108
}
Original file line number Diff line number Diff line change
1
+ // +build !linux
2
+
3
+ /*
4
+ Copyright 2019 The Kubernetes Authors.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ */
18
+
19
+ package phases
20
+
21
+ import (
22
+ "k8s.io/klog"
23
+ )
24
+
25
+ // unmountKubeletDirectory is a NOOP on all but linux.
26
+ func unmountKubeletDirectory (absoluteKubeletRunDirectory string ) error {
27
+ klog .Warning ("Cannot unmount filesystems on current OS, all mounted file systems will need to be manually unmounted" )
28
+ return nil
29
+ }
Original file line number Diff line number Diff line change
1
+ // +build linux
2
+
3
+ /*
4
+ Copyright 2019 The Kubernetes Authors.
5
+
6
+ Licensed under the Apache License, Version 2.0 (the "License");
7
+ you may not use this file except in compliance with the License.
8
+ You may obtain a copy of the License at
9
+
10
+ http://www.apache.org/licenses/LICENSE-2.0
11
+
12
+ Unless required by applicable law or agreed to in writing, software
13
+ distributed under the License is distributed on an "AS IS" BASIS,
14
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ See the License for the specific language governing permissions and
16
+ limitations under the License.
17
+ */
18
+
19
+ package phases
20
+
21
+ import (
22
+ "io/ioutil"
23
+ "strings"
24
+ "syscall"
25
+
26
+ "k8s.io/klog"
27
+ )
28
+
29
+ // unmountKubeletDirectory unmounts all paths that contain KubeletRunDirectory
30
+ func unmountKubeletDirectory (absoluteKubeletRunDirectory string ) error {
31
+ raw , err := ioutil .ReadFile ("/proc/mounts" )
32
+ if err != nil {
33
+ return err
34
+ }
35
+ mounts := strings .Split (string (raw ), "\n " )
36
+ for _ , mount := range mounts {
37
+ m := strings .Split (mount , " " )
38
+ if len (m ) < 2 || ! strings .HasPrefix (m [1 ], absoluteKubeletRunDirectory ) {
39
+ continue
40
+ }
41
+ if err := syscall .Unmount (m [1 ], 0 ); err != nil {
42
+ klog .Warningf ("[reset] Failed to unmount mounted directory in %s: %s" , absoluteKubeletRunDirectory , m [1 ])
43
+ }
44
+ }
45
+ return nil
46
+ }
You can’t perform that action at this time.
0 commit comments