mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-09 03:57:41 +00:00
Refactor controller-manager volume plugins
Most of the volume plugins were removed from k/k. Refactor how KCM controllers initialize the few leftovers.
This commit is contained in:
parent
cba5a93468
commit
9e29f95618
@ -270,7 +270,7 @@ func newPersistentVolumeBinderControllerDescriptor() *ControllerDescriptor {
|
|||||||
|
|
||||||
func startPersistentVolumeBinderController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) {
|
func startPersistentVolumeBinderController(ctx context.Context, controllerContext ControllerContext, controllerName string) (controller.Interface, bool, error) {
|
||||||
logger := klog.FromContext(ctx)
|
logger := klog.FromContext(ctx)
|
||||||
plugins, err := ProbeControllerVolumePlugins(logger, controllerContext.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration)
|
plugins, err := ProbeProvisionableRecyclableVolumePlugins(logger, controllerContext.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, true, fmt.Errorf("failed to probe volume plugins when starting persistentvolume controller: %v", err)
|
return nil, true, fmt.Errorf("failed to probe volume plugins when starting persistentvolume controller: %v", err)
|
||||||
}
|
}
|
||||||
@ -307,7 +307,7 @@ func startPersistentVolumeAttachDetachController(ctx context.Context, controller
|
|||||||
csiNodeInformer := controllerContext.InformerFactory.Storage().V1().CSINodes()
|
csiNodeInformer := controllerContext.InformerFactory.Storage().V1().CSINodes()
|
||||||
csiDriverInformer := controllerContext.InformerFactory.Storage().V1().CSIDrivers()
|
csiDriverInformer := controllerContext.InformerFactory.Storage().V1().CSIDrivers()
|
||||||
|
|
||||||
plugins, err := ProbeAttachableVolumePlugins(logger)
|
plugins, err := ProbeAttachableVolumePlugins(logger, controllerContext.ComponentConfig.PersistentVolumeBinderController.VolumeConfiguration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, true, fmt.Errorf("failed to probe volume plugins when starting attach/detach controller: %v", err)
|
return nil, true, fmt.Errorf("failed to probe volume plugins when starting attach/detach controller: %v", err)
|
||||||
}
|
}
|
||||||
|
@ -24,14 +24,14 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"k8s.io/klog/v2"
|
"k8s.io/klog/v2"
|
||||||
|
"k8s.io/kubernetes/pkg/volume/csi"
|
||||||
|
"k8s.io/kubernetes/pkg/volume/iscsi"
|
||||||
|
|
||||||
// Volume plugins
|
// Volume plugins
|
||||||
"k8s.io/kubernetes/pkg/volume"
|
"k8s.io/kubernetes/pkg/volume"
|
||||||
"k8s.io/kubernetes/pkg/volume/csi"
|
|
||||||
"k8s.io/kubernetes/pkg/volume/fc"
|
"k8s.io/kubernetes/pkg/volume/fc"
|
||||||
"k8s.io/kubernetes/pkg/volume/flexvolume"
|
"k8s.io/kubernetes/pkg/volume/flexvolume"
|
||||||
"k8s.io/kubernetes/pkg/volume/hostpath"
|
"k8s.io/kubernetes/pkg/volume/hostpath"
|
||||||
"k8s.io/kubernetes/pkg/volume/iscsi"
|
|
||||||
"k8s.io/kubernetes/pkg/volume/nfs"
|
"k8s.io/kubernetes/pkg/volume/nfs"
|
||||||
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
volumeutil "k8s.io/kubernetes/pkg/volume/util"
|
||||||
|
|
||||||
@ -42,14 +42,11 @@ import (
|
|||||||
|
|
||||||
// ProbeAttachableVolumePlugins collects all volume plugins for the attach/
|
// ProbeAttachableVolumePlugins collects all volume plugins for the attach/
|
||||||
// detach controller.
|
// detach controller.
|
||||||
// The list of plugins is manually compiled. This code and the plugin
|
func ProbeAttachableVolumePlugins(logger klog.Logger, config persistentvolumeconfig.VolumeConfiguration) ([]volume.VolumePlugin, error) {
|
||||||
// initialization code for kubelet really, really need a through refactor.
|
return probeControllerVolumePlugins(logger, config, func(plugin volume.VolumePlugin) bool {
|
||||||
func ProbeAttachableVolumePlugins(logger klog.Logger) ([]volume.VolumePlugin, error) {
|
_, ok := plugin.(volume.AttachableVolumePlugin)
|
||||||
allPlugins := []volume.VolumePlugin{}
|
return ok
|
||||||
allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
|
})
|
||||||
allPlugins = append(allPlugins, iscsi.ProbeVolumePlugins()...)
|
|
||||||
allPlugins = append(allPlugins, csi.ProbeVolumePlugins()...)
|
|
||||||
return allPlugins, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDynamicPluginProber gets the probers of dynamically discoverable plugins
|
// GetDynamicPluginProber gets the probers of dynamically discoverable plugins
|
||||||
@ -61,20 +58,31 @@ func GetDynamicPluginProber(config persistentvolumeconfig.VolumeConfiguration) v
|
|||||||
|
|
||||||
// ProbeExpandableVolumePlugins returns volume plugins which are expandable
|
// ProbeExpandableVolumePlugins returns volume plugins which are expandable
|
||||||
func ProbeExpandableVolumePlugins(logger klog.Logger, config persistentvolumeconfig.VolumeConfiguration) ([]volume.VolumePlugin, error) {
|
func ProbeExpandableVolumePlugins(logger klog.Logger, config persistentvolumeconfig.VolumeConfiguration) ([]volume.VolumePlugin, error) {
|
||||||
var err error
|
return probeControllerVolumePlugins(logger, config, func(plugin volume.VolumePlugin) bool {
|
||||||
allPlugins := []volume.VolumePlugin{}
|
_, ok := plugin.(volume.ExpandableVolumePlugin)
|
||||||
allPlugins, err = appendExpandableLegacyProviderVolumes(logger, allPlugins, utilfeature.DefaultFeatureGate)
|
return ok
|
||||||
if err != nil {
|
})
|
||||||
return allPlugins, err
|
|
||||||
}
|
|
||||||
return allPlugins, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProbeControllerVolumePlugins collects all persistent volume plugins into an
|
func ProbeProvisionableRecyclableVolumePlugins(logger klog.Logger, config persistentvolumeconfig.VolumeConfiguration) ([]volume.VolumePlugin, error) {
|
||||||
// easy to use list. Only volume plugins that implement any of
|
return probeControllerVolumePlugins(logger, config, func(plugin volume.VolumePlugin) bool {
|
||||||
// provisioner/recycler/deleter interface should be returned.
|
if _, ok := plugin.(volume.ProvisionableVolumePlugin); ok {
|
||||||
func ProbeControllerVolumePlugins(logger klog.Logger, config persistentvolumeconfig.VolumeConfiguration) ([]volume.VolumePlugin, error) {
|
return true
|
||||||
allPlugins := []volume.VolumePlugin{}
|
}
|
||||||
|
if _, ok := plugin.(volume.DeletableVolumePlugin); ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if _, ok := plugin.(volume.RecyclableVolumePlugin); ok {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// probeControllerVolumePlugins collects all persistent volume plugins
|
||||||
|
// used by KCM controllers into an easy to use list.
|
||||||
|
func probeControllerVolumePlugins(logger klog.Logger, config persistentvolumeconfig.VolumeConfiguration, filter func(plugin volume.VolumePlugin) bool) ([]volume.VolumePlugin, error) {
|
||||||
|
var allPlugins []volume.VolumePlugin
|
||||||
|
|
||||||
// The list of plugins to probe is decided by this binary, not
|
// The list of plugins to probe is decided by this binary, not
|
||||||
// by dynamic linking or other "magic". Plugins will be analyzed and
|
// by dynamic linking or other "magic". Plugins will be analyzed and
|
||||||
@ -107,14 +115,28 @@ func ProbeControllerVolumePlugins(logger klog.Logger, config persistentvolumecon
|
|||||||
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
|
klog.FlushAndExit(klog.ExitFlushTimeout, 1)
|
||||||
}
|
}
|
||||||
allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...)
|
allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...)
|
||||||
|
allPlugins = append(allPlugins, fc.ProbeVolumePlugins()...)
|
||||||
|
allPlugins = append(allPlugins, iscsi.ProbeVolumePlugins()...)
|
||||||
|
allPlugins = append(allPlugins, csi.ProbeVolumePlugins()...)
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
allPlugins, err = appendExpandableLegacyProviderVolumes(logger, allPlugins, utilfeature.DefaultFeatureGate)
|
allPlugins, err = appendLegacyControllerProviders(logger, allPlugins, utilfeature.DefaultFeatureGate)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return allPlugins, err
|
return allPlugins, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return allPlugins, nil
|
var filteredPlugins []volume.VolumePlugin
|
||||||
|
if filter == nil {
|
||||||
|
filteredPlugins = allPlugins
|
||||||
|
} else {
|
||||||
|
for _, plugin := range allPlugins {
|
||||||
|
if filter(plugin) {
|
||||||
|
filteredPlugins = append(filteredPlugins, plugin)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return filteredPlugins, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// AttemptToLoadRecycler tries decoding a pod from a filepath for use as a recycler for a volume.
|
// AttemptToLoadRecycler tries decoding a pod from a filepath for use as a recycler for a volume.
|
||||||
|
@ -53,7 +53,7 @@ type pluginInfo struct {
|
|||||||
pluginProbeFunction probeFn
|
pluginProbeFunction probeFn
|
||||||
}
|
}
|
||||||
|
|
||||||
func appendExpandableLegacyProviderVolumes(logger klog.Logger, allPlugins []volume.VolumePlugin, featureGate featuregate.FeatureGate) ([]volume.VolumePlugin, error) {
|
func appendLegacyControllerProviders(logger klog.Logger, allPlugins []volume.VolumePlugin, featureGate featuregate.FeatureGate) ([]volume.VolumePlugin, error) {
|
||||||
pluginMigrationStatus := make(map[string]pluginInfo)
|
pluginMigrationStatus := make(map[string]pluginInfo)
|
||||||
pluginMigrationStatus[plugins.PortworxVolumePluginName] = pluginInfo{pluginMigrationFeature: features.CSIMigrationPortworx, pluginUnregisterFeature: features.InTreePluginPortworxUnregister, pluginProbeFunction: portworx.ProbeVolumePlugins}
|
pluginMigrationStatus[plugins.PortworxVolumePluginName] = pluginInfo{pluginMigrationFeature: features.CSIMigrationPortworx, pluginUnregisterFeature: features.InTreePluginPortworxUnregister, pluginProbeFunction: portworx.ProbeVolumePlugins}
|
||||||
var err error
|
var err error
|
||||||
|
@ -40,7 +40,7 @@ func checkPlugins(t *testing.T, got []volume.VolumePlugin, expected []string) {
|
|||||||
|
|
||||||
func TestProbeAttachableVolumePlugins(t *testing.T) {
|
func TestProbeAttachableVolumePlugins(t *testing.T) {
|
||||||
logger, _ := ktesting.NewTestContext(t)
|
logger, _ := ktesting.NewTestContext(t)
|
||||||
plugins, err := ProbeAttachableVolumePlugins(logger)
|
plugins, err := ProbeAttachableVolumePlugins(logger, getConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ProbeAttachableVolumePlugins failed: %s", err)
|
t.Fatalf("ProbeAttachableVolumePlugins failed: %s", err)
|
||||||
}
|
}
|
||||||
@ -58,7 +58,7 @@ func TestProbeExpandableVolumePlugins(t *testing.T) {
|
|||||||
|
|
||||||
func TestProbeControllerVolumePlugins(t *testing.T) {
|
func TestProbeControllerVolumePlugins(t *testing.T) {
|
||||||
logger, _ := ktesting.NewTestContext(t)
|
logger, _ := ktesting.NewTestContext(t)
|
||||||
plugins, err := ProbeControllerVolumePlugins(logger, getConfig())
|
plugins, err := ProbeProvisionableRecyclableVolumePlugins(logger, getConfig())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("ProbeControllerVolumePlugins failed: %s", err)
|
t.Fatalf("ProbeControllerVolumePlugins failed: %s", err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user