Implement return status codes

This commit is contained in:
Hemant Kumar 2019-09-24 18:25:33 -04:00
parent 50dbcb3e00
commit dc9e64c31e
16 changed files with 100 additions and 2 deletions

View File

@ -32,6 +32,7 @@ import (
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util" "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
) )
const TestPluginName = "kubernetes.io/testPlugin" const TestPluginName = "kubernetes.io/testPlugin"
@ -445,6 +446,11 @@ func (attacher *testPluginAttacher) MountDevice(spec *volume.Spec, devicePath st
return nil return nil
} }
func (attacher *testPluginAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
// Detacher // Detacher
type testPluginDetacher struct { type testPluginDetacher struct {
detachedVolumeMap map[string][]string detachedVolumeMap map[string][]string

View File

@ -34,6 +34,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumeutil "k8s.io/kubernetes/pkg/volume/util" volumeutil "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
"k8s.io/legacy-cloud-providers/aws" "k8s.io/legacy-cloud-providers/aws"
) )
@ -250,6 +251,11 @@ func (attacher *awsElasticBlockStoreAttacher) MountDevice(spec *volume.Spec, dev
return nil return nil
} }
func (attacher *awsElasticBlockStoreAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
type awsElasticBlockStoreDetacher struct { type awsElasticBlockStoreDetacher struct {
mounter mount.Interface mounter mount.Interface
awsVolumes aws.Volumes awsVolumes aws.Volumes

View File

@ -37,6 +37,7 @@ import (
cloudprovider "k8s.io/cloud-provider" cloudprovider "k8s.io/cloud-provider"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util" "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
"k8s.io/legacy-cloud-providers/azure" "k8s.io/legacy-cloud-providers/azure"
) )
@ -259,6 +260,11 @@ func (attacher *azureDiskAttacher) MountDevice(spec *volume.Spec, devicePath str
return nil return nil
} }
func (d *azureDiskAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := d.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
// Detach detaches disk from Azure VM. // Detach detaches disk from Azure VM.
func (d *azureDiskDetacher) Detach(diskURI string, nodeName types.NodeName) error { func (d *azureDiskDetacher) Detach(diskURI string, nodeName types.NodeName) error {
if diskURI == "" { if diskURI == "" {

View File

@ -34,6 +34,7 @@ import (
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumeutil "k8s.io/kubernetes/pkg/volume/util" volumeutil "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
) )
type cinderDiskAttacher struct { type cinderDiskAttacher struct {
@ -303,6 +304,11 @@ func (attacher *cinderDiskAttacher) MountDevice(spec *volume.Spec, devicePath st
return nil return nil
} }
func (attacher *cinderDiskAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
type cinderDiskDetacher struct { type cinderDiskDetacher struct {
mounter mount.Interface mounter mount.Interface
cinderProvider BlockStorageProvider cinderProvider BlockStorageProvider

View File

@ -341,6 +341,11 @@ func (c *csiAttacher) MountDevice(spec *volume.Spec, devicePath string, deviceMo
return nil return nil
} }
func (c *csiAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := c.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
var _ volume.Detacher = &csiAttacher{} var _ volume.Detacher = &csiAttacher{}
var _ volume.DeviceUnmounter = &csiAttacher{} var _ volume.DeviceUnmounter = &csiAttacher{}

View File

@ -32,6 +32,7 @@ import (
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumeutil "k8s.io/kubernetes/pkg/volume/util" volumeutil "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
) )
type fcAttacher struct { type fcAttacher struct {
@ -131,6 +132,11 @@ func (attacher *fcAttacher) MountDevice(spec *volume.Spec, devicePath string, de
return nil return nil
} }
func (attacher *fcAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
type fcDetacher struct { type fcDetacher struct {
mounter mount.Interface mounter mount.Interface
manager diskManager manager diskManager

View File

@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/klog" "k8s.io/klog"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
) )
type flexVolumeAttacher struct { type flexVolumeAttacher struct {
@ -97,6 +98,11 @@ func (a *flexVolumeAttacher) MountDevice(spec *volume.Spec, devicePath string, d
return err return err
} }
func (attacher *flexVolumeAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
func (a *flexVolumeAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) { func (a *flexVolumeAttacher) VolumesAreAttached(specs []*volume.Spec, nodeName types.NodeName) (map[*volume.Spec]bool, error) {
volumesAttachedCheck := make(map[*volume.Spec]bool) volumesAttachedCheck := make(map[*volume.Spec]bool)
for _, spec := range specs { for _, spec := range specs {

View File

@ -38,6 +38,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets" "k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumeutil "k8s.io/kubernetes/pkg/volume/util" volumeutil "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
"k8s.io/legacy-cloud-providers/gce" "k8s.io/legacy-cloud-providers/gce"
) )
@ -328,6 +329,11 @@ func (attacher *gcePersistentDiskAttacher) MountDevice(spec *volume.Spec, device
return nil return nil
} }
func (attacher *gcePersistentDiskAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
type gcePersistentDiskDetacher struct { type gcePersistentDiskDetacher struct {
host volume.VolumeHost host volume.VolumeHost
gceDisks gce.Disks gceDisks gce.Disks

View File

@ -31,6 +31,8 @@ import (
"k8s.io/kubernetes/pkg/features" "k8s.io/kubernetes/pkg/features"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumeutil "k8s.io/kubernetes/pkg/volume/util" volumeutil "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
"k8s.io/utils/keymutex"
) )
type iscsiAttacher struct { type iscsiAttacher struct {
@ -134,6 +136,11 @@ func (attacher *iscsiAttacher) MountDevice(spec *volume.Spec, devicePath string,
return nil return nil
} }
func (attacher *iscsiAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
type iscsiDetacher struct { type iscsiDetacher struct {
host volume.VolumeHost host volume.VolumeHost
mounter mount.Interface mounter mount.Interface

View File

@ -33,6 +33,7 @@ import (
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
"k8s.io/kubernetes/pkg/volume/util" "k8s.io/kubernetes/pkg/volume/util"
"k8s.io/kubernetes/pkg/volume/util/hostutil" "k8s.io/kubernetes/pkg/volume/util/hostutil"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
"k8s.io/kubernetes/pkg/volume/validation" "k8s.io/kubernetes/pkg/volume/validation"
"k8s.io/utils/keymutex" "k8s.io/utils/keymutex"
"k8s.io/utils/mount" "k8s.io/utils/mount"
@ -370,6 +371,11 @@ func (dm *deviceMounter) MountDevice(spec *volume.Spec, devicePath string, devic
} }
} }
func (dm *deviceMounter) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := dm.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
func getVolumeSourceFSType(spec *volume.Spec) (string, error) { func getVolumeSourceFSType(spec *volume.Spec) (string, error) {
if spec.PersistentVolume != nil && if spec.PersistentVolume != nil &&
spec.PersistentVolume.Spec.Local != nil { spec.PersistentVolume.Spec.Local != nil {

View File

@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volutil "k8s.io/kubernetes/pkg/volume/util" volutil "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
) )
// NewAttacher implements AttachableVolumePlugin.NewAttacher. // NewAttacher implements AttachableVolumePlugin.NewAttacher.
@ -184,6 +185,11 @@ func (attacher *rbdAttacher) MountDevice(spec *volume.Spec, devicePath string, d
return nil return nil
} }
func (attacher *rbdAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
// rbdDetacher implements volume.Detacher interface. // rbdDetacher implements volume.Detacher interface.
type rbdDetacher struct { type rbdDetacher struct {
plugin *rbdPlugin plugin *rbdPlugin

View File

@ -1054,6 +1054,11 @@ func (fv *FakeVolume) MountDevice(spec *Spec, devicePath string, deviceMountPath
return nil return nil
} }
func (fv *FakeVolume) MountDeviceWithStatusTracking(spec *Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := fv.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
func (fv *FakeVolume) GetMountDeviceCallCount() int { func (fv *FakeVolume) GetMountDeviceCallCount() int {
fv.RLock() fv.RLock()
defer fv.RUnlock() defer fv.RUnlock()

View File

@ -575,12 +575,12 @@ func (og *operationGenerator) GenerateMountVolumeFunc(
} }
// Mount device to global mount path // Mount device to global mount path
err = volumeDeviceMounter.MountDevice( operationState, err := volumeDeviceMounter.MountDeviceWithStatusTracking(
volumeToMount.VolumeSpec, volumeToMount.VolumeSpec,
devicePath, devicePath,
deviceMountPath) deviceMountPath)
if err != nil { if err != nil {
if volumetypes.IsOperationTimeOutError(err) { if operationState == volumetypes.OperationInProgress {
markDeviceUncertainError := actualStateOfWorld.MarkDeviceAsUncertain(volumeToMount.VolumeName, devicePath, deviceMountPath) markDeviceUncertainError := actualStateOfWorld.MarkDeviceAsUncertain(volumeToMount.VolumeName, devicePath, deviceMountPath)
if markDeviceUncertainError != nil { if markDeviceUncertainError != nil {
klog.Infof("MountVolume.MarkDeviceAsUncertain failed with %v", markDeviceUncertainError) klog.Infof("MountVolume.MarkDeviceAsUncertain failed with %v", markDeviceUncertainError)

View File

@ -51,6 +51,23 @@ func (o *GeneratedOperations) Run() (eventErr, detailedErr error) {
return o.OperationFunc() return o.OperationFunc()
} }
type OperationStatus string
const (
// OperationFinished means volume operation has been finished
OperationFinished OperationStatus = "Finished"
// OperationInProgress means volume operation has been started and
// is in-progress. This state does not indicate if operation will succeed or fail but
// merely it has been started and in in-progress.
OperationInProgress OperationStatus = "InProgress"
// OperationStateNoChange indicates it is unchanged from previous state.
// This can be used to indicate transient failures for an operation which
// was in-progress previously.
OperationStateNoChange OperationStatus = "NoChange"
)
// OperationTimedOutError indicates a particular volume operation has timed out. // OperationTimedOutError indicates a particular volume operation has timed out.
type OperationTimedOutError struct { type OperationTimedOutError struct {
msg string msg string

View File

@ -23,6 +23,7 @@ import (
"k8s.io/apimachinery/pkg/api/resource" "k8s.io/apimachinery/pkg/api/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
) )
// Volume represents a directory used by pods or hosts on a node. All method // Volume represents a directory used by pods or hosts on a node. All method
@ -248,6 +249,9 @@ type DeviceMounter interface {
// individual pods can then bind mount // individual pods can then bind mount
// Note that devicePath can be empty if the volume plugin does not implement any of Attach and WaitForAttach methods. // Note that devicePath can be empty if the volume plugin does not implement any of Attach and WaitForAttach methods.
MountDevice(spec *Spec, devicePath string, deviceMountPath string) error MountDevice(spec *Spec, devicePath string, deviceMountPath string) error
// MountDeviceWithStatusTracking is same as MountDevice except status of mount operation is also returned
MountDeviceWithStatusTracking(spec *Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error)
} }
type BulkVolumeVerifier interface { type BulkVolumeVerifier interface {

View File

@ -33,6 +33,7 @@ import (
"k8s.io/apimachinery/pkg/types" "k8s.io/apimachinery/pkg/types"
"k8s.io/kubernetes/pkg/volume" "k8s.io/kubernetes/pkg/volume"
volumeutil "k8s.io/kubernetes/pkg/volume/util" volumeutil "k8s.io/kubernetes/pkg/volume/util"
volumetypes "k8s.io/kubernetes/pkg/volume/util/types"
"k8s.io/legacy-cloud-providers/vsphere" "k8s.io/legacy-cloud-providers/vsphere"
) )
@ -248,6 +249,11 @@ func (attacher *vsphereVMDKAttacher) MountDevice(spec *volume.Spec, devicePath s
return nil return nil
} }
func (attacher *vsphereVMDKAttacher) MountDeviceWithStatusTracking(spec *volume.Spec, devicePath string, deviceMountPath string) (volumetypes.OperationStatus, error) {
err := attacher.MountDevice(spec, devicePath, deviceMountPath)
return volumetypes.OperationFinished, err
}
type vsphereVMDKDetacher struct { type vsphereVMDKDetacher struct {
mounter mount.Interface mounter mount.Interface
vsphereVolumes vsphere.Volumes vsphereVolumes vsphere.Volumes