@@ -24,14 +24,14 @@ import (
24
24
"fmt"
25
25
26
26
"k8s.io/klog/v2"
27
+ "k8s.io/kubernetes/pkg/volume/csi"
28
+ "k8s.io/kubernetes/pkg/volume/iscsi"
27
29
28
30
// Volume plugins
29
31
"k8s.io/kubernetes/pkg/volume"
30
- "k8s.io/kubernetes/pkg/volume/csi"
31
32
"k8s.io/kubernetes/pkg/volume/fc"
32
33
"k8s.io/kubernetes/pkg/volume/flexvolume"
33
34
"k8s.io/kubernetes/pkg/volume/hostpath"
34
- "k8s.io/kubernetes/pkg/volume/iscsi"
35
35
"k8s.io/kubernetes/pkg/volume/nfs"
36
36
volumeutil "k8s.io/kubernetes/pkg/volume/util"
37
37
@@ -42,19 +42,11 @@ import (
42
42
43
43
// ProbeAttachableVolumePlugins collects all volume plugins for the attach/
44
44
// 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
+ })
58
50
}
59
51
60
52
// GetDynamicPluginProber gets the probers of dynamically discoverable plugins
@@ -66,21 +58,31 @@ func GetDynamicPluginProber(config persistentvolumeconfig.VolumeConfiguration) v
66
58
67
59
// ProbeExpandableVolumePlugins returns volume plugins which are expandable
68
60
func 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
+ })
77
80
}
78
81
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
84
86
85
87
// The list of plugins to probe is decided by this binary, not
86
88
// by dynamic linking or other "magic". Plugins will be analyzed and
@@ -113,14 +115,28 @@ func ProbeControllerVolumePlugins(logger klog.Logger, config persistentvolumecon
113
115
klog .FlushAndExit (klog .ExitFlushTimeout , 1 )
114
116
}
115
117
allPlugins = append (allPlugins , nfs .ProbeVolumePlugins (nfsConfig )... )
118
+ allPlugins = append (allPlugins , fc .ProbeVolumePlugins ()... )
119
+ allPlugins = append (allPlugins , iscsi .ProbeVolumePlugins ()... )
120
+ allPlugins = append (allPlugins , csi .ProbeVolumePlugins ()... )
116
121
117
122
var err error
118
- allPlugins , err = appendExpandableLegacyProviderVolumes (logger , allPlugins , utilfeature .DefaultFeatureGate )
123
+ allPlugins , err = appendLegacyControllerProviders (logger , allPlugins , utilfeature .DefaultFeatureGate )
119
124
if err != nil {
120
125
return allPlugins , err
121
126
}
122
127
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
124
140
}
125
141
126
142
// AttemptToLoadRecycler tries decoding a pod from a filepath for use as a recycler for a volume.
0 commit comments