k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/pkg/scheduler/framework/plugins/nodevolumelimits/utils.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 nodevolumelimits 18 19 import ( 20 "strings" 21 22 v1 "k8s.io/api/core/v1" 23 storagev1 "k8s.io/api/storage/v1" 24 "k8s.io/apimachinery/pkg/util/sets" 25 utilfeature "k8s.io/apiserver/pkg/util/feature" 26 csilibplugins "k8s.io/csi-translation-lib/plugins" 27 v1helper "k8s.io/kubernetes/pkg/apis/core/v1/helper" 28 "k8s.io/kubernetes/pkg/features" 29 "k8s.io/kubernetes/pkg/scheduler/framework" 30 ) 31 32 // isCSIMigrationOn returns a boolean value indicating whether 33 // the CSI migration has been enabled for a particular storage plugin. 34 func isCSIMigrationOn(csiNode *storagev1.CSINode, pluginName string) bool { 35 if csiNode == nil || len(pluginName) == 0 { 36 return false 37 } 38 39 // In-tree storage to CSI driver migration feature should be enabled, 40 // along with the plugin-specific one 41 switch pluginName { 42 case csilibplugins.AWSEBSInTreePluginName: 43 return true 44 case csilibplugins.PortworxVolumePluginName: 45 if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationPortworx) { 46 return false 47 } 48 case csilibplugins.GCEPDInTreePluginName: 49 return true 50 case csilibplugins.AzureDiskInTreePluginName: 51 return true 52 case csilibplugins.CinderInTreePluginName: 53 return true 54 default: 55 return false 56 } 57 58 // The plugin name should be listed in the CSINode object annotation. 59 // This indicates that the plugin has been migrated to a CSI driver in the node. 60 csiNodeAnn := csiNode.GetAnnotations() 61 if csiNodeAnn == nil { 62 return false 63 } 64 65 var mpaSet sets.Set[string] 66 mpa := csiNodeAnn[v1.MigratedPluginsAnnotationKey] 67 if len(mpa) == 0 { 68 mpaSet = sets.New[string]() 69 } else { 70 tok := strings.Split(mpa, ",") 71 mpaSet = sets.New(tok...) 72 } 73 74 return mpaSet.Has(pluginName) 75 } 76 77 // volumeLimits returns volume limits associated with the node. 78 func volumeLimits(n *framework.NodeInfo) map[v1.ResourceName]int64 { 79 volumeLimits := map[v1.ResourceName]int64{} 80 for k, v := range n.Allocatable.ScalarResources { 81 if v1helper.IsAttachableVolumeResourceName(k) { 82 volumeLimits[k] = v 83 } 84 } 85 return volumeLimits 86 }