1 // Copyright 2021 Chaos Mesh Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 16 package server 17 18 import ( 19 "context" 20 "strings" 21 22 "github.com/pkg/errors" 23 v1 "k8s.io/api/core/v1" 24 25 "github.com/chaos-mesh/chaos-mesh/pkg/bpm" 26 ) 27 28 // GetMounts returns mounts info 29 // The output looks like: 30 // ``` 31 // proc /proc proc rw,nosuid,nodev,noexec,relatime 0 0 32 // sys /sys sysfs rw,nosuid,nodev,noexec,relatime 0 0 33 // dev /dev devtmpfs rw,nosuid,relatime,size=16283300k,nr_inodes=4070825,mode=755,inode64 0 0 34 // run /run tmpfs rw,nosuid,nodev,relatime,mode=755,inode64 0 0 35 // tmpfs /dev/shm tmpfs rw,nosuid,nodev,inode64 0 0 36 // cgroup2 /sys/fs/cgroup cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate,memory_recursiveprot 0 0 37 // tmpfs /run/user/1000 tmpfs rw,nosuid,nodev,relatime,size=3258252k,nr_inodes=814563,mode=700,uid=1000,gid=1000,inode64 0 0 38 // ``` 39 func (r *Resolver) GetMounts(ctx context.Context, pod *v1.Pod) ([]string, error) { 40 cmd := "cat /proc/mounts" 41 out, err := r.ExecBypass(ctx, pod, cmd, bpm.PidNS, bpm.MountNS) 42 if err != nil { 43 return nil, errors.Wrapf(err, "run command %s failed", cmd) 44 } 45 return strings.Split(string(out), "\n"), nil 46 } 47