@@ -41,6 +41,8 @@ const (
41
41
42
42
secretNameTemplate = "azure-storage-account-%s-secret"
43
43
defaultSecretNamespace = "default"
44
+
45
+ resourceGroupAnnotation = "kubernetes.io/azure-file-resource-group"
44
46
)
45
47
46
48
var _ InTreePlugin = & azureFileCSITranslator {}
@@ -116,7 +118,11 @@ func (t *azureFileCSITranslator) TranslateInTreePVToCSI(pv *v1.PersistentVolume)
116
118
klog .Warningf ("getStorageAccountName(%s) returned with error: %v" , azureSource .SecretName , err )
117
119
accountName = azureSource .SecretName
118
120
}
119
- volumeID := fmt .Sprintf (volumeIDTemplate , "" , accountName , azureSource .ShareName , "" )
121
+ resourceGroup := ""
122
+ if v , ok := pv .ObjectMeta .Annotations [resourceGroupAnnotation ]; ok {
123
+ resourceGroup = v
124
+ }
125
+ volumeID := fmt .Sprintf (volumeIDTemplate , resourceGroup , accountName , azureSource .ShareName , "" )
120
126
121
127
var (
122
128
// refer to https://github.com/kubernetes-sigs/azurefile-csi-driver/blob/master/docs/driver-parameters.md
@@ -155,6 +161,7 @@ func (t *azureFileCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume)
155
161
ReadOnly : csiSource .ReadOnly ,
156
162
}
157
163
164
+ resourceGroup := ""
158
165
if csiSource .NodeStageSecretRef != nil && csiSource .NodeStageSecretRef .Name != "" {
159
166
azureSource .SecretName = csiSource .NodeStageSecretRef .Name
160
167
azureSource .SecretNamespace = & csiSource .NodeStageSecretRef .Namespace
@@ -164,16 +171,20 @@ func (t *azureFileCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume)
164
171
}
165
172
}
166
173
} else {
167
- _ , storageAccount , fileShareName , _ , err := getFileShareInfo (csiSource .VolumeHandle )
174
+ rg , storageAccount , fileShareName , _ , err := getFileShareInfo (csiSource .VolumeHandle )
168
175
if err != nil {
169
176
return nil , err
170
177
}
171
178
azureSource .ShareName = fileShareName
172
179
azureSource .SecretName = fmt .Sprintf (secretNameTemplate , storageAccount )
180
+ resourceGroup = rg
173
181
}
174
182
175
183
pv .Spec .CSI = nil
176
184
pv .Spec .AzureFile = azureSource
185
+ if resourceGroup != "" {
186
+ pv .ObjectMeta .Annotations [resourceGroupAnnotation ] = resourceGroup
187
+ }
177
188
178
189
return pv , nil
179
190
}
0 commit comments