...
1
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
33
34 func isCSIMigrationOn(csiNode *storagev1.CSINode, pluginName string) bool {
35 if csiNode == nil || len(pluginName) == 0 {
36 return false
37 }
38
39
40
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 case csilibplugins.RBDVolumePluginName:
55 if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationRBD) {
56 return false
57 }
58 default:
59 return false
60 }
61
62
63
64 csiNodeAnn := csiNode.GetAnnotations()
65 if csiNodeAnn == nil {
66 return false
67 }
68
69 var mpaSet sets.Set[string]
70 mpa := csiNodeAnn[v1.MigratedPluginsAnnotationKey]
71 if len(mpa) == 0 {
72 mpaSet = sets.New[string]()
73 } else {
74 tok := strings.Split(mpa, ",")
75 mpaSet = sets.New(tok...)
76 }
77
78 return mpaSet.Has(pluginName)
79 }
80
81
82 func volumeLimits(n *framework.NodeInfo) map[v1.ResourceName]int64 {
83 volumeLimits := map[v1.ResourceName]int64{}
84 for k, v := range n.Allocatable.ScalarResources {
85 if v1helper.IsAttachableVolumeResourceName(k) {
86 volumeLimits[k] = v
87 }
88 }
89 return volumeLimits
90 }
91
View as plain text