@@ -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,14 +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
- allPlugins := []volume.VolumePlugin {}
49
- allPlugins = append (allPlugins , fc .ProbeVolumePlugins ()... )
50
- allPlugins = append (allPlugins , iscsi .ProbeVolumePlugins ()... )
51
- allPlugins = append (allPlugins , csi .ProbeVolumePlugins ()... )
52
- 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
+ })
53
50
}
54
51
55
52
// GetDynamicPluginProber gets the probers of dynamically discoverable plugins
@@ -61,20 +58,31 @@ func GetDynamicPluginProber(config persistentvolumeconfig.VolumeConfiguration) v
61
58
62
59
// ProbeExpandableVolumePlugins returns volume plugins which are expandable
63
60
func ProbeExpandableVolumePlugins (logger klog.Logger , config persistentvolumeconfig.VolumeConfiguration ) ([]volume.VolumePlugin , error ) {
64
- var err error
65
- allPlugins := []volume.VolumePlugin {}
66
- allPlugins , err = appendExpandableLegacyProviderVolumes (logger , allPlugins , utilfeature .DefaultFeatureGate )
67
- if err != nil {
68
- return allPlugins , err
69
- }
70
- return allPlugins , nil
61
+ return probeControllerVolumePlugins (logger , config , func (plugin volume.VolumePlugin ) bool {
62
+ _ , ok := plugin .(volume.ExpandableVolumePlugin )
63
+ return ok
64
+ })
71
65
}
72
66
73
- // ProbeControllerVolumePlugins collects all persistent volume plugins into an
74
- // easy to use list. Only volume plugins that implement any of
75
- // provisioner/recycler/deleter interface should be returned.
76
- func ProbeControllerVolumePlugins (logger klog.Logger , config persistentvolumeconfig.VolumeConfiguration ) ([]volume.VolumePlugin , error ) {
77
- allPlugins := []volume.VolumePlugin {}
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
+ })
80
+ }
81
+
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
78
86
79
87
// The list of plugins to probe is decided by this binary, not
80
88
// by dynamic linking or other "magic". Plugins will be analyzed and
@@ -107,14 +115,28 @@ func ProbeControllerVolumePlugins(logger klog.Logger, config persistentvolumecon
107
115
klog .FlushAndExit (klog .ExitFlushTimeout , 1 )
108
116
}
109
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 ()... )
110
121
111
122
var err error
112
- allPlugins , err = appendExpandableLegacyProviderVolumes (logger , allPlugins , utilfeature .DefaultFeatureGate )
123
+ allPlugins , err = appendLegacyControllerProviders (logger , allPlugins , utilfeature .DefaultFeatureGate )
113
124
if err != nil {
114
125
return allPlugins , err
115
126
}
116
127
117
- 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
118
140
}
119
141
120
142
// AttemptToLoadRecycler tries decoding a pod from a filepath for use as a recycler for a volume.
0 commit comments