utils.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /*
  2. Copyright 2019 The Kubernetes Authors.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package nodevolumelimits
  14. import (
  15. "strings"
  16. v1 "k8s.io/api/core/v1"
  17. storagev1 "k8s.io/api/storage/v1"
  18. "k8s.io/apimachinery/pkg/util/sets"
  19. utilfeature "k8s.io/apiserver/pkg/util/feature"
  20. csilibplugins "k8s.io/csi-translation-lib/plugins"
  21. "k8s.io/kubernetes/pkg/features"
  22. )
  23. // isCSIMigrationOn returns a boolean value indicating whether
  24. // the CSI migration has been enabled for a particular storage plugin.
  25. func isCSIMigrationOn(csiNode *storagev1.CSINode, pluginName string) bool {
  26. if csiNode == nil || len(pluginName) == 0 {
  27. return false
  28. }
  29. // In-tree storage to CSI driver migration feature should be enabled,
  30. // along with the plugin-specific one
  31. if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigration) {
  32. return false
  33. }
  34. switch pluginName {
  35. case csilibplugins.AWSEBSInTreePluginName:
  36. if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationAWS) {
  37. return false
  38. }
  39. case csilibplugins.GCEPDInTreePluginName:
  40. if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationGCE) {
  41. return false
  42. }
  43. case csilibplugins.AzureDiskInTreePluginName:
  44. if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationAzureDisk) {
  45. return false
  46. }
  47. case csilibplugins.CinderInTreePluginName:
  48. if !utilfeature.DefaultFeatureGate.Enabled(features.CSIMigrationOpenStack) {
  49. return false
  50. }
  51. default:
  52. return false
  53. }
  54. // The plugin name should be listed in the CSINode object annotation.
  55. // This indicates that the plugin has been migrated to a CSI driver in the node.
  56. csiNodeAnn := csiNode.GetAnnotations()
  57. if csiNodeAnn == nil {
  58. return false
  59. }
  60. var mpaSet sets.String
  61. mpa := csiNodeAnn[v1.MigratedPluginsAnnotationKey]
  62. if len(mpa) == 0 {
  63. mpaSet = sets.NewString()
  64. } else {
  65. tok := strings.Split(mpa, ",")
  66. mpaSet = sets.NewString(tok...)
  67. }
  68. return mpaSet.Has(pluginName)
  69. }