Merge pull request #106853 from gnufied/disable-exp-backoff-volume-not-inuse
When volume is not marked in-use, do not backoff
This commit is contained in:
@@ -449,6 +449,8 @@ type VolumeHost interface {
|
||||
// Returns the name of the node
|
||||
GetNodeName() types.NodeName
|
||||
|
||||
GetAttachedVolumesFromNodeStatus() (map[v1.UniqueVolumeName]string, error)
|
||||
|
||||
// Returns the event recorder of kubelet.
|
||||
GetEventRecorder() record.EventRecorder
|
||||
|
||||
|
@@ -1655,6 +1655,19 @@ func GetTestKubeletVolumePluginMgr(t *testing.T) (*VolumePluginMgr, *FakeVolumeP
|
||||
return v.GetPluginMgr(), plugins[0].(*FakeVolumePlugin)
|
||||
}
|
||||
|
||||
func GetTestKubeletVolumePluginMgrWithNode(t *testing.T, node *v1.Node) (*VolumePluginMgr, *FakeVolumePlugin) {
|
||||
plugins := ProbeVolumePlugins(VolumeConfig{})
|
||||
v := NewFakeKubeletVolumeHost(
|
||||
t,
|
||||
"", /* rootDir */
|
||||
nil, /* kubeClient */
|
||||
plugins, /* plugins */
|
||||
)
|
||||
v.WithNode(node)
|
||||
|
||||
return v.GetPluginMgr(), plugins[0].(*FakeVolumePlugin)
|
||||
}
|
||||
|
||||
// CreateTestPVC returns a provisionable PVC for tests
|
||||
func CreateTestPVC(capacity string, accessModes []v1.PersistentVolumeAccessMode) *v1.PersistentVolumeClaim {
|
||||
claim := v1.PersistentVolumeClaim{
|
||||
|
@@ -64,6 +64,7 @@ type fakeVolumeHost struct {
|
||||
nodeLabels map[string]string
|
||||
nodeName string
|
||||
subpather subpath.Interface
|
||||
node *v1.Node
|
||||
csiDriverLister storagelistersv1.CSIDriverLister
|
||||
volumeAttachmentLister storagelistersv1.VolumeAttachmentLister
|
||||
informerFactory informers.SharedInformerFactory
|
||||
@@ -153,6 +154,10 @@ func (f *fakeVolumeHost) GetPluginMgr() *VolumePluginMgr {
|
||||
return f.pluginMgr
|
||||
}
|
||||
|
||||
func (f *fakeVolumeHost) GetAttachedVolumesFromNodeStatus() (map[v1.UniqueVolumeName]string, error) {
|
||||
return map[v1.UniqueVolumeName]string{}, nil
|
||||
}
|
||||
|
||||
func (f *fakeVolumeHost) NewWrapperMounter(volName string, spec Spec, pod *v1.Pod, opts VolumeOptions) (Mounter, error) {
|
||||
// The name of wrapper volume is set to "wrapped_{wrapped_volume_name}"
|
||||
wrapperVolumeName := "wrapped_" + volName
|
||||
@@ -305,25 +310,25 @@ type fakeKubeletVolumeHost struct {
|
||||
var _ KubeletVolumeHost = &fakeKubeletVolumeHost{}
|
||||
var _ FakeVolumeHost = &fakeKubeletVolumeHost{}
|
||||
|
||||
func NewFakeKubeletVolumeHost(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin) FakeVolumeHost {
|
||||
func NewFakeKubeletVolumeHost(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin) *fakeKubeletVolumeHost {
|
||||
return newFakeKubeletVolumeHost(t, rootDir, kubeClient, plugins, nil, nil, "", nil, nil)
|
||||
}
|
||||
|
||||
func NewFakeKubeletVolumeHostWithCloudProvider(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin, cloud cloudprovider.Interface) FakeVolumeHost {
|
||||
func NewFakeKubeletVolumeHostWithCloudProvider(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin, cloud cloudprovider.Interface) *fakeKubeletVolumeHost {
|
||||
return newFakeKubeletVolumeHost(t, rootDir, kubeClient, plugins, cloud, nil, "", nil, nil)
|
||||
}
|
||||
|
||||
func NewFakeKubeletVolumeHostWithNodeLabels(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin, labels map[string]string) FakeVolumeHost {
|
||||
func NewFakeKubeletVolumeHostWithNodeLabels(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin, labels map[string]string) *fakeKubeletVolumeHost {
|
||||
volHost := newFakeKubeletVolumeHost(t, rootDir, kubeClient, plugins, nil, nil, "", nil, nil)
|
||||
volHost.nodeLabels = labels
|
||||
return volHost
|
||||
}
|
||||
|
||||
func NewFakeKubeletVolumeHostWithCSINodeName(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin, nodeName string, driverLister storagelistersv1.CSIDriverLister, volumeAttachLister storagelistersv1.VolumeAttachmentLister) FakeVolumeHost {
|
||||
func NewFakeKubeletVolumeHostWithCSINodeName(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin, nodeName string, driverLister storagelistersv1.CSIDriverLister, volumeAttachLister storagelistersv1.VolumeAttachmentLister) *fakeKubeletVolumeHost {
|
||||
return newFakeKubeletVolumeHost(t, rootDir, kubeClient, plugins, nil, nil, nodeName, driverLister, volumeAttachLister)
|
||||
}
|
||||
|
||||
func NewFakeKubeletVolumeHostWithMounterFSType(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin, pathToTypeMap map[string]hostutil.FileType) FakeVolumeHost {
|
||||
func NewFakeKubeletVolumeHostWithMounterFSType(t *testing.T, rootDir string, kubeClient clientset.Interface, plugins []VolumePlugin, pathToTypeMap map[string]hostutil.FileType) *fakeKubeletVolumeHost {
|
||||
return newFakeKubeletVolumeHost(t, rootDir, kubeClient, plugins, nil, pathToTypeMap, "", nil, nil)
|
||||
}
|
||||
|
||||
@@ -351,6 +356,11 @@ func newFakeKubeletVolumeHost(t *testing.T, rootDir string, kubeClient clientset
|
||||
return host
|
||||
}
|
||||
|
||||
func (f *fakeKubeletVolumeHost) WithNode(node *v1.Node) *fakeKubeletVolumeHost {
|
||||
f.node = node
|
||||
return f
|
||||
}
|
||||
|
||||
func (f *fakeKubeletVolumeHost) SetKubeletError(err error) {
|
||||
f.mux.Lock()
|
||||
defer f.mux.Unlock()
|
||||
@@ -362,6 +372,17 @@ func (f *fakeKubeletVolumeHost) GetInformerFactory() informers.SharedInformerFac
|
||||
return f.informerFactory
|
||||
}
|
||||
|
||||
func (f *fakeKubeletVolumeHost) GetAttachedVolumesFromNodeStatus() (map[v1.UniqueVolumeName]string, error) {
|
||||
result := map[v1.UniqueVolumeName]string{}
|
||||
if f.node != nil {
|
||||
for _, av := range f.node.Status.VolumesAttached {
|
||||
result[av.Name] = av.DevicePath
|
||||
}
|
||||
}
|
||||
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (f *fakeKubeletVolumeHost) CSIDriverLister() storagelistersv1.CSIDriverLister {
|
||||
return f.csiDriverLister
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@ limitations under the License.
|
||||
package operationexecutor
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
@@ -418,6 +419,23 @@ const (
|
||||
VolumeNotMounted VolumeMountState = "VolumeNotMounted"
|
||||
)
|
||||
|
||||
type MountPreConditionFailed struct {
|
||||
msg string
|
||||
}
|
||||
|
||||
func (err *MountPreConditionFailed) Error() string {
|
||||
return err.msg
|
||||
}
|
||||
|
||||
func NewMountPreConditionFailedError(msg string) *MountPreConditionFailed {
|
||||
return &MountPreConditionFailed{msg: msg}
|
||||
}
|
||||
|
||||
func IsMountFailedPreconditionError(err error) bool {
|
||||
var failedPreconditionError *MountPreConditionFailed
|
||||
return errors.As(err, &failedPreconditionError)
|
||||
}
|
||||
|
||||
// GenerateMsgDetailed returns detailed msgs for volumes to mount
|
||||
func (volume *VolumeToMount) GenerateMsgDetailed(prefixMsg, suffixMsg string) (detailedMsg string) {
|
||||
detailedStr := fmt.Sprintf("(UniqueName: %q) pod %q (UID: %q)", volume.VolumeName, volume.Pod.Name, volume.Pod.UID)
|
||||
|
@@ -48,9 +48,10 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
unknownVolumePlugin string = "UnknownVolumePlugin"
|
||||
unknownAttachableVolumePlugin string = "UnknownAttachableVolumePlugin"
|
||||
DetachOperationName string = "volume_detach"
|
||||
unknownVolumePlugin string = "UnknownVolumePlugin"
|
||||
unknownAttachableVolumePlugin string = "UnknownAttachableVolumePlugin"
|
||||
DetachOperationName string = "volume_detach"
|
||||
VerifyControllerAttachedVolumeOpName string = "verify_controller_attached_volume"
|
||||
)
|
||||
|
||||
// InTreeToCSITranslator contains methods required to check migratable status
|
||||
@@ -1514,6 +1515,20 @@ func (og *operationGenerator) GenerateVerifyControllerAttachedVolumeFunc(
|
||||
return volumetypes.GeneratedOperations{}, volumeToMount.GenerateErrorDetailed("VerifyControllerAttachedVolume.FindPluginBySpec failed", err)
|
||||
}
|
||||
|
||||
// For attachable volume types, lets check if volume is attached by reading from node lister.
|
||||
// This would avoid exponential back-off and creation of goroutine unnecessarily. We still
|
||||
// verify status of attached volume by directly reading from API server later on.This is necessarily
|
||||
// to ensure any race conditions because of cached state in the informer.
|
||||
if volumeToMount.PluginIsAttachable {
|
||||
cachedAttachedVolumes, _ := og.volumePluginMgr.Host.GetAttachedVolumesFromNodeStatus()
|
||||
if cachedAttachedVolumes != nil {
|
||||
_, volumeFound := cachedAttachedVolumes[volumeToMount.VolumeName]
|
||||
if !volumeFound {
|
||||
return volumetypes.GeneratedOperations{}, NewMountPreConditionFailedError(fmt.Sprintf("volume %s is not yet in node's status", volumeToMount.VolumeName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
verifyControllerAttachedVolumeFunc := func() volumetypes.OperationContext {
|
||||
migrated := getMigratedStatusBySpec(volumeToMount.VolumeSpec)
|
||||
if !volumeToMount.PluginIsAttachable {
|
||||
@@ -1579,7 +1594,7 @@ func (og *operationGenerator) GenerateVerifyControllerAttachedVolumeFunc(
|
||||
}
|
||||
|
||||
return volumetypes.GeneratedOperations{
|
||||
OperationName: "verify_controller_attached_volume",
|
||||
OperationName: VerifyControllerAttachedVolumeOpName,
|
||||
OperationFunc: verifyControllerAttachedVolumeFunc,
|
||||
CompleteFunc: util.OperationCompleteHook(util.GetFullQualifiedPluginNameForVolume(volumePlugin.GetPluginName(), volumeToMount.VolumeSpec), "verify_controller_attached_volume"),
|
||||
EventRecorderFunc: nil, // nil because we do not want to generate event on error
|
||||
|
Reference in New Issue
Block a user