@@ -38,6 +38,7 @@ import (
38
38
"k8s.io/apimachinery/pkg/util/sets"
39
39
volumehelpers "k8s.io/cloud-provider/volume/helpers"
40
40
"k8s.io/klog/v2"
41
+ "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/constants"
41
42
)
42
43
43
44
const (
@@ -110,7 +111,7 @@ var (
110
111
http .StatusConflict : codes .FailedPrecondition ,
111
112
}
112
113
113
- validDataCacheMode = []string {DataCacheModeWriteBack , DataCacheModeWriteThrough }
114
+ validDataCacheMode = []string {constants . DataCacheModeWriteBack , constants . DataCacheModeWriteThrough }
114
115
115
116
// Regular expressions for validating parent_id, key and value of a resource tag.
116
117
regexParent = regexp .MustCompile (`(^[1-9][0-9]{0,31}$)|(^[a-z][a-z0-9-]{4,28}[a-z0-9]$)` )
@@ -165,9 +166,9 @@ func KeyToVolumeID(volKey *meta.Key, project string) (string, error) {
165
166
166
167
func GenerateUnderspecifiedVolumeID (diskName string , isZonal bool ) string {
167
168
if isZonal {
168
- return fmt .Sprintf (volIDZonalFmt , UnspecifiedValue , UnspecifiedValue , diskName )
169
+ return fmt .Sprintf (volIDZonalFmt , constants . UnspecifiedValue , constants . UnspecifiedValue , diskName )
169
170
}
170
- return fmt .Sprintf (volIDRegionalFmt , UnspecifiedValue , UnspecifiedValue , diskName )
171
+ return fmt .Sprintf (volIDRegionalFmt , constants . UnspecifiedValue , constants . UnspecifiedValue , diskName )
171
172
}
172
173
173
174
func SnapshotIDToProjectKey (id string ) (string , string , string , error ) {
@@ -705,7 +706,7 @@ func VolumeIdAsMultiZone(volumeId string) (string, error) {
705
706
if splitId [volIDToplogyKey ] != "zones" {
706
707
return "" , fmt .Errorf ("expected id to be zonal. Got: %s" , volumeId )
707
708
}
708
- splitId [volIDToplogyValue ] = MultiZoneValue
709
+ splitId [volIDToplogyValue ] = constants . MultiZoneValue
709
710
return strings .Join (splitId , "/" ), nil
710
711
}
711
712
@@ -764,43 +765,43 @@ func ShortString(s string) string {
764
765
765
766
// GetHyperdiskAttachLimit returns the hyperdisk attach limit based on machine type prefix and vCPUs
766
767
func GetHyperdiskAttachLimit (machineTypePrefix string , vCPUs int64 ) int64 {
767
- var limitMap []MachineHyperdiskLimit
768
+ var limitMap []constants. MachineHyperdiskLimit
768
769
769
770
switch machineTypePrefix {
770
771
case "c4" :
771
- limitMap = C4MachineHyperdiskAttachLimitMap
772
+ limitMap = constants . C4MachineHyperdiskAttachLimitMap
772
773
case "c4d" :
773
- limitMap = C4DMachineHyperdiskAttachLimitMap
774
+ limitMap = constants . C4DMachineHyperdiskAttachLimitMap
774
775
case "n4" :
775
- limitMap = N4MachineHyperdiskAttachLimitMap
776
+ limitMap = constants . N4MachineHyperdiskAttachLimitMap
776
777
case "c4a" :
777
- limitMap = C4AMachineHyperdiskAttachLimitMap
778
+ limitMap = constants . C4AMachineHyperdiskAttachLimitMap
778
779
case "a4x" :
779
- limitMap = A4XMachineHyperdiskAttachLimitMap
780
+ limitMap = constants . A4XMachineHyperdiskAttachLimitMap
780
781
default :
781
782
// Fallback to the most conservative Gen4 map for unknown types
782
- return MapNumber (vCPUs , C4DMachineHyperdiskAttachLimitMap )
783
+ return MapNumber (vCPUs , constants . C4DMachineHyperdiskAttachLimitMap )
783
784
}
784
785
785
786
return MapNumber (vCPUs , limitMap )
786
787
}
787
788
788
789
// mapNumber maps the vCPUs to the appropriate hyperdisk limit
789
- func MapNumber (vCPUs int64 , limitMap []MachineHyperdiskLimit ) int64 {
790
+ func MapNumber (vCPUs int64 , limitMap []constants. MachineHyperdiskLimit ) int64 {
790
791
for _ , limit := range limitMap {
791
- if vCPUs <= limit .max {
792
- return limit .value
792
+ if vCPUs <= limit .Max {
793
+ return limit .Value
793
794
}
794
795
}
795
796
// Return the last value if vCPUs exceeds all max values
796
797
if len (limitMap ) > 0 {
797
- return limitMap [len (limitMap )- 1 ].value
798
+ return limitMap [len (limitMap )- 1 ].Value
798
799
}
799
800
return 15
800
801
}
801
802
802
803
func DiskTypeLabelKey (diskType string ) string {
803
- return fmt .Sprintf ("%s/%s" , DiskTypeKeyPrefix , diskType )
804
+ return fmt .Sprintf ("%s/%s" , constants . DiskTypeKeyPrefix , diskType )
804
805
}
805
806
806
807
// IsUpdateIopsThroughputValuesAllowed checks if a disk type is hyperdisk,
0 commit comments