@@ -27,164 +27,11 @@ import (
2727 "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/convert"
2828)
2929
30- const (
31- // Disk Params
32- ParameterAccessMode = "access-mode"
33-
34- // Parameters for StorageClass
35- ParameterKeyType = "type"
36- ParameterKeyReplicationType = "replication-type"
37- ParameterKeyDiskEncryptionKmsKey = "disk-encryption-kms-key"
38- ParameterKeyLabels = "labels"
39- ParameterKeyProvisionedIOPSOnCreate = "provisioned-iops-on-create"
40- ParameterKeyProvisionedThroughputOnCreate = "provisioned-throughput-on-create"
41- ParameterAvailabilityClass = "availability-class"
42- ParameterKeyEnableConfidentialCompute = "enable-confidential-storage"
43- ParameterKeyStoragePools = "storage-pools"
44- ParameterKeyUseAllowedDiskTopology = "use-allowed-disk-topology"
45-
46- // Parameters for Data Cache
47- ParameterKeyDataCacheSize = "data-cache-size"
48- ParameterKeyDataCacheMode = "data-cache-mode"
49- ParameterKeyResourceTags = "resource-tags"
50- ParameterKeyEnableMultiZoneProvisioning = "enable-multi-zone-provisioning"
51-
52- // Parameters for VolumeSnapshotClass
53- ParameterKeyStorageLocations = "storage-locations"
54- ParameterKeySnapshotType = "snapshot-type"
55- ParameterKeyImageFamily = "image-family"
56- replicationTypeNone = "none"
57-
58- // Keys for PV and PVC parameters as reported by external-provisioner
59- ParameterKeyPVCName = "csi.storage.k8s.io/pvc/name"
60- ParameterKeyPVCNamespace = "csi.storage.k8s.io/pvc/namespace"
61- ParameterKeyPVName = "csi.storage.k8s.io/pv/name"
62-
63- // Keys for tags to put in the provisioned disk description
64- tagKeyCreatedForClaimNamespace = "kubernetes.io/created-for/pvc/namespace"
65- tagKeyCreatedForClaimName = "kubernetes.io/created-for/pvc/name"
66- tagKeyCreatedForVolumeName = "kubernetes.io/created-for/pv/name"
67- tagKeyCreatedBy = "storage.gke.io/created-by"
68-
69- // Keys for Snapshot and SnapshotContent parameters as reported by external-snapshotter
70- ParameterKeyVolumeSnapshotName = "csi.storage.k8s.io/volumesnapshot/name"
71- ParameterKeyVolumeSnapshotNamespace = "csi.storage.k8s.io/volumesnapshot/namespace"
72- ParameterKeyVolumeSnapshotContentName = "csi.storage.k8s.io/volumesnapshotcontent/name"
73-
74- // Parameters for AvailabilityClass
75- ParameterNoAvailabilityClass = "none"
76- ParameterRegionalHardFailoverClass = "regional-hard-failover"
77-
78- // Keys for tags to put in the provisioned snapshot description
79- tagKeyCreatedForSnapshotName = "kubernetes.io/created-for/volumesnapshot/name"
80- tagKeyCreatedForSnapshotNamespace = "kubernetes.io/created-for/volumesnapshot/namespace"
81- tagKeyCreatedForSnapshotContentName = "kubernetes.io/created-for/volumesnapshotcontent/name"
82-
83- // Hyperdisk disk types
84- DiskTypeHdHA = "hyperdisk-balanced-high-availability"
85- DiskTypeHdT = "hyperdisk-throughput"
86- DiskTypeHdE = "hyperdisk-extreme"
87- DiskTypeHdML = "hyperdisk-ml"
88-
89- // Parameters for VolumeSnapshotClass
90- DiskSnapshotType = "snapshots"
91- DiskImageType = "images"
92- )
93-
94- type StoragePool struct {
95- Project string
96- Zone string
97- Name string
98- ResourceName string
99- }
100-
101- type DataCacheParameters struct {
102- // Values: {string} in int64 form
103- // Default: ""
104- DataCacheSize string
105- // Values: writethrough, writeback
106- // Default: writethrough
107- DataCacheMode string
108- }
109-
110- // DiskParameters contains normalized and defaulted disk parameters
111- type DiskParameters struct {
112- // Values: pd-standard, pd-balanced, pd-ssd, or any other PD disk type. Not validated.
113- // Default: pd-standard
114- DiskType string
115- // Values: "none", regional-pd
116- // Default: "none"
117- ReplicationType string
118- // Values: {string}
119- // Default: ""
120- DiskEncryptionKMSKey string
121- // Values: {map[string]string}
122- // Default: ""
123- Tags map [string ]string
124- // Values: {map[string]string}
125- // Default: ""
126- Labels map [string ]string
127- // Values: {int64}
128- // Default: none
129- ProvisionedIOPSOnCreate int64
130- // Values: {int64}
131- // Default: none
132- ProvisionedThroughputOnCreate int64
133- // Values: {bool}
134- // Default: false
135- EnableConfidentialCompute bool
136- // Default: false
137- ForceAttach bool
138- // Values: {[]string}
139- // Default: ""
140- StoragePools []StoragePool
141- // Values: {map[string]string}
142- // Default: ""
143- ResourceTags map [string ]string
144- // Values: {bool}
145- // Default: false
146- MultiZoneProvisioning bool
147- // Values: READ_WRITE_SINGLE, READ_ONLY_MANY, READ_WRITE_MANY
148- // Default: READ_WRITE_SINGLE
149- AccessMode string
150- // Values {}
151- // Default: false
152- UseAllowedDiskTopology bool
153- }
154-
155- func (dp * DiskParameters ) IsRegional () bool {
156- return dp .ReplicationType == "regional-pd" || dp .DiskType == DiskTypeHdHA
157- }
158-
159- // SnapshotParameters contains normalized and defaulted parameters for snapshots
160- type SnapshotParameters struct {
161- StorageLocations []string
162- SnapshotType string
163- ImageFamily string
164- Tags map [string ]string
165- Labels map [string ]string
166- ResourceTags map [string ]string
167- }
168-
169- type ParameterProcessor struct {
170- DriverName string
171- EnableStoragePools bool
172- EnableMultiZone bool
173- EnableHdHA bool
174- EnableDiskTopology bool
175- }
176-
177- type ModifyVolumeParameters struct {
178- IOPS * int64
179- Throughput * int64
180- }
181-
18230// ExtractAndDefaultParameters will take the relevant parameters from a map and
18331// put them into a well defined struct making sure to default unspecified fields.
18432// extraVolumeLabels are added as labels; if there are also labels specified in
18533// parameters, any matching extraVolumeLabels will be overridden.
18634func (pp * ParameterProcessor ) ExtractAndDefaultParameters (parameters map [string ]string , extraVolumeLabels map [string ]string , enableDataCache bool , extraTags map [string ]string ) (DiskParameters , DataCacheParameters , error ) {
187-
18835 p := DiskParameters {
18936 DiskType : "pd-standard" , // Default
19037 ReplicationType : replicationTypeNone , // Default
@@ -275,7 +122,7 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
275122 if paramEnableConfidentialCompute {
276123 // DiskEncryptionKmsKey is needed to enable confidentialStorage
277124 if val , ok := parameters [ParameterKeyDiskEncryptionKmsKey ]; ! ok || ! isValidDiskEncryptionKmsKey (val ) {
278- return p , d , fmt .Errorf ("Valid %v is required to enable ConfidentialStorage" , ParameterKeyDiskEncryptionKmsKey )
125+ return p , d , fmt .Errorf ("valid %v is required to enable ConfidentialStorage" , ParameterKeyDiskEncryptionKmsKey )
279126 }
280127 }
281128
@@ -304,7 +151,7 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
304151 d .DataCacheSize = strconv .FormatInt (paramDataCacheSize , 10 )
305152 case ParameterKeyDataCacheMode :
306153 if ! enableDataCache {
307- return p , d , fmt .Errorf ("data caching enabled %v; parameters contains invalid option %q" , enableDataCache , ParameterKeyDataCacheSize )
154+ return p , d , fmt .Errorf ("data caching enabled %v; parameters contains invalid option %q" , enableDataCache , ParameterKeyDataCacheMode )
308155 }
309156 if err := ValidateDataCacheMode (v ); err != nil {
310157 return p , d , fmt .Errorf ("parameters contains invalid option: %s: %w" , ParameterKeyDataCacheMode , err )
@@ -425,7 +272,6 @@ func extractResourceTagsParameter(tagsString string, resourceTags map[string]str
425272}
426273
427274func ExtractModifyVolumeParameters (parameters map [string ]string ) (ModifyVolumeParameters , error ) {
428-
429275 modifyVolumeParams := ModifyVolumeParameters {}
430276
431277 for key , value := range parameters {
@@ -446,6 +292,7 @@ func ExtractModifyVolumeParameters(parameters map[string]string) (ModifyVolumePa
446292 return ModifyVolumeParameters {}, fmt .Errorf ("parameters contain unknown parameter: %s" , key )
447293 }
448294 }
295+
449296 return modifyVolumeParams , nil
450297}
451298
@@ -457,13 +304,13 @@ func convertStringToAvailabilityClass(str string) (string, error) {
457304 case ParameterRegionalHardFailoverClass :
458305 return ParameterRegionalHardFailoverClass , nil
459306 }
460- return "" , fmt .Errorf ("Unexpected boolean string %s" , str )
307+ return "" , fmt .Errorf ("unexpected boolean string %s" , str )
461308}
462309
463310// StoragePoolZones returns the unique zones of the given storage pool resource names.
464311// Returns an error if multiple storage pools in 1 zone are found.
465312func StoragePoolZones (storagePools []StoragePool ) ([]string , error ) {
466- zonesSet := sets.String {}
313+ zonesSet := sets .New [ string ]()
467314 var zones []string
468315 for _ , sp := range storagePools {
469316 if zonesSet .Has (sp .Zone ) {
0 commit comments