k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/cmd/kubelet/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(plugins []volume.VolumePlugin, inTreePluginName string, 32 featureGate featuregate.FeatureGate, pluginInfo pluginInfo) ([]volume.VolumePlugin, error) { 33 _, err := csimigration.CheckMigrationFeatureFlags(featureGate, pluginInfo.pluginMigrationFeature, pluginInfo.pluginUnregisterFeature) 34 if err != nil { 35 klog.InfoS("Unexpected CSI Migration Feature Flags combination detected, CSI Migration may not take effect", "err", err) 36 // TODO: fail and return here once alpha only tests can set the feature flags for a plugin correctly 37 } 38 39 // Skip appending the in-tree plugin to the list of plugins to be probed/initialized 40 // if the plugin unregister feature flag is set 41 if featureGate.Enabled(pluginInfo.pluginUnregisterFeature) { 42 klog.InfoS("Skipped registration of plugin since feature flag is enabled", "pluginName", inTreePluginName, "featureFlag", pluginInfo.pluginUnregisterFeature) 43 return plugins, nil 44 } 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 appendLegacyProviderVolumes(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(allPlugins, pluginName, featureGate, pluginInfo) 62 if err != nil { 63 return allPlugins, err 64 } 65 } 66 return allPlugins, nil 67 }