@@ -31,6 +31,8 @@ import (
31
31
32
32
csi "github.com/container-storage-interface/spec/lib/go/csi"
33
33
34
+ "k8s.io/client-go/kubernetes"
35
+ "k8s.io/client-go/rest"
34
36
"k8s.io/klog/v2"
35
37
"k8s.io/mount-utils"
36
38
@@ -101,7 +103,12 @@ const (
101
103
// doc https://cloud.google.com/compute/docs/memory-optimized-machines#x4_disks
102
104
x4HyperdiskLimit int64 = 39
103
105
// doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a4-disks
104
- a4HyperdiskLimit int64 = 127
106
+ a4HyperdiskLimit int64 = 127
107
+ // doc https://cloud.google.com/compute/docs/storage-optimized-machines#z3_disks
108
+ // doc https://cloud.google.com/compute/docs/accelerator-optimized-machines#a3-disks
109
+ gen3HyperdiskLimit int64 = 31
110
+ // doc https://cloud.google.com/compute/docs/compute-optimized-machines#h3_disks
111
+ h3HyperdiskLimit int64 = 7 // Use limit for Hyperdisk Balanced
105
112
defaultLinuxFsType = "ext4"
106
113
defaultWindowsFsType = "ntfs"
107
114
fsTypeExt3 = "ext3"
@@ -571,7 +578,7 @@ func (ns *GCENodeServer) NodeGetInfo(ctx context.Context, req *csi.NodeGetInfoRe
571
578
572
579
nodeID := common .CreateNodeID (ns .MetadataService .GetProject (), ns .MetadataService .GetZone (), ns .MetadataService .GetName ())
573
580
574
- volumeLimits , err := ns .GetVolumeLimits ()
581
+ volumeLimits , err := ns .GetVolumeLimits (ctx )
575
582
if err != nil {
576
583
klog .Errorf ("GetVolumeLimits failed: %v. The error is ignored so that the driver can register" , err .Error ())
577
584
// No error should be returned from NodeGetInfo, otherwise the driver will not register
@@ -733,7 +740,7 @@ func (ns *GCENodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpa
733
740
}, nil
734
741
}
735
742
736
- func (ns * GCENodeServer ) GetVolumeLimits () (int64 , error ) {
743
+ func (ns * GCENodeServer ) GetVolumeLimits (ctx context. Context ) (int64 , error ) {
737
744
// Machine-type format: n1-type-CPUS or custom-CPUS-RAM or f1/g1-type
738
745
machineType := ns .MetadataService .GetMachineType ()
739
746
@@ -743,6 +750,22 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
743
750
return volumeLimitSmall , nil
744
751
}
745
752
}
753
+
754
+ // Get attach limit override from label
755
+ attachLimitOverride , err := GetAttachLimitsOverrideFromNodeLabel (ctx , ns .MetadataService .GetName ())
756
+ if err == nil && attachLimitOverride > 0 && attachLimitOverride < 128 {
757
+ return attachLimitOverride , nil
758
+ } else {
759
+ // If there is an error or the range is not valid, still proceed to get defaults for the machine type
760
+ if err != nil {
761
+ klog .Warningf ("using default value due to err getting node-restriction.kubernetes.io/gke-volume-attach-limit-override: %v" , err )
762
+ }
763
+ if attachLimitOverride != 0 {
764
+ klog .Warningf ("using default value due to invalid node-restriction.kubernetes.io/gke-volume-attach-limit-override: %d" , attachLimitOverride )
765
+ }
766
+ }
767
+
768
+ // Process gen4 machine attach limits
746
769
gen4MachineTypesPrefix := []string {"c4a-" , "c4-" , "n4-" }
747
770
for _ , gen4Prefix := range gen4MachineTypesPrefix {
748
771
if strings .HasPrefix (machineType , gen4Prefix ) {
@@ -766,5 +789,59 @@ func (ns *GCENodeServer) GetVolumeLimits() (int64, error) {
766
789
}
767
790
}
768
791
792
+ // Process gen3 machine attach limits
793
+ gen3MachineTypesPrefix := []string {"c3-" , "c3d-" }
794
+ for _ , gen3Prefix := range gen3MachineTypesPrefix {
795
+ if strings .HasPrefix (machineType , gen3Prefix ) {
796
+ cpus , err := common .ExtractCPUFromMachineType (machineType )
797
+ if err != nil {
798
+ return volumeLimitSmall , err
799
+ }
800
+ if cpus <= 8 || strings .Contains (machineType , "metal" ) {
801
+ return volumeLimitSmall , nil
802
+ }
803
+ return gen3HyperdiskLimit , nil
804
+
805
+ }
806
+ if strings .HasPrefix (machineType , "z3-" ) {
807
+ return gen3HyperdiskLimit , nil
808
+ }
809
+ if strings .HasPrefix (machineType , "h3-" ) {
810
+ return h3HyperdiskLimit , nil
811
+ }
812
+ if strings .HasPrefix (machineType , "a3-" ) {
813
+ if machineType == "a3-ultragpu-8g" {
814
+ return volumeLimitBig , nil
815
+ } else {
816
+ return gen3HyperdiskLimit , nil
817
+ }
818
+ }
819
+
820
+ }
821
+
769
822
return volumeLimitBig , nil
770
823
}
824
+
825
+ func GetAttachLimitsOverrideFromNodeLabel (ctx context.Context , nodeName string ) (int64 , error ) {
826
+ cfg , err := rest .InClusterConfig ()
827
+ if err != nil {
828
+ return 0 , err
829
+ }
830
+ kubeClient , err := kubernetes .NewForConfig (cfg )
831
+ if err != nil {
832
+ return 0 , err
833
+ }
834
+ node , err := getNodeWithRetry (ctx , kubeClient , nodeName )
835
+ if err != nil {
836
+ return 0 , err
837
+ }
838
+ if val , found := node .GetLabels ()[fmt .Sprintf (common .NodeRestrictionLabelPrefix , common .AttachLimitOverrideLabel )]; found {
839
+ attachLimitOverrideForNode , err := strconv .ParseInt (val , 10 , 64 )
840
+ if err != nil {
841
+ return 0 , fmt .Errorf ("error getting attach limit override from node label: %v" , err )
842
+ }
843
+ klog .V (4 ).Infof ("attach limit override for the node: %v" , attachLimitOverrideForNode )
844
+ return attachLimitOverrideForNode , nil
845
+ }
846
+ return 0 , nil
847
+ }
0 commit comments