...

Source file src/k8s.io/kubernetes/cmd/kubelet/app/plugins_providers.go

Documentation: k8s.io/kubernetes/cmd/kubelet/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  	// Credential providers
    24  	_ "k8s.io/kubernetes/pkg/credentialprovider/gcp"
    25  
    26  	"k8s.io/component-base/featuregate"
    27  	"k8s.io/csi-translation-lib/plugins"
    28  	"k8s.io/klog/v2"
    29  	"k8s.io/kubernetes/pkg/features"
    30  	"k8s.io/kubernetes/pkg/volume"
    31  	"k8s.io/kubernetes/pkg/volume/csimigration"
    32  	"k8s.io/kubernetes/pkg/volume/portworx"
    33  	"k8s.io/kubernetes/pkg/volume/rbd"
    34  )
    35  
    36  type probeFn func() []volume.VolumePlugin
    37  
    38  func appendPluginBasedOnFeatureFlags(plugins []volume.VolumePlugin, inTreePluginName string,
    39  	featureGate featuregate.FeatureGate, pluginInfo pluginInfo) ([]volume.VolumePlugin, error) {
    40  	_, err := csimigration.CheckMigrationFeatureFlags(featureGate, pluginInfo.pluginMigrationFeature, pluginInfo.pluginUnregisterFeature)
    41  	if err != nil {
    42  		klog.InfoS("Unexpected CSI Migration Feature Flags combination detected, CSI Migration may not take effect", "err", err)
    43  		// TODO: fail and return here once alpha only tests can set the feature flags for a plugin correctly
    44  	}
    45  
    46  	// Skip appending the in-tree plugin to the list of plugins to be probed/initialized
    47  	// if the plugin unregister feature flag is set
    48  	if featureGate.Enabled(pluginInfo.pluginUnregisterFeature) {
    49  		klog.InfoS("Skipped registration of plugin since feature flag is enabled", "pluginName", inTreePluginName, "featureFlag", pluginInfo.pluginUnregisterFeature)
    50  		return plugins, nil
    51  	}
    52  
    53  	plugins = append(plugins, pluginInfo.pluginProbeFunction()...)
    54  	return plugins, nil
    55  }
    56  
    57  type pluginInfo struct {
    58  	pluginMigrationFeature  featuregate.Feature
    59  	pluginUnregisterFeature featuregate.Feature
    60  	pluginProbeFunction     probeFn
    61  }
    62  
    63  func appendLegacyProviderVolumes(allPlugins []volume.VolumePlugin, featureGate featuregate.FeatureGate) ([]volume.VolumePlugin, error) {
    64  	pluginMigrationStatus := make(map[string]pluginInfo)
    65  	pluginMigrationStatus[plugins.PortworxVolumePluginName] = pluginInfo{pluginMigrationFeature: features.CSIMigrationPortworx, pluginUnregisterFeature: features.InTreePluginPortworxUnregister, pluginProbeFunction: portworx.ProbeVolumePlugins}
    66  	pluginMigrationStatus[plugins.RBDVolumePluginName] = pluginInfo{pluginMigrationFeature: features.CSIMigrationRBD, pluginUnregisterFeature: features.InTreePluginRBDUnregister, pluginProbeFunction: rbd.ProbeVolumePlugins}
    67  	var err error
    68  	for pluginName, pluginInfo := range pluginMigrationStatus {
    69  		allPlugins, err = appendPluginBasedOnFeatureFlags(allPlugins, pluginName, featureGate, pluginInfo)
    70  		if err != nil {
    71  			return allPlugins, err
    72  		}
    73  	}
    74  	return allPlugins, nil
    75  }
    76  

View as plain text