...

Source file src/k8s.io/kubernetes/cmd/kube-controller-manager/app/plugins_providers.go

Documentation: k8s.io/kubernetes/cmd/kube-controller-manager/app

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

View as plain text