@@ -24,14 +24,14 @@ import (
2424 "fmt"
2525
2626 "k8s.io/klog/v2"
27+ "k8s.io/kubernetes/pkg/volume/csi"
28+ "k8s.io/kubernetes/pkg/volume/iscsi"
2729
2830 // Volume plugins
2931 "k8s.io/kubernetes/pkg/volume"
30- "k8s.io/kubernetes/pkg/volume/csi"
3132 "k8s.io/kubernetes/pkg/volume/fc"
3233 "k8s.io/kubernetes/pkg/volume/flexvolume"
3334 "k8s.io/kubernetes/pkg/volume/hostpath"
34- "k8s.io/kubernetes/pkg/volume/iscsi"
3535 "k8s.io/kubernetes/pkg/volume/nfs"
3636 volumeutil "k8s.io/kubernetes/pkg/volume/util"
3737
@@ -42,19 +42,11 @@ import (
4242
4343// ProbeAttachableVolumePlugins collects all volume plugins for the attach/
4444// detach controller.
45- // The list of plugins is manually compiled. This code and the plugin
46- // initialization code for kubelet really, really need a through refactor.
47- func ProbeAttachableVolumePlugins (logger klog.Logger ) ([]volume.VolumePlugin , error ) {
48- var err error
49- allPlugins := []volume.VolumePlugin {}
50- allPlugins , err = appendAttachableLegacyProviderVolumes (logger , allPlugins , utilfeature .DefaultFeatureGate )
51- if err != nil {
52- return allPlugins , err
53- }
54- allPlugins = append (allPlugins , fc .ProbeVolumePlugins ()... )
55- allPlugins = append (allPlugins , iscsi .ProbeVolumePlugins ()... )
56- allPlugins = append (allPlugins , csi .ProbeVolumePlugins ()... )
57- return allPlugins , nil
45+ func ProbeAttachableVolumePlugins (logger klog.Logger , config persistentvolumeconfig.VolumeConfiguration ) ([]volume.VolumePlugin , error ) {
46+ return probeControllerVolumePlugins (logger , config , func (plugin volume.VolumePlugin ) bool {
47+ _ , ok := plugin .(volume.AttachableVolumePlugin )
48+ return ok
49+ })
5850}
5951
6052// GetDynamicPluginProber gets the probers of dynamically discoverable plugins
@@ -66,21 +58,31 @@ func GetDynamicPluginProber(config persistentvolumeconfig.VolumeConfiguration) v
6658
6759// ProbeExpandableVolumePlugins returns volume plugins which are expandable
6860func ProbeExpandableVolumePlugins (logger klog.Logger , config persistentvolumeconfig.VolumeConfiguration ) ([]volume.VolumePlugin , error ) {
69- var err error
70- allPlugins := []volume.VolumePlugin {}
71- allPlugins , err = appendExpandableLegacyProviderVolumes (logger , allPlugins , utilfeature .DefaultFeatureGate )
72- if err != nil {
73- return allPlugins , err
74- }
75- allPlugins = append (allPlugins , fc .ProbeVolumePlugins ()... )
76- return allPlugins , nil
61+ return probeControllerVolumePlugins (logger , config , func (plugin volume.VolumePlugin ) bool {
62+ _ , ok := plugin .(volume.ExpandableVolumePlugin )
63+ return ok
64+ })
65+ }
66+
67+ func ProbeProvisionableRecyclableVolumePlugins (logger klog.Logger , config persistentvolumeconfig.VolumeConfiguration ) ([]volume.VolumePlugin , error ) {
68+ return probeControllerVolumePlugins (logger , config , func (plugin volume.VolumePlugin ) bool {
69+ if _ , ok := plugin .(volume.ProvisionableVolumePlugin ); ok {
70+ return true
71+ }
72+ if _ , ok := plugin .(volume.DeletableVolumePlugin ); ok {
73+ return true
74+ }
75+ if _ , ok := plugin .(volume.RecyclableVolumePlugin ); ok {
76+ return true
77+ }
78+ return false
79+ })
7780}
7881
79- // ProbeControllerVolumePlugins collects all persistent volume plugins into an
80- // easy to use list. Only volume plugins that implement any of
81- // provisioner/recycler/deleter interface should be returned.
82- func ProbeControllerVolumePlugins (logger klog.Logger , config persistentvolumeconfig.VolumeConfiguration ) ([]volume.VolumePlugin , error ) {
83- allPlugins := []volume.VolumePlugin {}
82+ // probeControllerVolumePlugins collects all persistent volume plugins
83+ // used by KCM controllers into an easy to use list.
84+ func probeControllerVolumePlugins (logger klog.Logger , config persistentvolumeconfig.VolumeConfiguration , filter func (plugin volume.VolumePlugin ) bool ) ([]volume.VolumePlugin , error ) {
85+ var allPlugins []volume.VolumePlugin
8486
8587 // The list of plugins to probe is decided by this binary, not
8688 // by dynamic linking or other "magic". Plugins will be analyzed and
@@ -113,14 +115,28 @@ func ProbeControllerVolumePlugins(logger klog.Logger, config persistentvolumecon
113115 klog .FlushAndExit (klog .ExitFlushTimeout , 1 )
114116 }
115117 allPlugins = append (allPlugins , nfs .ProbeVolumePlugins (nfsConfig )... )
118+ allPlugins = append (allPlugins , fc .ProbeVolumePlugins ()... )
119+ allPlugins = append (allPlugins , iscsi .ProbeVolumePlugins ()... )
120+ allPlugins = append (allPlugins , csi .ProbeVolumePlugins ()... )
116121
117122 var err error
118- allPlugins , err = appendExpandableLegacyProviderVolumes (logger , allPlugins , utilfeature .DefaultFeatureGate )
123+ allPlugins , err = appendLegacyControllerProviders (logger , allPlugins , utilfeature .DefaultFeatureGate )
119124 if err != nil {
120125 return allPlugins , err
121126 }
122127
123- return allPlugins , nil
128+ var filteredPlugins []volume.VolumePlugin
129+ if filter == nil {
130+ filteredPlugins = allPlugins
131+ } else {
132+ for _ , plugin := range allPlugins {
133+ if filter (plugin ) {
134+ filteredPlugins = append (filteredPlugins , plugin )
135+ }
136+ }
137+ }
138+
139+ return filteredPlugins , nil
124140}
125141
126142// AttemptToLoadRecycler tries decoding a pod from a filepath for use as a recycler for a volume.
0 commit comments