@@ -38,6 +38,7 @@ import (
3838 "k8s.io/apimachinery/pkg/util/sets"
3939 volumehelpers "k8s.io/cloud-provider/volume/helpers"
4040 "k8s.io/klog/v2"
41+ "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/constants"
4142)
4243
4344const (
@@ -110,7 +111,7 @@ var (
110111 http .StatusConflict : codes .FailedPrecondition ,
111112 }
112113
113- validDataCacheMode = []string {DataCacheModeWriteBack , DataCacheModeWriteThrough }
114+ validDataCacheMode = []string {constants . DataCacheModeWriteBack , constants . DataCacheModeWriteThrough }
114115
115116 // Regular expressions for validating parent_id, key and value of a resource tag.
116117 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) {
165166
166167func GenerateUnderspecifiedVolumeID (diskName string , isZonal bool ) string {
167168 if isZonal {
168- return fmt .Sprintf (volIDZonalFmt , UnspecifiedValue , UnspecifiedValue , diskName )
169+ return fmt .Sprintf (volIDZonalFmt , constants . UnspecifiedValue , constants . UnspecifiedValue , diskName )
169170 }
170- return fmt .Sprintf (volIDRegionalFmt , UnspecifiedValue , UnspecifiedValue , diskName )
171+ return fmt .Sprintf (volIDRegionalFmt , constants . UnspecifiedValue , constants . UnspecifiedValue , diskName )
171172}
172173
173174func SnapshotIDToProjectKey (id string ) (string , string , string , error ) {
@@ -705,7 +706,7 @@ func VolumeIdAsMultiZone(volumeId string) (string, error) {
705706 if splitId [volIDToplogyKey ] != "zones" {
706707 return "" , fmt .Errorf ("expected id to be zonal. Got: %s" , volumeId )
707708 }
708- splitId [volIDToplogyValue ] = MultiZoneValue
709+ splitId [volIDToplogyValue ] = constants . MultiZoneValue
709710 return strings .Join (splitId , "/" ), nil
710711}
711712
@@ -764,43 +765,43 @@ func ShortString(s string) string {
764765
765766// GetHyperdiskAttachLimit returns the hyperdisk attach limit based on machine type prefix and vCPUs
766767func GetHyperdiskAttachLimit (machineTypePrefix string , vCPUs int64 ) int64 {
767- var limitMap []MachineHyperdiskLimit
768+ var limitMap []constants. MachineHyperdiskLimit
768769
769770 switch machineTypePrefix {
770771 case "c4" :
771- limitMap = C4MachineHyperdiskAttachLimitMap
772+ limitMap = constants . C4MachineHyperdiskAttachLimitMap
772773 case "c4d" :
773- limitMap = C4DMachineHyperdiskAttachLimitMap
774+ limitMap = constants . C4DMachineHyperdiskAttachLimitMap
774775 case "n4" :
775- limitMap = N4MachineHyperdiskAttachLimitMap
776+ limitMap = constants . N4MachineHyperdiskAttachLimitMap
776777 case "c4a" :
777- limitMap = C4AMachineHyperdiskAttachLimitMap
778+ limitMap = constants . C4AMachineHyperdiskAttachLimitMap
778779 case "a4x" :
779- limitMap = A4XMachineHyperdiskAttachLimitMap
780+ limitMap = constants . A4XMachineHyperdiskAttachLimitMap
780781 default :
781782 // Fallback to the most conservative Gen4 map for unknown types
782- return MapNumber (vCPUs , C4DMachineHyperdiskAttachLimitMap )
783+ return MapNumber (vCPUs , constants . C4DMachineHyperdiskAttachLimitMap )
783784 }
784785
785786 return MapNumber (vCPUs , limitMap )
786787}
787788
788789// 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 {
790791 for _ , limit := range limitMap {
791- if vCPUs <= limit .max {
792- return limit .value
792+ if vCPUs <= limit .Max {
793+ return limit .Value
793794 }
794795 }
795796 // Return the last value if vCPUs exceeds all max values
796797 if len (limitMap ) > 0 {
797- return limitMap [len (limitMap )- 1 ].value
798+ return limitMap [len (limitMap )- 1 ].Value
798799 }
799800 return 15
800801}
801802
802803func DiskTypeLabelKey (diskType string ) string {
803- return fmt .Sprintf ("%s/%s" , DiskTypeKeyPrefix , diskType )
804+ return fmt .Sprintf ("%s/%s" , constants . DiskTypeKeyPrefix , diskType )
804805}
805806
806807// IsUpdateIopsThroughputValuesAllowed checks if a disk type is hyperdisk,
0 commit comments