attacher-defaults.go 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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 flexvolume
  14. import (
  15. "time"
  16. "k8s.io/klog"
  17. "k8s.io/apimachinery/pkg/types"
  18. "k8s.io/kubernetes/pkg/util/mount"
  19. "k8s.io/kubernetes/pkg/volume"
  20. )
  21. type attacherDefaults flexVolumeAttacher
  22. // Attach is part of the volume.Attacher interface
  23. func (a *attacherDefaults) Attach(spec *volume.Spec, hostName types.NodeName) (string, error) {
  24. klog.Warning(logPrefix(a.plugin.flexVolumePlugin), "using default Attach for volume ", spec.Name(), ", host ", hostName)
  25. return "", nil
  26. }
  27. // WaitForAttach is part of the volume.Attacher interface
  28. func (a *attacherDefaults) WaitForAttach(spec *volume.Spec, devicePath string, timeout time.Duration) (string, error) {
  29. klog.Warning(logPrefix(a.plugin.flexVolumePlugin), "using default WaitForAttach for volume ", spec.Name(), ", device ", devicePath)
  30. return devicePath, nil
  31. }
  32. // GetDeviceMountPath is part of the volume.Attacher interface
  33. func (a *attacherDefaults) GetDeviceMountPath(spec *volume.Spec, mountsDir string) (string, error) {
  34. return a.plugin.getDeviceMountPath(spec)
  35. }
  36. // MountDevice is part of the volume.Attacher interface
  37. func (a *attacherDefaults) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, mounter mount.Interface) error {
  38. klog.Warning(logPrefix(a.plugin.flexVolumePlugin), "using default MountDevice for volume ", spec.Name(), ", device ", devicePath, ", deviceMountPath ", deviceMountPath)
  39. volSourceFSType, err := getFSType(spec)
  40. if err != nil {
  41. return err
  42. }
  43. readOnly, err := getReadOnly(spec)
  44. if err != nil {
  45. return err
  46. }
  47. options := make([]string, 0)
  48. if readOnly {
  49. options = append(options, "ro")
  50. } else {
  51. options = append(options, "rw")
  52. }
  53. diskMounter := &mount.SafeFormatAndMount{Interface: mounter, Exec: a.plugin.host.GetExec(a.plugin.GetPluginName())}
  54. return diskMounter.FormatAndMount(devicePath, deviceMountPath, volSourceFSType, options)
  55. }