...

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

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

     1  /*
     2  Copyright 2017 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  	"time"
    21  
    22  	"k8s.io/klog/v2"
    23  	"k8s.io/mount-utils"
    24  
    25  	"k8s.io/apimachinery/pkg/types"
    26  	"k8s.io/kubernetes/pkg/volume"
    27  )
    28  
    29  type attacherDefaults flexVolumeAttacher
    30  
    31  // Attach is part of the volume.Attacher interface
    32  func (a *attacherDefaults) Attach(spec *volume.Spec, hostName types.NodeName) (string, error) {
    33  	klog.Warning(logPrefix(a.plugin.flexVolumePlugin), "using default Attach for volume ", spec.Name(), ", host ", hostName)
    34  	return "", nil
    35  }
    36  
    37  // WaitForAttach is part of the volume.Attacher interface
    38  func (a *attacherDefaults) WaitForAttach(spec *volume.Spec, devicePath string, timeout time.Duration) (string, error) {
    39  	klog.Warning(logPrefix(a.plugin.flexVolumePlugin), "using default WaitForAttach for volume ", spec.Name(), ", device ", devicePath)
    40  	return devicePath, nil
    41  }
    42  
    43  // GetDeviceMountPath is part of the volume.Attacher interface
    44  func (a *attacherDefaults) GetDeviceMountPath(spec *volume.Spec, mountsDir string) (string, error) {
    45  	return a.plugin.getDeviceMountPath(spec)
    46  }
    47  
    48  // MountDevice is part of the volume.Attacher interface
    49  func (a *attacherDefaults) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, mounter mount.Interface) error {
    50  	klog.Warning(logPrefix(a.plugin.flexVolumePlugin), "using default MountDevice for volume ", spec.Name(), ", device ", devicePath, ", deviceMountPath ", deviceMountPath)
    51  
    52  	volSourceFSType, err := getFSType(spec)
    53  	if err != nil {
    54  		return err
    55  	}
    56  
    57  	readOnly, err := getReadOnly(spec)
    58  	if err != nil {
    59  		return err
    60  	}
    61  
    62  	options := make([]string, 0)
    63  
    64  	if readOnly {
    65  		options = append(options, "ro")
    66  	} else {
    67  		options = append(options, "rw")
    68  	}
    69  
    70  	diskMounter := &mount.SafeFormatAndMount{Interface: mounter, Exec: a.plugin.host.GetExec(a.plugin.GetPluginName())}
    71  
    72  	return diskMounter.FormatAndMount(devicePath, deviceMountPath, volSourceFSType, options)
    73  }
    74  

View as plain text