...

Source file src/k8s.io/kubernetes/pkg/volume/flexvolume/expander-defaults.go

Documentation: k8s.io/kubernetes/pkg/volume/flexvolume

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

View as plain text