Merge pull request #91307 from yuga711/attach

CSI: Modify VolumeAttachment check to use Informer/Cache
This commit is contained in:
Kubernetes Prow Robot
2020-06-15 08:10:10 -07:00
committed by GitHub
14 changed files with 129 additions and 43 deletions

View File

@@ -111,6 +111,7 @@ func NewAttachDetachController(
pvInformer coreinformers.PersistentVolumeInformer,
csiNodeInformer storageinformersv1.CSINodeInformer,
csiDriverInformer storageinformersv1.CSIDriverInformer,
volumeAttachmentInformer storageinformersv1.VolumeAttachmentInformer,
cloud cloudprovider.Interface,
plugins []volume.VolumePlugin,
prober volume.DynamicPluginProber,
@@ -142,6 +143,9 @@ func NewAttachDetachController(
adc.csiDriverLister = csiDriverInformer.Lister()
adc.csiDriversSynced = csiDriverInformer.Informer().HasSynced
adc.volumeAttachmentLister = volumeAttachmentInformer.Lister()
adc.volumeAttachmentSynced = volumeAttachmentInformer.Informer().HasSynced
if err := adc.volumePluginMgr.InitPlugins(plugins, prober, adc); err != nil {
return nil, fmt.Errorf("Could not initialize volume plugins for Attach/Detach Controller: %+v", err)
}
@@ -254,6 +258,12 @@ type attachDetachController struct {
csiDriverLister storagelistersv1.CSIDriverLister
csiDriversSynced kcache.InformerSynced
// volumeAttachmentLister is the shared volumeAttachment lister used to fetch and store
// VolumeAttachment objects from the API server. It is shared with other controllers
// and therefore the VolumeAttachment objects in its store should be treated as immutable.
volumeAttachmentLister storagelistersv1.VolumeAttachmentLister
volumeAttachmentSynced kcache.InformerSynced
// cloud provider used by volume host
cloud cloudprovider.Interface
@@ -319,6 +329,9 @@ func (adc *attachDetachController) Run(stopCh <-chan struct{}) {
if adc.csiDriversSynced != nil {
synced = append(synced, adc.csiDriversSynced)
}
if adc.volumeAttachmentSynced != nil {
synced = append(synced, adc.volumeAttachmentSynced)
}
if !kcache.WaitForNamedCacheSync("attach detach", stopCh, synced...) {
return
@@ -675,6 +688,10 @@ func (adc *attachDetachController) IsAttachDetachController() bool {
return true
}
func (adc *attachDetachController) VolumeAttachmentLister() storagelistersv1.VolumeAttachmentLister {
return adc.volumeAttachmentLister
}
// VolumeHost implementation
// This is an unfortunate requirement of the current factoring of volume plugin
// initializing code. It requires kubelet specific methods used by the mounting

View File

@@ -48,6 +48,7 @@ func Test_NewAttachDetachController_Positive(t *testing.T) {
informerFactory.Core().V1().PersistentVolumes(),
informerFactory.Storage().V1().CSINodes(),
informerFactory.Storage().V1().CSIDrivers(),
informerFactory.Storage().V1().VolumeAttachments(),
nil, /* cloud */
nil, /* plugins */
nil, /* prober */
@@ -168,6 +169,7 @@ func attachDetachRecoveryTestCase(t *testing.T, extraPods1 []*v1.Pod, extraPods2
informerFactory.Core().V1().PersistentVolumes(),
informerFactory.Storage().V1().CSINodes(),
informerFactory.Storage().V1().CSIDrivers(),
informerFactory.Storage().V1().VolumeAttachments(),
nil, /* cloud */
plugins,
prober,