expander-defaults.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. "k8s.io/apimachinery/pkg/api/resource"
  17. "k8s.io/klog"
  18. "k8s.io/kubernetes/pkg/volume"
  19. "k8s.io/kubernetes/pkg/volume/util"
  20. )
  21. type expanderDefaults struct {
  22. plugin *flexVolumePlugin
  23. }
  24. func newExpanderDefaults(plugin *flexVolumePlugin) *expanderDefaults {
  25. return &expanderDefaults{plugin}
  26. }
  27. func (e *expanderDefaults) ExpandVolumeDevice(spec *volume.Spec, newSize resource.Quantity, oldSize resource.Quantity) (resource.Quantity, error) {
  28. klog.Warning(logPrefix(e.plugin), "using default expand for volume ", spec.Name(), ", to size ", newSize, " from ", oldSize)
  29. return newSize, nil
  30. }
  31. // the defaults for NodeExpand return a generic resize indicator that will trigger the operation executor to go ahead with
  32. // generic filesystem resize
  33. func (e *expanderDefaults) NodeExpand(rsOpt volume.NodeResizeOptions) (bool, error) {
  34. klog.Warning(logPrefix(e.plugin), "using default filesystem resize for volume ", rsOpt.VolumeSpec.Name(), ", at ", rsOpt.DevicePath)
  35. fsVolume, err := util.CheckVolumeModeFilesystem(rsOpt.VolumeSpec)
  36. if err != nil {
  37. return false, fmt.Errorf("error checking VolumeMode: %v", err)
  38. }
  39. // if volume is not a fs file system, there is nothing for us to do here.
  40. if !fsVolume {
  41. return true, nil
  42. }
  43. _, err = util.GenericResizeFS(e.plugin.host, e.plugin.GetPluginName(), rsOpt.DevicePath, rsOpt.DeviceMountPath)
  44. if err != nil {
  45. return false, err
  46. }
  47. return true, nil
  48. }