local.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602
  1. /*
  2. Copyright 2017 The Kubernetes Authors.
  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. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package local
  14. import (
  15. "fmt"
  16. "os"
  17. "path/filepath"
  18. "runtime"
  19. "strings"
  20. "k8s.io/klog"
  21. "k8s.io/api/core/v1"
  22. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  23. "k8s.io/apimachinery/pkg/types"
  24. "k8s.io/client-go/tools/record"
  25. "k8s.io/kubernetes/pkg/kubelet/events"
  26. "k8s.io/kubernetes/pkg/util/mount"
  27. "k8s.io/kubernetes/pkg/volume"
  28. "k8s.io/kubernetes/pkg/volume/util"
  29. "k8s.io/kubernetes/pkg/volume/validation"
  30. "k8s.io/utils/keymutex"
  31. utilstrings "k8s.io/utils/strings"
  32. )
  33. const (
  34. defaultFSType = "ext4"
  35. )
  36. // ProbeVolumePlugins is the primary entrypoint for volume plugins.
  37. func ProbeVolumePlugins() []volume.VolumePlugin {
  38. return []volume.VolumePlugin{&localVolumePlugin{}}
  39. }
  40. type localVolumePlugin struct {
  41. host volume.VolumeHost
  42. volumeLocks keymutex.KeyMutex
  43. recorder record.EventRecorder
  44. }
  45. var _ volume.VolumePlugin = &localVolumePlugin{}
  46. var _ volume.PersistentVolumePlugin = &localVolumePlugin{}
  47. var _ volume.BlockVolumePlugin = &localVolumePlugin{}
  48. const (
  49. localVolumePluginName = "kubernetes.io/local-volume"
  50. )
  51. func (plugin *localVolumePlugin) Init(host volume.VolumeHost) error {
  52. plugin.host = host
  53. plugin.volumeLocks = keymutex.NewHashed(0)
  54. plugin.recorder = host.GetEventRecorder()
  55. return nil
  56. }
  57. func (plugin *localVolumePlugin) GetPluginName() string {
  58. return localVolumePluginName
  59. }
  60. func (plugin *localVolumePlugin) GetVolumeName(spec *volume.Spec) (string, error) {
  61. // This volume is only supported as a PersistentVolumeSource, so the PV name is unique
  62. return spec.Name(), nil
  63. }
  64. func (plugin *localVolumePlugin) CanSupport(spec *volume.Spec) bool {
  65. // This volume is only supported as a PersistentVolumeSource
  66. return (spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Local != nil)
  67. }
  68. func (plugin *localVolumePlugin) IsMigratedToCSI() bool {
  69. return false
  70. }
  71. func (plugin *localVolumePlugin) RequiresRemount() bool {
  72. return false
  73. }
  74. func (plugin *localVolumePlugin) SupportsMountOption() bool {
  75. return true
  76. }
  77. func (plugin *localVolumePlugin) SupportsBulkVolumeVerification() bool {
  78. return false
  79. }
  80. func (plugin *localVolumePlugin) GetAccessModes() []v1.PersistentVolumeAccessMode {
  81. // The current meaning of AccessMode is how many nodes can attach to it, not how many pods can mount it
  82. return []v1.PersistentVolumeAccessMode{
  83. v1.ReadWriteOnce,
  84. }
  85. }
  86. func getVolumeSource(spec *volume.Spec) (*v1.LocalVolumeSource, bool, error) {
  87. if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.Local != nil {
  88. return spec.PersistentVolume.Spec.Local, spec.ReadOnly, nil
  89. }
  90. return nil, false, fmt.Errorf("Spec does not reference a Local volume type")
  91. }
  92. func (plugin *localVolumePlugin) NewMounter(spec *volume.Spec, pod *v1.Pod, _ volume.VolumeOptions) (volume.Mounter, error) {
  93. _, readOnly, err := getVolumeSource(spec)
  94. if err != nil {
  95. return nil, err
  96. }
  97. globalLocalPath, err := plugin.getGlobalLocalPath(spec)
  98. if err != nil {
  99. return nil, err
  100. }
  101. return &localVolumeMounter{
  102. localVolume: &localVolume{
  103. pod: pod,
  104. podUID: pod.UID,
  105. volName: spec.Name(),
  106. mounter: plugin.host.GetMounter(plugin.GetPluginName()),
  107. plugin: plugin,
  108. globalPath: globalLocalPath,
  109. MetricsProvider: volume.NewMetricsStatFS(plugin.host.GetPodVolumeDir(pod.UID, utilstrings.EscapeQualifiedName(localVolumePluginName), spec.Name())),
  110. },
  111. mountOptions: util.MountOptionFromSpec(spec),
  112. readOnly: readOnly,
  113. }, nil
  114. }
  115. func (plugin *localVolumePlugin) NewUnmounter(volName string, podUID types.UID) (volume.Unmounter, error) {
  116. return &localVolumeUnmounter{
  117. localVolume: &localVolume{
  118. podUID: podUID,
  119. volName: volName,
  120. mounter: plugin.host.GetMounter(plugin.GetPluginName()),
  121. plugin: plugin,
  122. },
  123. }, nil
  124. }
  125. func (plugin *localVolumePlugin) NewBlockVolumeMapper(spec *volume.Spec, pod *v1.Pod,
  126. _ volume.VolumeOptions) (volume.BlockVolumeMapper, error) {
  127. volumeSource, readOnly, err := getVolumeSource(spec)
  128. if err != nil {
  129. return nil, err
  130. }
  131. return &localVolumeMapper{
  132. localVolume: &localVolume{
  133. podUID: pod.UID,
  134. volName: spec.Name(),
  135. globalPath: volumeSource.Path,
  136. plugin: plugin,
  137. },
  138. readOnly: readOnly,
  139. }, nil
  140. }
  141. func (plugin *localVolumePlugin) NewBlockVolumeUnmapper(volName string,
  142. podUID types.UID) (volume.BlockVolumeUnmapper, error) {
  143. return &localVolumeUnmapper{
  144. localVolume: &localVolume{
  145. podUID: podUID,
  146. volName: volName,
  147. plugin: plugin,
  148. },
  149. }, nil
  150. }
  151. // TODO: check if no path and no topology constraints are ok
  152. func (plugin *localVolumePlugin) ConstructVolumeSpec(volumeName, mountPath string) (*volume.Spec, error) {
  153. fs := v1.PersistentVolumeFilesystem
  154. localVolume := &v1.PersistentVolume{
  155. ObjectMeta: metav1.ObjectMeta{
  156. Name: volumeName,
  157. },
  158. Spec: v1.PersistentVolumeSpec{
  159. PersistentVolumeSource: v1.PersistentVolumeSource{
  160. Local: &v1.LocalVolumeSource{
  161. Path: "",
  162. },
  163. },
  164. VolumeMode: &fs,
  165. },
  166. }
  167. return volume.NewSpecFromPersistentVolume(localVolume, false), nil
  168. }
  169. func (plugin *localVolumePlugin) ConstructBlockVolumeSpec(podUID types.UID, volumeName,
  170. mapPath string) (*volume.Spec, error) {
  171. block := v1.PersistentVolumeBlock
  172. localVolume := &v1.PersistentVolume{
  173. ObjectMeta: metav1.ObjectMeta{
  174. Name: volumeName,
  175. },
  176. Spec: v1.PersistentVolumeSpec{
  177. PersistentVolumeSource: v1.PersistentVolumeSource{
  178. Local: &v1.LocalVolumeSource{
  179. Path: "",
  180. },
  181. },
  182. VolumeMode: &block,
  183. },
  184. }
  185. return volume.NewSpecFromPersistentVolume(localVolume, false), nil
  186. }
  187. func (plugin *localVolumePlugin) generateBlockDeviceBaseGlobalPath() string {
  188. return filepath.Join(plugin.host.GetPluginDir(localVolumePluginName), util.MountsInGlobalPDPath)
  189. }
  190. func (plugin *localVolumePlugin) getGlobalLocalPath(spec *volume.Spec) (string, error) {
  191. if spec.PersistentVolume.Spec.Local == nil || len(spec.PersistentVolume.Spec.Local.Path) == 0 {
  192. return "", fmt.Errorf("local volume source is nil or local path is not set")
  193. }
  194. fileType, err := plugin.host.GetMounter(plugin.GetPluginName()).GetFileType(spec.PersistentVolume.Spec.Local.Path)
  195. if err != nil {
  196. return "", err
  197. }
  198. switch fileType {
  199. case mount.FileTypeDirectory:
  200. return spec.PersistentVolume.Spec.Local.Path, nil
  201. case mount.FileTypeBlockDev:
  202. return filepath.Join(plugin.generateBlockDeviceBaseGlobalPath(), spec.Name()), nil
  203. default:
  204. return "", fmt.Errorf("only directory and block device are supported")
  205. }
  206. }
  207. var _ volume.DeviceMountableVolumePlugin = &localVolumePlugin{}
  208. type deviceMounter struct {
  209. plugin *localVolumePlugin
  210. mounter *mount.SafeFormatAndMount
  211. }
  212. var _ volume.DeviceMounter = &deviceMounter{}
  213. func (plugin *localVolumePlugin) CanDeviceMount(spec *volume.Spec) (bool, error) {
  214. return true, nil
  215. }
  216. func (plugin *localVolumePlugin) NewDeviceMounter() (volume.DeviceMounter, error) {
  217. return &deviceMounter{
  218. plugin: plugin,
  219. mounter: util.NewSafeFormatAndMountFromHost(plugin.GetPluginName(), plugin.host),
  220. }, nil
  221. }
  222. func (dm *deviceMounter) mountLocalBlockDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
  223. klog.V(4).Infof("local: mounting device %s to %s", devicePath, deviceMountPath)
  224. notMnt, err := dm.mounter.IsLikelyNotMountPoint(deviceMountPath)
  225. if err != nil {
  226. if os.IsNotExist(err) {
  227. if err := os.MkdirAll(deviceMountPath, 0750); err != nil {
  228. return err
  229. }
  230. notMnt = true
  231. } else {
  232. return err
  233. }
  234. }
  235. if !notMnt {
  236. return nil
  237. }
  238. fstype, err := getVolumeSourceFSType(spec)
  239. if err != nil {
  240. return err
  241. }
  242. ro, err := getVolumeSourceReadOnly(spec)
  243. if err != nil {
  244. return err
  245. }
  246. options := []string{}
  247. if ro {
  248. options = append(options, "ro")
  249. }
  250. mountOptions := util.MountOptionFromSpec(spec, options...)
  251. err = dm.mounter.FormatAndMount(devicePath, deviceMountPath, fstype, mountOptions)
  252. if err != nil {
  253. os.Remove(deviceMountPath)
  254. return fmt.Errorf("local: failed to mount device %s at %s (fstype: %s), error %v", devicePath, deviceMountPath, fstype, err)
  255. }
  256. klog.V(3).Infof("local: successfully mount device %s at %s (fstype: %s)", devicePath, deviceMountPath, fstype)
  257. return nil
  258. }
  259. func (dm *deviceMounter) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string) error {
  260. if spec.PersistentVolume.Spec.Local == nil || len(spec.PersistentVolume.Spec.Local.Path) == 0 {
  261. return fmt.Errorf("local volume source is nil or local path is not set")
  262. }
  263. fileType, err := dm.mounter.GetFileType(spec.PersistentVolume.Spec.Local.Path)
  264. if err != nil {
  265. return err
  266. }
  267. switch fileType {
  268. case mount.FileTypeBlockDev:
  269. // local volume plugin does not implement AttachableVolumePlugin interface, so set devicePath to Path in PV spec directly
  270. devicePath = spec.PersistentVolume.Spec.Local.Path
  271. return dm.mountLocalBlockDevice(spec, devicePath, deviceMountPath)
  272. case mount.FileTypeDirectory:
  273. // if the given local volume path is of already filesystem directory, return directly
  274. return nil
  275. default:
  276. return fmt.Errorf("only directory and block device are supported")
  277. }
  278. }
  279. func getVolumeSourceFSType(spec *volume.Spec) (string, error) {
  280. if spec.PersistentVolume != nil &&
  281. spec.PersistentVolume.Spec.Local != nil {
  282. if spec.PersistentVolume.Spec.Local.FSType != nil {
  283. return *spec.PersistentVolume.Spec.Local.FSType, nil
  284. }
  285. // if the FSType is not set in local PV spec, setting it to default ("ext4")
  286. return defaultFSType, nil
  287. }
  288. return "", fmt.Errorf("spec does not reference a Local volume type")
  289. }
  290. func getVolumeSourceReadOnly(spec *volume.Spec) (bool, error) {
  291. if spec.PersistentVolume != nil &&
  292. spec.PersistentVolume.Spec.Local != nil {
  293. // local volumes used as a PersistentVolume gets the ReadOnly flag indirectly through
  294. // the persistent-claim volume used to mount the PV
  295. return spec.ReadOnly, nil
  296. }
  297. return false, fmt.Errorf("spec does not reference a Local volume type")
  298. }
  299. func (dm *deviceMounter) GetDeviceMountPath(spec *volume.Spec) (string, error) {
  300. return dm.plugin.getGlobalLocalPath(spec)
  301. }
  302. func (plugin *localVolumePlugin) NewDeviceUnmounter() (volume.DeviceUnmounter, error) {
  303. return &deviceMounter{
  304. plugin: plugin,
  305. mounter: util.NewSafeFormatAndMountFromHost(plugin.GetPluginName(), plugin.host),
  306. }, nil
  307. }
  308. func (plugin *localVolumePlugin) GetDeviceMountRefs(deviceMountPath string) ([]string, error) {
  309. mounter := plugin.host.GetMounter(plugin.GetPluginName())
  310. return mounter.GetMountRefs(deviceMountPath)
  311. }
  312. var _ volume.DeviceUnmounter = &deviceMounter{}
  313. func (dm *deviceMounter) UnmountDevice(deviceMountPath string) error {
  314. // If the local PV is a block device,
  315. // The deviceMountPath is generated to the format like :/var/lib/kubelet/plugins/kubernetes.io/local-volume/mounts/localpv.spec.Name;
  316. // If it is a filesystem directory, then the deviceMountPath is set directly to pvSpec.Local.Path
  317. // We only need to unmount block device here, so we need to check if the deviceMountPath passed here
  318. // has base mount path: /var/lib/kubelet/plugins/kubernetes.io/local-volume/mounts
  319. basemountPath := dm.plugin.generateBlockDeviceBaseGlobalPath()
  320. if mount.PathWithinBase(deviceMountPath, basemountPath) {
  321. return mount.CleanupMountPoint(deviceMountPath, dm.mounter, false)
  322. }
  323. return nil
  324. }
  325. // Local volumes represent a local directory on a node.
  326. // The directory at the globalPath will be bind-mounted to the pod's directory
  327. type localVolume struct {
  328. volName string
  329. pod *v1.Pod
  330. podUID types.UID
  331. // Global path to the volume
  332. globalPath string
  333. // Mounter interface that provides system calls to mount the global path to the pod local path.
  334. mounter mount.Interface
  335. plugin *localVolumePlugin
  336. volume.MetricsProvider
  337. }
  338. func (l *localVolume) GetPath() string {
  339. return l.plugin.host.GetPodVolumeDir(l.podUID, utilstrings.EscapeQualifiedName(localVolumePluginName), l.volName)
  340. }
  341. type localVolumeMounter struct {
  342. *localVolume
  343. readOnly bool
  344. mountOptions []string
  345. }
  346. var _ volume.Mounter = &localVolumeMounter{}
  347. func (m *localVolumeMounter) GetAttributes() volume.Attributes {
  348. return volume.Attributes{
  349. ReadOnly: m.readOnly,
  350. Managed: !m.readOnly,
  351. SupportsSELinux: true,
  352. }
  353. }
  354. // CanMount checks prior to mount operations to verify that the required components (binaries, etc.)
  355. // to mount the volume are available on the underlying node.
  356. // If not, it returns an error
  357. func (m *localVolumeMounter) CanMount() error {
  358. return nil
  359. }
  360. // SetUp bind mounts the directory to the volume path
  361. func (m *localVolumeMounter) SetUp(mounterArgs volume.MounterArgs) error {
  362. return m.SetUpAt(m.GetPath(), mounterArgs)
  363. }
  364. // SetUpAt bind mounts the directory to the volume path and sets up volume ownership
  365. func (m *localVolumeMounter) SetUpAt(dir string, mounterArgs volume.MounterArgs) error {
  366. m.plugin.volumeLocks.LockKey(m.globalPath)
  367. defer m.plugin.volumeLocks.UnlockKey(m.globalPath)
  368. if m.globalPath == "" {
  369. return fmt.Errorf("LocalVolume volume %q path is empty", m.volName)
  370. }
  371. err := validation.ValidatePathNoBacksteps(m.globalPath)
  372. if err != nil {
  373. return fmt.Errorf("invalid path: %s %v", m.globalPath, err)
  374. }
  375. notMnt, err := mount.IsNotMountPoint(m.mounter, dir)
  376. klog.V(4).Infof("LocalVolume mount setup: PodDir(%s) VolDir(%s) Mounted(%t) Error(%v), ReadOnly(%t)", dir, m.globalPath, !notMnt, err, m.readOnly)
  377. if err != nil && !os.IsNotExist(err) {
  378. klog.Errorf("cannot validate mount point: %s %v", dir, err)
  379. return err
  380. }
  381. if !notMnt {
  382. return nil
  383. }
  384. refs, err := m.mounter.GetMountRefs(m.globalPath)
  385. if mounterArgs.FsGroup != nil {
  386. if err != nil {
  387. klog.Errorf("cannot collect mounting information: %s %v", m.globalPath, err)
  388. return err
  389. }
  390. // Only count mounts from other pods
  391. refs = m.filterPodMounts(refs)
  392. if len(refs) > 0 {
  393. fsGroupNew := int64(*mounterArgs.FsGroup)
  394. fsGroupOld, err := m.mounter.GetFSGroup(m.globalPath)
  395. if err != nil {
  396. return fmt.Errorf("failed to check fsGroup for %s (%v)", m.globalPath, err)
  397. }
  398. if fsGroupNew != fsGroupOld {
  399. m.plugin.recorder.Eventf(m.pod, v1.EventTypeWarning, events.WarnAlreadyMountedVolume, "The requested fsGroup is %d, but the volume %s has GID %d. The volume may not be shareable.", fsGroupNew, m.volName, fsGroupOld)
  400. }
  401. }
  402. }
  403. if runtime.GOOS != "windows" {
  404. // skip below MkdirAll for windows since the "bind mount" logic is implemented differently in mount_wiondows.go
  405. if err := os.MkdirAll(dir, 0750); err != nil {
  406. klog.Errorf("mkdir failed on disk %s (%v)", dir, err)
  407. return err
  408. }
  409. }
  410. // Perform a bind mount to the full path to allow duplicate mounts of the same volume.
  411. options := []string{"bind"}
  412. if m.readOnly {
  413. options = append(options, "ro")
  414. }
  415. mountOptions := util.JoinMountOptions(options, m.mountOptions)
  416. klog.V(4).Infof("attempting to mount %s", dir)
  417. globalPath := util.MakeAbsolutePath(runtime.GOOS, m.globalPath)
  418. err = m.mounter.Mount(globalPath, dir, "", mountOptions)
  419. if err != nil {
  420. klog.Errorf("Mount of volume %s failed: %v", dir, err)
  421. notMnt, mntErr := mount.IsNotMountPoint(m.mounter, dir)
  422. if mntErr != nil {
  423. klog.Errorf("IsNotMountPoint check failed: %v", mntErr)
  424. return err
  425. }
  426. if !notMnt {
  427. if mntErr = m.mounter.Unmount(dir); mntErr != nil {
  428. klog.Errorf("Failed to unmount: %v", mntErr)
  429. return err
  430. }
  431. notMnt, mntErr = mount.IsNotMountPoint(m.mounter, dir)
  432. if mntErr != nil {
  433. klog.Errorf("IsNotMountPoint check failed: %v", mntErr)
  434. return err
  435. }
  436. if !notMnt {
  437. // This is very odd, we don't expect it. We'll try again next sync loop.
  438. klog.Errorf("%s is still mounted, despite call to unmount(). Will try again next sync loop.", dir)
  439. return err
  440. }
  441. }
  442. os.Remove(dir)
  443. return err
  444. }
  445. if !m.readOnly {
  446. // Volume owner will be written only once on the first volume mount
  447. if len(refs) == 0 {
  448. return volume.SetVolumeOwnership(m, mounterArgs.FsGroup)
  449. }
  450. }
  451. return nil
  452. }
  453. // filterPodMounts only returns mount paths inside the kubelet pod directory
  454. func (m *localVolumeMounter) filterPodMounts(refs []string) []string {
  455. filtered := []string{}
  456. for _, r := range refs {
  457. if strings.HasPrefix(r, m.plugin.host.GetPodsDir()+string(os.PathSeparator)) {
  458. filtered = append(filtered, r)
  459. }
  460. }
  461. return filtered
  462. }
  463. type localVolumeUnmounter struct {
  464. *localVolume
  465. }
  466. var _ volume.Unmounter = &localVolumeUnmounter{}
  467. // TearDown unmounts the bind mount
  468. func (u *localVolumeUnmounter) TearDown() error {
  469. return u.TearDownAt(u.GetPath())
  470. }
  471. // TearDownAt unmounts the bind mount
  472. func (u *localVolumeUnmounter) TearDownAt(dir string) error {
  473. klog.V(4).Infof("Unmounting volume %q at path %q\n", u.volName, dir)
  474. return mount.CleanupMountPoint(dir, u.mounter, true) /* extensiveMountPointCheck = true */
  475. }
  476. // localVolumeMapper implements the BlockVolumeMapper interface for local volumes.
  477. type localVolumeMapper struct {
  478. *localVolume
  479. readOnly bool
  480. }
  481. var _ volume.BlockVolumeMapper = &localVolumeMapper{}
  482. // SetUpDevice provides physical device path for the local PV.
  483. func (m *localVolumeMapper) SetUpDevice() (string, error) {
  484. globalPath := util.MakeAbsolutePath(runtime.GOOS, m.globalPath)
  485. klog.V(4).Infof("SetupDevice returning path %s", globalPath)
  486. return globalPath, nil
  487. }
  488. func (m *localVolumeMapper) MapDevice(devicePath, globalMapPath, volumeMapPath, volumeMapName string, podUID types.UID) error {
  489. return util.MapBlockVolume(devicePath, globalMapPath, volumeMapPath, volumeMapName, podUID)
  490. }
  491. // localVolumeUnmapper implements the BlockVolumeUnmapper interface for local volumes.
  492. type localVolumeUnmapper struct {
  493. *localVolume
  494. }
  495. var _ volume.BlockVolumeUnmapper = &localVolumeUnmapper{}
  496. // TearDownDevice will undo SetUpDevice procedure. In local PV, all of this already handled by operation_generator.
  497. func (u *localVolumeUnmapper) TearDownDevice(mapPath, _ string) error {
  498. klog.V(4).Infof("local: TearDownDevice completed for: %s", mapPath)
  499. return nil
  500. }
  501. // GetGlobalMapPath returns global map path and error.
  502. // path: plugins/kubernetes.io/kubernetes.io/local-volume/volumeDevices/{volumeName}
  503. func (l *localVolume) GetGlobalMapPath(spec *volume.Spec) (string, error) {
  504. return filepath.Join(l.plugin.host.GetVolumeDevicePluginDir(utilstrings.EscapeQualifiedName(localVolumePluginName)),
  505. l.volName), nil
  506. }
  507. // GetPodDeviceMapPath returns pod device map path and volume name.
  508. // path: pods/{podUid}/volumeDevices/kubernetes.io~local-volume
  509. // volName: local-pv-ff0d6d4
  510. func (l *localVolume) GetPodDeviceMapPath() (string, string) {
  511. return l.plugin.host.GetPodVolumeDeviceDir(l.podUID,
  512. utilstrings.EscapeQualifiedName(localVolumePluginName)), l.volName
  513. }