Merge pull request #58519 from linyouchong/lyc-probe
Automatic merge from submit-queue (batch tested with PRs 60073, 58519, 61860). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. flexvolume prober: trigger plugin init only for the relevant plugin **What this PR does / why we need it**: The automatic discovery trigger init only to the specific plugin directory that was updated, and not to all the plugins in the flexvolume plugin directory. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes #58352 **Special notes for your reviewer**: NONE **Release note**: ``` NONE ```
This commit is contained in:
@@ -36,12 +36,22 @@ import (
|
||||
"k8s.io/kubernetes/pkg/volume/util/recyclerclient"
|
||||
)
|
||||
|
||||
type ProbeOperation uint32
|
||||
type ProbeEvent struct {
|
||||
Plugin VolumePlugin // VolumePlugin that was added/updated/removed. if ProbeEvent.Op is 'ProbeRemove', Plugin should be nil
|
||||
PluginName string
|
||||
Op ProbeOperation // The operation to the plugin
|
||||
}
|
||||
|
||||
const (
|
||||
// Common parameter which can be specified in StorageClass to specify the desired FSType
|
||||
// Provisioners SHOULD implement support for this if they are block device based
|
||||
// Must be a filesystem type supported by the host operating system.
|
||||
// Ex. "ext4", "xfs", "ntfs". Default value depends on the provisioner
|
||||
VolumeParameterFSType = "fstype"
|
||||
|
||||
ProbeAddOrUpdate ProbeOperation = 1 << iota
|
||||
ProbeRemove
|
||||
)
|
||||
|
||||
// VolumeOptions contains option information about a volume.
|
||||
@@ -75,12 +85,8 @@ type VolumeOptions struct {
|
||||
type DynamicPluginProber interface {
|
||||
Init() error
|
||||
|
||||
// If an update has occurred since the last probe, updated = true
|
||||
// and the list of probed plugins is returned.
|
||||
// Otherwise, update = false and probedPlugins = nil.
|
||||
//
|
||||
// If an error occurs, updated and probedPlugins are undefined.
|
||||
Probe() (updated bool, probedPlugins []VolumePlugin, err error)
|
||||
// If an error occurs, events are undefined.
|
||||
Probe() (events []ProbeEvent, err error)
|
||||
}
|
||||
|
||||
// VolumePlugin is an interface to volume plugins that can be used on a
|
||||
@@ -314,7 +320,7 @@ type VolumePluginMgr struct {
|
||||
mutex sync.Mutex
|
||||
plugins map[string]VolumePlugin
|
||||
prober DynamicPluginProber
|
||||
probedPlugins []VolumePlugin
|
||||
probedPlugins map[string]VolumePlugin
|
||||
Host VolumeHost
|
||||
}
|
||||
|
||||
@@ -431,6 +437,9 @@ func (pm *VolumePluginMgr) InitPlugins(plugins []VolumePlugin, prober DynamicPlu
|
||||
if pm.plugins == nil {
|
||||
pm.plugins = map[string]VolumePlugin{}
|
||||
}
|
||||
if pm.probedPlugins == nil {
|
||||
pm.probedPlugins = map[string]VolumePlugin{}
|
||||
}
|
||||
|
||||
allErrs := []error{}
|
||||
for _, plugin := range plugins {
|
||||
@@ -544,21 +553,25 @@ func (pm *VolumePluginMgr) FindPluginByName(name string) (VolumePlugin, error) {
|
||||
// Check if probedPlugin cache update is required.
|
||||
// If it is, initialize all probed plugins and replace the cache with them.
|
||||
func (pm *VolumePluginMgr) refreshProbedPlugins() {
|
||||
updated, plugins, err := pm.prober.Probe()
|
||||
events, err := pm.prober.Probe()
|
||||
if err != nil {
|
||||
glog.Errorf("Error dynamically probing plugins: %s", err)
|
||||
return // Use cached plugins upon failure.
|
||||
}
|
||||
|
||||
if updated {
|
||||
pm.probedPlugins = []VolumePlugin{}
|
||||
for _, plugin := range plugins {
|
||||
if err := pm.initProbedPlugin(plugin); err != nil {
|
||||
for _, event := range events {
|
||||
if event.Op == ProbeAddOrUpdate {
|
||||
if err := pm.initProbedPlugin(event.Plugin); err != nil {
|
||||
glog.Errorf("Error initializing dynamically probed plugin %s; error: %s",
|
||||
plugin.GetPluginName(), err)
|
||||
event.Plugin.GetPluginName(), err)
|
||||
continue
|
||||
}
|
||||
pm.probedPlugins = append(pm.probedPlugins, plugin)
|
||||
pm.probedPlugins[event.Plugin.GetPluginName()] = event.Plugin
|
||||
} else if event.Op == ProbeRemove {
|
||||
delete(pm.probedPlugins, event.Plugin.GetPluginName())
|
||||
} else {
|
||||
glog.Errorf("Unknown Operation on PluginName: %s.",
|
||||
event.Plugin.GetPluginName())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -803,5 +816,5 @@ func ValidateRecyclerPodTemplate(pod *v1.Pod) error {
|
||||
|
||||
type dummyPluginProber struct{}
|
||||
|
||||
func (*dummyPluginProber) Init() error { return nil }
|
||||
func (*dummyPluginProber) Probe() (bool, []VolumePlugin, error) { return false, nil, nil }
|
||||
func (*dummyPluginProber) Init() error { return nil }
|
||||
func (*dummyPluginProber) Probe() ([]ProbeEvent, error) { return nil, nil }
|
||||
|
Reference in New Issue
Block a user