k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kube-controller-manager/app/plugins_providers.go (about)

     1  /*
     2  Copyright 2019 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package app
    18  
    19  import (
    20  	"k8s.io/component-base/featuregate"
    21  	"k8s.io/csi-translation-lib/plugins"
    22  	"k8s.io/klog/v2"
    23  	"k8s.io/kubernetes/pkg/features"
    24  	"k8s.io/kubernetes/pkg/volume"
    25  	"k8s.io/kubernetes/pkg/volume/csimigration"
    26  	"k8s.io/kubernetes/pkg/volume/portworx"
    27  )
    28  
    29  type probeFn func() []volume.VolumePlugin
    30  
    31  func appendPluginBasedOnFeatureFlags(logger klog.Logger, plugins []volume.VolumePlugin, inTreePluginName string, featureGate featuregate.FeatureGate, pluginInfo pluginInfo) ([]volume.VolumePlugin, error) {
    32  
    33  	_, err := csimigration.CheckMigrationFeatureFlags(featureGate, pluginInfo.pluginMigrationFeature, pluginInfo.pluginUnregisterFeature)
    34  	if err != nil {
    35  		logger.Error(err, "Unexpected CSI Migration Feature Flags combination detected. CSI Migration may not take effect")
    36  		klog.FlushAndExit(klog.ExitFlushTimeout, 1)
    37  		// TODO: fail and return here once alpha only tests can set the feature flags for a plugin correctly
    38  	}
    39  
    40  	// Skip appending the in-tree plugin to the list of plugins to be probed/initialized
    41  	// if the plugin unregister feature flag is set
    42  	if featureGate.Enabled(pluginInfo.pluginUnregisterFeature) {
    43  		logger.Info("Skip registration of plugin since feature flag is enabled", "plugin", inTreePluginName, "feature", pluginInfo.pluginUnregisterFeature)
    44  		return plugins, nil
    45  	}
    46  	plugins = append(plugins, pluginInfo.pluginProbeFunction()...)
    47  	return plugins, nil
    48  }
    49  
    50  type pluginInfo struct {
    51  	pluginMigrationFeature  featuregate.Feature
    52  	pluginUnregisterFeature featuregate.Feature
    53  	pluginProbeFunction     probeFn
    54  }
    55  
    56  func appendAttachableLegacyProviderVolumes(logger klog.Logger, allPlugins []volume.VolumePlugin, featureGate featuregate.FeatureGate) ([]volume.VolumePlugin, error) {
    57  	pluginMigrationStatus := make(map[string]pluginInfo)
    58  	pluginMigrationStatus[plugins.PortworxVolumePluginName] = pluginInfo{pluginMigrationFeature: features.CSIMigrationPortworx, pluginUnregisterFeature: features.InTreePluginPortworxUnregister, pluginProbeFunction: portworx.ProbeVolumePlugins}
    59  	var err error
    60  	for pluginName, pluginInfo := range pluginMigrationStatus {
    61  		allPlugins, err = appendPluginBasedOnFeatureFlags(logger, allPlugins, pluginName, featureGate, pluginInfo)
    62  		if err != nil {
    63  			return allPlugins, err
    64  		}
    65  	}
    66  	return allPlugins, nil
    67  }
    68  
    69  func appendExpandableLegacyProviderVolumes(logger klog.Logger, allPlugins []volume.VolumePlugin, featureGate featuregate.FeatureGate) ([]volume.VolumePlugin, error) {
    70  	return appendLegacyProviderVolumes(logger, allPlugins, featureGate)
    71  }
    72  
    73  func appendLegacyProviderVolumes(logger klog.Logger, allPlugins []volume.VolumePlugin, featureGate featuregate.FeatureGate) ([]volume.VolumePlugin, error) {
    74  	return appendAttachableLegacyProviderVolumes(logger, allPlugins, featureGate)
    75  }