@@ -35,6 +35,11 @@ import (
35
35
"k8s.io/legacy-cloud-providers/azure"
36
36
)
37
37
38
+ const (
39
+ TagsDelimiter = ","
40
+ TagKeyValueDelimiter = "="
41
+ )
42
+
38
43
type azureDiskProvisioner struct {
39
44
plugin * azureDataDiskPlugin
40
45
options volume.VolumeOptions
@@ -118,6 +123,7 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
118
123
diskIopsReadWrite string
119
124
diskMbpsReadWrite string
120
125
diskEncryptionSetID string
126
+ customTags string
121
127
122
128
maxShares int
123
129
)
@@ -164,6 +170,8 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
164
170
diskMbpsReadWrite = v
165
171
case "diskencryptionsetid" :
166
172
diskEncryptionSetID = v
173
+ case "tags" :
174
+ customTags = v
167
175
case azure .WriteAcceleratorEnabled :
168
176
writeAcceleratorEnabled = v
169
177
case "maxshares" :
@@ -261,9 +269,14 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
261
269
diskURI := ""
262
270
labels := map [string ]string {}
263
271
if kind == v1 .AzureManagedDisk {
264
- tags := make (map [string ]string )
272
+ tags , err := ConvertTagsToMap (customTags )
273
+ if err != nil {
274
+ return nil , err
275
+ }
265
276
if p .options .CloudTags != nil {
266
- tags = * (p .options .CloudTags )
277
+ for k , v := range * (p .options .CloudTags ) {
278
+ tags [k ] = v
279
+ }
267
280
}
268
281
if strings .EqualFold (writeAcceleratorEnabled , "true" ) {
269
282
tags [azure .WriteAcceleratorEnabled ] = "true"
@@ -386,3 +399,28 @@ func (p *azureDiskProvisioner) Provision(selectedNode *v1.Node, allowedTopologie
386
399
387
400
return pv , nil
388
401
}
402
+
403
+ // ConvertTagsToMap convert the tags from string to map
404
+ // the valid tags fomat is "key1=value1,key2=value2", which could be converted to
405
+ // {"key1": "value1", "key2": "value2"}
406
+ func ConvertTagsToMap (tags string ) (map [string ]string , error ) {
407
+ m := make (map [string ]string )
408
+ if tags == "" {
409
+ return m , nil
410
+ }
411
+ s := strings .Split (tags , TagsDelimiter )
412
+ for _ , tag := range s {
413
+ kv := strings .Split (tag , TagKeyValueDelimiter )
414
+ if len (kv ) != 2 {
415
+ return nil , fmt .Errorf ("Tags '%s' are invalid, the format should like: 'key1=value1,key2=value2'" , tags )
416
+ }
417
+ key := strings .TrimSpace (kv [0 ])
418
+ if key == "" {
419
+ return nil , fmt .Errorf ("Tags '%s' are invalid, the format should like: 'key1=value1,key2=value2'" , tags )
420
+ }
421
+ value := strings .TrimSpace (kv [1 ])
422
+ m [key ] = value
423
+ }
424
+
425
+ return m , nil
426
+ }
0 commit comments