mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-06-14 02:43:36 +00:00
vendor updates
This commit is contained in:
3
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/BUILD
generated
vendored
3
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/BUILD
generated
vendored
@ -54,8 +54,7 @@ go_test(
|
||||
"probe_test.go",
|
||||
"unmounter_test.go",
|
||||
],
|
||||
importpath = "k8s.io/kubernetes/pkg/volume/flexvolume",
|
||||
library = ":go_default_library",
|
||||
embed = [":go_default_library"],
|
||||
deps = [
|
||||
"//pkg/util/filesystem:go_default_library",
|
||||
"//pkg/util/mount:go_default_library",
|
||||
|
13
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/attacher-defaults.go
generated
vendored
13
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/attacher-defaults.go
generated
vendored
@ -48,7 +48,16 @@ func (a *attacherDefaults) GetDeviceMountPath(spec *volume.Spec, mountsDir strin
|
||||
// MountDevice is part of the volume.Attacher interface
|
||||
func (a *attacherDefaults) MountDevice(spec *volume.Spec, devicePath string, deviceMountPath string, mounter mount.Interface) error {
|
||||
glog.Warning(logPrefix(a.plugin.flexVolumePlugin), "using default MountDevice for volume ", spec.Name, ", device ", devicePath, ", deviceMountPath ", deviceMountPath)
|
||||
volSource, readOnly := getVolumeSource(spec)
|
||||
|
||||
volSourceFSType, err := getFSType(spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
readOnly, err := getReadOnly(spec)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
options := make([]string, 0)
|
||||
|
||||
@ -60,5 +69,5 @@ func (a *attacherDefaults) MountDevice(spec *volume.Spec, devicePath string, dev
|
||||
|
||||
diskMounter := &mount.SafeFormatAndMount{Interface: mounter, Exec: a.plugin.host.GetExec(a.plugin.GetPluginName())}
|
||||
|
||||
return diskMounter.FormatAndMount(devicePath, deviceMountPath, volSource.FSType, options)
|
||||
return diskMounter.FormatAndMount(devicePath, deviceMountPath, volSourceFSType, options)
|
||||
}
|
||||
|
2
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/common_test.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/common_test.go
generated
vendored
@ -119,7 +119,7 @@ func fakePersistentVolumeSpec() *volume.Spec {
|
||||
},
|
||||
Spec: v1.PersistentVolumeSpec{
|
||||
PersistentVolumeSource: v1.PersistentVolumeSource{
|
||||
FlexVolume: &v1.FlexVolumeSource{
|
||||
FlexVolume: &v1.FlexPersistentVolumeSource{
|
||||
Driver: "kubernetes.io/fakeAttacher",
|
||||
ReadOnly: false,
|
||||
},
|
||||
|
13
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/detacher.go
generated
vendored
13
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/detacher.go
generated
vendored
@ -19,7 +19,6 @@ package flexvolume
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/golang/glog"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
@ -47,18 +46,6 @@ func (d *flexVolumeDetacher) Detach(volumeName string, hostName types.NodeName)
|
||||
return err
|
||||
}
|
||||
|
||||
// WaitForDetach is part of the volume.Detacher interface.
|
||||
func (d *flexVolumeDetacher) WaitForDetach(devicePath string, timeout time.Duration) error {
|
||||
call := d.plugin.NewDriverCallWithTimeout(waitForDetachCmd, timeout)
|
||||
call.Append(devicePath)
|
||||
|
||||
_, err := call.Run()
|
||||
if isCmdNotSupportedErr(err) {
|
||||
return (*detacherDefaults)(d).WaitForDetach(devicePath, timeout)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// UnmountDevice is part of the volume.Detacher interface.
|
||||
func (d *flexVolumeDetacher) UnmountDevice(deviceMountPath string) error {
|
||||
|
||||
|
22
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/driver-call.go
generated
vendored
22
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/driver-call.go
generated
vendored
@ -39,7 +39,6 @@ const (
|
||||
mountDeviceCmd = "mountdevice"
|
||||
|
||||
detachCmd = "detach"
|
||||
waitForDetachCmd = "waitfordetach"
|
||||
unmountDeviceCmd = "unmountdevice"
|
||||
|
||||
mountCmd = "mount"
|
||||
@ -162,10 +161,25 @@ func (dc *DriverCall) Run() (*DriverStatus, error) {
|
||||
type OptionsForDriver map[string]string
|
||||
|
||||
func NewOptionsForDriver(spec *volume.Spec, host volume.VolumeHost, extraOptions map[string]string) (OptionsForDriver, error) {
|
||||
volSource, readOnly := getVolumeSource(spec)
|
||||
|
||||
volSourceFSType, err := getFSType(spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
readOnly, err := getReadOnly(spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
volSourceOptions, err := getOptions(spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
options := map[string]string{}
|
||||
|
||||
options[optionFSType] = volSource.FSType
|
||||
options[optionFSType] = volSourceFSType
|
||||
|
||||
if readOnly {
|
||||
options[optionReadWrite] = "ro"
|
||||
@ -179,7 +193,7 @@ func NewOptionsForDriver(spec *volume.Spec, host volume.VolumeHost, extraOptions
|
||||
options[key] = value
|
||||
}
|
||||
|
||||
for key, value := range volSource.Options {
|
||||
for key, value := range volSourceOptions {
|
||||
options[key] = value
|
||||
}
|
||||
|
||||
|
2
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/flexvolume_test.go
generated
vendored
2
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/flexvolume_test.go
generated
vendored
@ -185,7 +185,7 @@ func TestCanSupport(t *testing.T) {
|
||||
if !plugin.CanSupport(&volume.Spec{Volume: &v1.Volume{VolumeSource: v1.VolumeSource{FlexVolume: &v1.FlexVolumeSource{Driver: "kubernetes.io/fakeAttacher"}}}}) {
|
||||
t.Errorf("Expected true")
|
||||
}
|
||||
if !plugin.CanSupport(&volume.Spec{PersistentVolume: &v1.PersistentVolume{Spec: v1.PersistentVolumeSpec{PersistentVolumeSource: v1.PersistentVolumeSource{FlexVolume: &v1.FlexVolumeSource{Driver: "kubernetes.io/fakeAttacher"}}}}}) {
|
||||
if !plugin.CanSupport(&volume.Spec{PersistentVolume: &v1.PersistentVolume{Spec: v1.PersistentVolumeSpec{PersistentVolumeSource: v1.PersistentVolumeSource{FlexVolume: &v1.FlexPersistentVolumeSource{Driver: "kubernetes.io/fakeAttacher"}}}}}) {
|
||||
t.Errorf("Expected true")
|
||||
}
|
||||
if plugin.CanSupport(&volume.Spec{Volume: &v1.Volume{VolumeSource: v1.VolumeSource{}}}) {
|
||||
|
23
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/plugin.go
generated
vendored
23
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/plugin.go
generated
vendored
@ -30,6 +30,7 @@ import (
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
utilstrings "k8s.io/kubernetes/pkg/util/strings"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
"k8s.io/kubernetes/pkg/volume/util"
|
||||
"k8s.io/utils/exec"
|
||||
)
|
||||
|
||||
@ -103,7 +104,7 @@ func (plugin *flexVolumePlugin) getExecutable() string {
|
||||
execName := parts[len(parts)-1]
|
||||
execPath := path.Join(plugin.execPath, execName)
|
||||
if runtime.GOOS == "windows" {
|
||||
execPath = volume.GetWindowsPath(execPath)
|
||||
execPath = util.GetWindowsPath(execPath)
|
||||
}
|
||||
return execPath
|
||||
}
|
||||
@ -137,8 +138,11 @@ func (plugin *flexVolumePlugin) GetVolumeName(spec *volume.Spec) (string, error)
|
||||
|
||||
// CanSupport is part of the volume.VolumePlugin interface.
|
||||
func (plugin *flexVolumePlugin) CanSupport(spec *volume.Spec) bool {
|
||||
source, _ := getVolumeSource(spec)
|
||||
return (source != nil) && (source.Driver == plugin.driverName)
|
||||
sourceDriver, err := getDriver(spec)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return sourceDriver == plugin.driverName
|
||||
}
|
||||
|
||||
// RequiresRemount is part of the volume.VolumePlugin interface.
|
||||
@ -161,10 +165,19 @@ func (plugin *flexVolumePlugin) NewMounter(spec *volume.Spec, pod *api.Pod, _ vo
|
||||
|
||||
// newMounterInternal is the internal mounter routine to build the volume.
|
||||
func (plugin *flexVolumePlugin) newMounterInternal(spec *volume.Spec, pod *api.Pod, mounter mount.Interface, runner exec.Interface) (volume.Mounter, error) {
|
||||
source, readOnly := getVolumeSource(spec)
|
||||
sourceDriver, err := getDriver(spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
readOnly, err := getReadOnly(spec)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &flexVolumeMounter{
|
||||
flexVolume: &flexVolume{
|
||||
driverName: source.Driver,
|
||||
driverName: sourceDriver,
|
||||
execPath: plugin.getExecutable(),
|
||||
mounter: mounter,
|
||||
plugin: plugin,
|
||||
|
80
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/util.go
generated
vendored
80
vendor/k8s.io/kubernetes/pkg/volume/flexvolume/util.go
generated
vendored
@ -22,15 +22,18 @@ import (
|
||||
"os"
|
||||
|
||||
"github.com/golang/glog"
|
||||
api "k8s.io/api/core/v1"
|
||||
"k8s.io/kubernetes/pkg/util/mount"
|
||||
"k8s.io/kubernetes/pkg/volume"
|
||||
"k8s.io/kubernetes/pkg/volume/util"
|
||||
)
|
||||
|
||||
func addSecretsToOptions(options map[string]string, spec *volume.Spec, namespace string, driverName string, host volume.VolumeHost) error {
|
||||
fv, _ := getVolumeSource(spec)
|
||||
if fv.SecretRef == nil {
|
||||
secretName, secretNamespace, err := getSecretNameAndNamespace(spec, namespace)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if len(secretName) == 0 || len(secretNamespace) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -39,9 +42,9 @@ func addSecretsToOptions(options map[string]string, spec *volume.Spec, namespace
|
||||
return fmt.Errorf("Cannot get kube client")
|
||||
}
|
||||
|
||||
secrets, err := util.GetSecretForPV(namespace, fv.SecretRef.Name, driverName, host.GetKubeClient())
|
||||
secrets, err := util.GetSecretForPV(secretNamespace, secretName, driverName, host.GetKubeClient())
|
||||
if err != nil {
|
||||
err = fmt.Errorf("Couldn't get secret %v/%v err: %v", namespace, fv.SecretRef.Name, err)
|
||||
err = fmt.Errorf("Couldn't get secret %v/%v err: %v", secretNamespace, secretName, err)
|
||||
return err
|
||||
}
|
||||
for name, data := range secrets {
|
||||
@ -52,15 +55,68 @@ func addSecretsToOptions(options map[string]string, spec *volume.Spec, namespace
|
||||
return nil
|
||||
}
|
||||
|
||||
func getVolumeSource(spec *volume.Spec) (volumeSource *api.FlexVolumeSource, readOnly bool) {
|
||||
var notFlexVolume = fmt.Errorf("not a flex volume")
|
||||
|
||||
func getDriver(spec *volume.Spec) (string, error) {
|
||||
if spec.Volume != nil && spec.Volume.FlexVolume != nil {
|
||||
volumeSource = spec.Volume.FlexVolume
|
||||
readOnly = volumeSource.ReadOnly
|
||||
} else if spec.PersistentVolume != nil {
|
||||
volumeSource = spec.PersistentVolume.Spec.FlexVolume
|
||||
readOnly = spec.ReadOnly
|
||||
return spec.Volume.FlexVolume.Driver, nil
|
||||
}
|
||||
return
|
||||
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
|
||||
return spec.PersistentVolume.Spec.FlexVolume.Driver, nil
|
||||
}
|
||||
return "", notFlexVolume
|
||||
}
|
||||
|
||||
func getFSType(spec *volume.Spec) (string, error) {
|
||||
if spec.Volume != nil && spec.Volume.FlexVolume != nil {
|
||||
return spec.Volume.FlexVolume.FSType, nil
|
||||
}
|
||||
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
|
||||
return spec.PersistentVolume.Spec.FlexVolume.FSType, nil
|
||||
}
|
||||
return "", notFlexVolume
|
||||
}
|
||||
|
||||
func getSecretNameAndNamespace(spec *volume.Spec, podNamespace string) (string, string, error) {
|
||||
if spec.Volume != nil && spec.Volume.FlexVolume != nil {
|
||||
if spec.Volume.FlexVolume.SecretRef == nil {
|
||||
return "", "", nil
|
||||
}
|
||||
return spec.Volume.FlexVolume.SecretRef.Name, podNamespace, nil
|
||||
}
|
||||
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
|
||||
if spec.PersistentVolume.Spec.FlexVolume.SecretRef == nil {
|
||||
return "", "", nil
|
||||
}
|
||||
secretName := spec.PersistentVolume.Spec.FlexVolume.SecretRef.Name
|
||||
secretNamespace := spec.PersistentVolume.Spec.FlexVolume.SecretRef.Namespace
|
||||
if len(secretNamespace) == 0 {
|
||||
secretNamespace = podNamespace
|
||||
}
|
||||
return secretName, secretNamespace, nil
|
||||
}
|
||||
return "", "", notFlexVolume
|
||||
}
|
||||
|
||||
func getReadOnly(spec *volume.Spec) (bool, error) {
|
||||
if spec.Volume != nil && spec.Volume.FlexVolume != nil {
|
||||
return spec.Volume.FlexVolume.ReadOnly, nil
|
||||
}
|
||||
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
|
||||
// ReadOnly is specified at the PV level
|
||||
return spec.ReadOnly, nil
|
||||
}
|
||||
return false, notFlexVolume
|
||||
}
|
||||
|
||||
func getOptions(spec *volume.Spec) (map[string]string, error) {
|
||||
if spec.Volume != nil && spec.Volume.FlexVolume != nil {
|
||||
return spec.Volume.FlexVolume.Options, nil
|
||||
}
|
||||
if spec.PersistentVolume != nil && spec.PersistentVolume.Spec.FlexVolume != nil {
|
||||
return spec.PersistentVolume.Spec.FlexVolume.Options, nil
|
||||
}
|
||||
return nil, notFlexVolume
|
||||
}
|
||||
|
||||
func prepareForMount(mounter mount.Interface, deviceMountPath string) (bool, error) {
|
||||
|
Reference in New Issue
Block a user