@@ -19,6 +19,8 @@ package common
19
19
import (
20
20
"fmt"
21
21
"strings"
22
+
23
+ "k8s.io/klog/v2"
22
24
)
23
25
24
26
const (
@@ -32,7 +34,11 @@ const (
32
34
ParameterAvailabilityClass = "availability-class"
33
35
ParameterKeyEnableConfidentialCompute = "enable-confidential-storage"
34
36
ParameterKeyStoragePools = "storage-pools"
35
- ParameterKeyResourceTags = "resource-tags"
37
+
38
+ // Parameters for Data Cache
39
+ ParameterKeyDataCacheSize = "data-cache-size"
40
+ ParameterKeyDataCacheMode = "data-cache-mode"
41
+ ParameterKeyResourceTags = "resource-tags"
36
42
37
43
// Parameters for VolumeSnapshotClass
38
44
ParameterKeyStorageLocations = "storage-locations"
@@ -68,6 +74,16 @@ const (
68
74
tagKeyCreatedForSnapshotContentName = "kubernetes.io/created-for/volumesnapshotcontent/name"
69
75
)
70
76
77
+ type DataCacheParameters struct {
78
+ // Values: {string}
79
+ // Default: ""
80
+ // Example: "25Gi"
81
+ DataCacheSize string
82
+ // Values: writethrough, writeback
83
+ // Default: writethrough
84
+ DataCacheMode string
85
+ }
86
+
71
87
// DiskParameters contains normalized and defaulted disk parameters
72
88
type DiskParameters struct {
73
89
// Values: pd-standard, pd-balanced, pd-ssd, or any other PD disk type. Not validated.
@@ -125,7 +141,7 @@ type StoragePool struct {
125
141
// put them into a well defined struct making sure to default unspecified fields.
126
142
// extraVolumeLabels are added as labels; if there are also labels specified in
127
143
// parameters, any matching extraVolumeLabels will be overridden.
128
- func ExtractAndDefaultParameters (parameters map [string ]string , driverName string , extraVolumeLabels map [string ]string , enableStoragePools bool , extraTags map [string ]string ) (DiskParameters , error ) {
144
+ func ExtractAndDefaultParameters (parameters map [string ]string , driverName string , extraVolumeLabels map [string ]string , enableStoragePools bool , enableDataCache bool , extraTags map [string ]string ) (DiskParameters , DataCacheParameters , error ) {
129
145
p := DiskParameters {
130
146
DiskType : "pd-standard" , // Default
131
147
ReplicationType : replicationTypeNone , // Default
@@ -135,6 +151,12 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
135
151
ResourceTags : make (map [string ]string ), // Default
136
152
}
137
153
154
+ // Set data cache feature default
155
+ d := DataCacheParameters {}
156
+ if enableDataCache {
157
+ d .DataCacheMode = "writethrough"
158
+ }
159
+
138
160
for k , v := range extraVolumeLabels {
139
161
p .Labels [k ] = v
140
162
}
@@ -169,7 +191,7 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
169
191
case ParameterKeyLabels :
170
192
paramLabels , err := ConvertLabelsStringToMap (v )
171
193
if err != nil {
172
- return p , fmt .Errorf ("parameters contain invalid labels parameter: %w" , err )
194
+ return p , d , fmt .Errorf ("parameters contain invalid labels parameter: %w" , err )
173
195
}
174
196
// Override any existing labels with those from this parameter.
175
197
for labelKey , labelValue := range paramLabels {
@@ -178,58 +200,71 @@ func ExtractAndDefaultParameters(parameters map[string]string, driverName string
178
200
case ParameterKeyProvisionedIOPSOnCreate :
179
201
paramProvisionedIOPSOnCreate , err := ConvertStringToInt64 (v )
180
202
if err != nil {
181
- return p , fmt .Errorf ("parameters contain invalid provisionedIOPSOnCreate parameter: %w" , err )
203
+ return p , d , fmt .Errorf ("parameters contain invalid provisionedIOPSOnCreate parameter: %w" , err )
182
204
}
183
205
p .ProvisionedIOPSOnCreate = paramProvisionedIOPSOnCreate
184
206
case ParameterKeyProvisionedThroughputOnCreate :
185
207
paramProvisionedThroughputOnCreate , err := ConvertMiStringToInt64 (v )
186
208
if err != nil {
187
- return p , fmt .Errorf ("parameters contain invalid provisionedThroughputOnCreate parameter: %w" , err )
209
+ return p , d , fmt .Errorf ("parameters contain invalid provisionedThroughputOnCreate parameter: %w" , err )
188
210
}
189
211
p .ProvisionedThroughputOnCreate = paramProvisionedThroughputOnCreate
190
212
case ParameterAvailabilityClass :
191
213
paramAvailabilityClass , err := ConvertStringToAvailabilityClass (v )
192
214
if err != nil {
193
- return p , fmt .Errorf ("parameters contain invalid availability class parameter: %w" , err )
215
+ return p , d , fmt .Errorf ("parameters contain invalid availability class parameter: %w" , err )
194
216
}
195
217
if paramAvailabilityClass == ParameterRegionalHardFailoverClass {
196
218
p .ForceAttach = true
197
219
}
198
220
case ParameterKeyEnableConfidentialCompute :
199
221
paramEnableConfidentialCompute , err := ConvertStringToBool (v )
200
222
if err != nil {
201
- return p , fmt .Errorf ("parameters contain invalid value for enable-confidential-storage parameter: %w" , err )
223
+ return p , d , fmt .Errorf ("parameters contain invalid value for enable-confidential-storage parameter: %w" , err )
202
224
}
203
225
204
226
if paramEnableConfidentialCompute {
205
227
// DiskEncryptionKmsKey is needed to enable confidentialStorage
206
228
if val , ok := parameters [ParameterKeyDiskEncryptionKmsKey ]; ! ok || ! isValidDiskEncryptionKmsKey (val ) {
207
- return p , fmt .Errorf ("Valid %v is required to enable ConfidentialStorage" , ParameterKeyDiskEncryptionKmsKey )
229
+ return p , d , fmt .Errorf ("Valid %v is required to enable ConfidentialStorage" , ParameterKeyDiskEncryptionKmsKey )
208
230
}
209
231
}
210
232
211
233
p .EnableConfidentialCompute = paramEnableConfidentialCompute
212
234
case ParameterKeyStoragePools :
213
235
if ! enableStoragePools {
214
- return p , fmt .Errorf ("parameters contains invalid option %q" , ParameterKeyStoragePools )
236
+ return p , d , fmt .Errorf ("parameters contains invalid option %q" , ParameterKeyStoragePools )
215
237
}
216
238
storagePools , err := ParseStoragePools (v )
217
239
if err != nil {
218
- return p , fmt .Errorf ("parameters contain invalid value for %s parameter: %w" , ParameterKeyStoragePools , err )
240
+ return p , d , fmt .Errorf ("parameters contain invalid value for %s parameter: %w" , ParameterKeyStoragePools , err )
219
241
}
220
242
p .StoragePools = storagePools
243
+ case ParameterKeyDataCacheSize :
244
+ if ! enableDataCache {
245
+ return p , d , fmt .Errorf ("parameters contains invalid option %q" , ParameterKeyDataCacheSize )
246
+ }
247
+ // TODO: need to parse or validate the string
248
+ d .DataCacheSize = v
249
+ klog .V (2 ).Infof ("====== Data cache size is %v ======" , v )
250
+ case ParameterKeyDataCacheMode :
251
+ if ! enableDataCache {
252
+ return p , d , fmt .Errorf ("parameters contains invalid option %q" , ParameterKeyDataCacheSize )
253
+ }
254
+ d .DataCacheMode = v
255
+ klog .V (2 ).Infof ("====== Data cache mode is %v ======" , v )
221
256
case ParameterKeyResourceTags :
222
257
if err := extractResourceTagsParameter (v , p .ResourceTags ); err != nil {
223
- return p , err
258
+ return p , d , err
224
259
}
225
260
default :
226
- return p , fmt .Errorf ("parameters contains invalid option %q" , k )
261
+ return p , d , fmt .Errorf ("parameters contains invalid option %q" , k )
227
262
}
228
263
}
229
264
if len (p .Tags ) > 0 {
230
265
p .Tags [tagKeyCreatedBy ] = driverName
231
266
}
232
- return p , nil
267
+ return p , d , nil
233
268
}
234
269
235
270
func ExtractAndDefaultSnapshotParameters (parameters map [string ]string , driverName string , extraTags map [string ]string ) (SnapshotParameters , error ) {
0 commit comments