From 0d4799964558b1e96587737613d6e79e1679cb82 Mon Sep 17 00:00:00 2001 From: andyzhangx Date: Thu, 17 Sep 2020 13:19:13 +0000 Subject: [PATCH] fix azure file migration panic --- .../src/k8s.io/csi-translation-lib/plugins/azure_file.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/staging/src/k8s.io/csi-translation-lib/plugins/azure_file.go b/staging/src/k8s.io/csi-translation-lib/plugins/azure_file.go index ff1c2b0b517..94ef714fe27 100644 --- a/staging/src/k8s.io/csi-translation-lib/plugins/azure_file.go +++ b/staging/src/k8s.io/csi-translation-lib/plugins/azure_file.go @@ -119,8 +119,10 @@ func (t *azureFileCSITranslator) TranslateInTreePVToCSI(pv *v1.PersistentVolume) accountName = azureSource.SecretName } resourceGroup := "" - if v, ok := pv.ObjectMeta.Annotations[resourceGroupAnnotation]; ok { - resourceGroup = v + if pv.ObjectMeta.Annotations != nil { + if v, ok := pv.ObjectMeta.Annotations[resourceGroupAnnotation]; ok { + resourceGroup = v + } } volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, azureSource.ShareName, "") @@ -183,6 +185,9 @@ func (t *azureFileCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume) pv.Spec.CSI = nil pv.Spec.AzureFile = azureSource if resourceGroup != "" { + if pv.ObjectMeta.Annotations == nil { + pv.ObjectMeta.Annotations = map[string]string{} + } pv.ObjectMeta.Annotations[resourceGroupAnnotation] = resourceGroup }