attach_limit.go 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. Copyright 2018 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 util
  14. import (
  15. "crypto/sha1"
  16. "encoding/hex"
  17. )
  18. // This file is a common place holder for volume limit utility constants
  19. // shared between volume package and scheduler
  20. const (
  21. // EBSVolumeLimitKey resource name that will store volume limits for EBS
  22. EBSVolumeLimitKey = "attachable-volumes-aws-ebs"
  23. // EBSNitroLimitRegex finds nitro instance types with different limit than EBS defaults
  24. EBSNitroLimitRegex = "^[cmr]5.*|t3|z1d"
  25. // DefaultMaxEBSVolumes is the limit for volumes attached to an instance.
  26. // Amazon recommends no more than 40; the system root volume uses at least one.
  27. // See http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/volume_limits.html#linux-specific-volume-limits
  28. DefaultMaxEBSVolumes = 39
  29. // DefaultMaxEBSNitroVolumeLimit is default EBS volume limit on m5 and c5 instances
  30. DefaultMaxEBSNitroVolumeLimit = 25
  31. // AzureVolumeLimitKey stores resource name that will store volume limits for Azure
  32. AzureVolumeLimitKey = "attachable-volumes-azure-disk"
  33. // GCEVolumeLimitKey stores resource name that will store volume limits for GCE node
  34. GCEVolumeLimitKey = "attachable-volumes-gce-pd"
  35. // CinderVolumeLimitKey contains Volume limit key for Cinder
  36. CinderVolumeLimitKey = "attachable-volumes-cinder"
  37. // DefaultMaxCinderVolumes defines the maximum number of PD Volumes for Cinder
  38. // For Openstack we are keeping this to a high enough value so as depending on backend
  39. // cluster admins can configure it.
  40. DefaultMaxCinderVolumes = 256
  41. // CSIAttachLimitPrefix defines prefix used for CSI volumes
  42. CSIAttachLimitPrefix = "attachable-volumes-csi-"
  43. // ResourceNameLengthLimit stores maximum allowed Length for a ResourceName
  44. ResourceNameLengthLimit = 63
  45. )
  46. // GetCSIAttachLimitKey returns limit key used for CSI volumes
  47. func GetCSIAttachLimitKey(driverName string) string {
  48. csiPrefixLength := len(CSIAttachLimitPrefix)
  49. totalkeyLength := csiPrefixLength + len(driverName)
  50. if totalkeyLength >= ResourceNameLengthLimit {
  51. charsFromDriverName := driverName[:23]
  52. hash := sha1.New()
  53. hash.Write([]byte(driverName))
  54. hashed := hex.EncodeToString(hash.Sum(nil))
  55. hashed = hashed[:16]
  56. return CSIAttachLimitPrefix + charsFromDriverName + hashed
  57. }
  58. return CSIAttachLimitPrefix + driverName
  59. }