k8s.io/kubernetes@v1.29.3/pkg/volume/flexvolume/expander.go (about) 1 /* 2 Copyright 2018 The Kubernetes Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package flexvolume 18 19 import ( 20 "fmt" 21 "strconv" 22 23 "k8s.io/apimachinery/pkg/api/resource" 24 "k8s.io/kubernetes/pkg/volume" 25 ) 26 27 func (plugin *flexVolumePlugin) ExpandVolumeDevice(spec *volume.Spec, newSize resource.Quantity, oldSize resource.Quantity) (resource.Quantity, error) { 28 call := plugin.NewDriverCall(expandVolumeCmd) 29 call.AppendSpec(spec, plugin.host, nil) 30 31 devicePath, err := plugin.getDeviceMountPath(spec) 32 if err != nil { 33 return newSize, err 34 } 35 call.Append(devicePath) 36 call.Append(strconv.FormatInt(newSize.Value(), 10)) 37 call.Append(strconv.FormatInt(oldSize.Value(), 10)) 38 39 _, err = call.Run() 40 if isCmdNotSupportedErr(err) { 41 return newExpanderDefaults(plugin).ExpandVolumeDevice(spec, newSize, oldSize) 42 } 43 return newSize, err 44 } 45 46 func (plugin *flexVolumePlugin) NodeExpand(rsOpt volume.NodeResizeOptions) (bool, error) { 47 // This method is called after we spec.PersistentVolume.Spec.Capacity 48 // has been updated to the new size. The underlying driver thus sees 49 // the _new_ (requested) size and can find out the _current_ size from 50 // its underlying storage implementation 51 52 if rsOpt.VolumeSpec.PersistentVolume == nil { 53 return false, fmt.Errorf("PersistentVolume not found for spec: %s", rsOpt.VolumeSpec.Name()) 54 } 55 56 call := plugin.NewDriverCall(expandFSCmd) 57 call.AppendSpec(rsOpt.VolumeSpec, plugin.host, nil) 58 call.Append(rsOpt.DevicePath) 59 call.Append(rsOpt.DeviceMountPath) 60 call.Append(strconv.FormatInt(rsOpt.NewSize.Value(), 10)) 61 call.Append(strconv.FormatInt(rsOpt.OldSize.Value(), 10)) 62 63 _, err := call.Run() 64 if isCmdNotSupportedErr(err) { 65 return newExpanderDefaults(plugin).NodeExpand(rsOpt) 66 } 67 if err != nil { 68 return false, err 69 } 70 return true, nil 71 }