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