expander.go 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /*
  2. Copyright 2018 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. "fmt"
  16. "strconv"
  17. "k8s.io/apimachinery/pkg/api/resource"
  18. "k8s.io/kubernetes/pkg/volume"
  19. )
  20. func (plugin *flexVolumePlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resource.Quantity, oldSize resource.Quantity) (resource.Quantity, error) {
  21. call := plugin.NewDriverCall(expandVolumeCmd)
  22. call.AppendSpec(spec, plugin.host, nil)
  23. devicePath, err := plugin.getDeviceMountPath(spec)
  24. if err != nil {
  25. return newSize, err
  26. }
  27. call.Append(devicePath)
  28. call.Append(strconv.FormatInt(newSize.Value(), 10))
  29. call.Append(strconv.FormatInt(oldSize.Value(), 10))
  30. _, err = call.Run()
  31. if isCmdNotSupportedErr(err) {
  32. return newExpanderDefaults(plugin).ExpandVolumeDevice(spec, newSize, oldSize)
  33. }
  34. return newSize, err
  35. }
  36. func (plugin *flexVolumePlugin) NodeExpand(rsOpt volume.NodeResizeOptions) (bool, error) {
  37. // This method is called after we spec.PersistentVolume.Spec.Capacity
  38. // has been updated to the new size. The underlying driver thus sees
  39. // the _new_ (requested) size and can find out the _current_ size from
  40. // its underlying storage implementation
  41. if rsOpt.VolumeSpec.PersistentVolume == nil {
  42. return false, fmt.Errorf("PersistentVolume not found for spec: %s", rsOpt.VolumeSpec.Name())
  43. }
  44. call := plugin.NewDriverCall(expandFSCmd)
  45. call.AppendSpec(rsOpt.VolumeSpec, plugin.host, nil)
  46. call.Append(rsOpt.DevicePath)
  47. call.Append(rsOpt.DeviceMountPath)
  48. call.Append(strconv.FormatInt(rsOpt.NewSize.Value(), 10))
  49. call.Append(strconv.FormatInt(rsOpt.OldSize.Value(), 10))
  50. _, err := call.Run()
  51. if isCmdNotSupportedErr(err) {
  52. return newExpanderDefaults(plugin).NodeExpand(rsOpt)
  53. }
  54. if err != nil {
  55. return false, err
  56. }
  57. return true, nil
  58. }