Skip to content

Commit 9e29f95

Browse files
committed
Refactor controller-manager volume plugins
Most of the volume plugins were removed from k/k. Refactor how KCM controllers initialize the few leftovers.
1 parent cba5a93 commit 9e29f95

File tree

4 files changed

+51
-29
lines changed

4 files changed

+51
-29
lines changed

cmd/kube-controller-manager/app/core.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ func newPersistentVolumeBinderControllerDescriptor() *ControllerDescriptor {
270270

271271
func startPersistentVolumeBinderController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) {
272272
logger := klog.FromContext(ctx)
273-
plugins, err := ProbeControllerVolumePlugins(logger, controllerContext.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration)
273+
plugins, err := ProbeProvisionableRecyclableVolumePlugins(logger, controllerContext.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration)
274274
if err != nil {
275275
return nil, true, fmt.Errorf("failed to probe volume plugins when starting persistentvolume controller: %v", err)
276276
}
@@ -307,7 +307,7 @@ func startPersistentVolumeAttachDetachController(ctx context.Context, controller
307307
csiNodeInformer := controllerContext.InformerFactory.Storage().V1().CSINodes()
308308
csiDriverInformer := controllerContext.InformerFactory.Storage().V1().CSIDrivers()
309309

310-
plugins, err := ProbeAttachableVolumePlugins(logger)
310+
plugins, err := ProbeAttachableVolumePlugins(logger, controllerContext.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration)
311311
if err != nil {
312312
return nil, true, fmt.Errorf("failed to probe volume plugins when starting attach/detach controller: %v", err)
313313
}

cmd/kube-controller-manager/app/plugins.go

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -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,14 +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-
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+
})
5350
}
5451

5552
// GetDynamicPluginProber gets the probers of dynamically discoverable plugins
@@ -61,20 +58,31 @@ func GetDynamicPluginProber(config persistentvolumeconfig.VolumeConfiguration) v
6158

6259
// ProbeExpandableVolumePlugins returns volume plugins which are expandable
6360
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+
})
7165
}
7266

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
7886

7987
// The list of plugins to probe is decided by this binary, not
8088
// by dynamic linking or other "magic". Plugins will be analyzed and
@@ -107,14 +115,28 @@ func ProbeControllerVolumePlugins(logger klog.Logger, config persistentvolumecon
107115
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
108116
}
109117
allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...)
118+
allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
119+
allPlugins = append(allPlugins, iscsi.ProbeVolumePlugins()...)
120+
allPlugins = append(allPlugins, csi.ProbeVolumePlugins()...)
110121

111122
var err error
112-
allPlugins, err = appendExpandableLegacyProviderVolumes(logger, allPlugins, utilfeature.DefaultFeatureGate)
123+
allPlugins, err = appendLegacyControllerProviders(logger, allPlugins, utilfeature.DefaultFeatureGate)
113124
if err != nil {
114125
return allPlugins, err
115126
}
116127

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
118140
}
119141

120142
// AttemptToLoadRecycler tries decoding a pod from a filepath for use as a recycler for a volume.

cmd/kube-controller-manager/app/plugins_providers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type pluginInfo struct {
5353
pluginProbeFunction probeFn
5454
}
5555

56-
func appendExpandableLegacyProviderVolumes(logger klog.Logger, allPlugins []volume.VolumePlugin, featureGate featuregate.FeatureGate) ([]volume.VolumePlugin, error) {
56+
func appendLegacyControllerProviders(logger klog.Logger, allPlugins []volume.VolumePlugin, featureGate featuregate.FeatureGate) ([]volume.VolumePlugin, error) {
5757
pluginMigrationStatus := make(map[string]pluginInfo)
5858
pluginMigrationStatus[plugins.PortworxVolumePluginName] = pluginInfo{pluginMigrationFeature: features.CSIMigrationPortworx, pluginUnregisterFeature: features.InTreePluginPortworxUnregister, pluginProbeFunction: portworx.ProbeVolumePlugins}
5959
var err error

cmd/kube-controller-manager/app/plugins_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func checkPlugins(t *testing.T, got []volume.VolumePlugin, expected []string) {
4040

4141
func TestProbeAttachableVolumePlugins(t *testing.T) {
4242
logger, _ := ktesting.NewTestContext(t)
43-
plugins, err := ProbeAttachableVolumePlugins(logger)
43+
plugins, err := ProbeAttachableVolumePlugins(logger, getConfig())
4444
if err != nil {
4545
t.Fatalf("ProbeAttachableVolumePlugins failed: %s", err)
4646
}
@@ -58,7 +58,7 @@ func TestProbeExpandableVolumePlugins(t *testing.T) {
5858

5959
func TestProbeControllerVolumePlugins(t *testing.T) {
6060
logger, _ := ktesting.NewTestContext(t)
61-
plugins, err := ProbeControllerVolumePlugins(logger, getConfig())
61+
plugins, err := ProbeProvisionableRecyclableVolumePlugins(logger, getConfig())
6262
if err != nil {
6363
t.Fatalf("ProbeControllerVolumePlugins failed: %s", err)
6464
}

0 commit comments

Comments
 (0)