mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #94853 from andyzhangx/azurefile-migration-issue
fix azure file migration panic
This commit is contained in:
commit
57e9a41ae3
@ -119,9 +119,11 @@ func (t *azureFileCSITranslator) TranslateInTreePVToCSI(pv *v1.PersistentVolume)
|
|||||||
accountName = azureSource.SecretName
|
accountName = azureSource.SecretName
|
||||||
}
|
}
|
||||||
resourceGroup := ""
|
resourceGroup := ""
|
||||||
|
if pv.ObjectMeta.Annotations != nil {
|
||||||
if v, ok := pv.ObjectMeta.Annotations[resourceGroupAnnotation]; ok {
|
if v, ok := pv.ObjectMeta.Annotations[resourceGroupAnnotation]; ok {
|
||||||
resourceGroup = v
|
resourceGroup = v
|
||||||
}
|
}
|
||||||
|
}
|
||||||
volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, azureSource.ShareName, "")
|
volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, azureSource.ShareName, "")
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -183,6 +185,9 @@ func (t *azureFileCSITranslator) TranslateCSIPVToInTree(pv *v1.PersistentVolume)
|
|||||||
pv.Spec.CSI = nil
|
pv.Spec.CSI = nil
|
||||||
pv.Spec.AzureFile = azureSource
|
pv.Spec.AzureFile = azureSource
|
||||||
if resourceGroup != "" {
|
if resourceGroup != "" {
|
||||||
|
if pv.ObjectMeta.Annotations == nil {
|
||||||
|
pv.ObjectMeta.Annotations = map[string]string{}
|
||||||
|
}
|
||||||
pv.ObjectMeta.Annotations[resourceGroupAnnotation] = resourceGroup
|
pv.ObjectMeta.Annotations[resourceGroupAnnotation] = resourceGroup
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -282,6 +282,120 @@ func TestTranslateAzureFileInTreePVToCSI(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTranslateCSIPVToInTree(t *testing.T) {
|
||||||
|
translator := NewAzureFileCSITranslator()
|
||||||
|
|
||||||
|
secretNamespace := "secretnamespace"
|
||||||
|
mp := make(map[string]string)
|
||||||
|
mp["shareName"] = "unit-test"
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
volume *corev1.PersistentVolume
|
||||||
|
expVol *corev1.PersistentVolume
|
||||||
|
expErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "empty volume",
|
||||||
|
expErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "resource group empty",
|
||||||
|
volume: &corev1.PersistentVolume{
|
||||||
|
Spec: corev1.PersistentVolumeSpec{
|
||||||
|
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||||
|
CSI: &corev1.CSIPersistentVolumeSource{
|
||||||
|
NodeStageSecretRef: &corev1.SecretReference{
|
||||||
|
Name: "ut",
|
||||||
|
Namespace: secretNamespace,
|
||||||
|
},
|
||||||
|
ReadOnly: true,
|
||||||
|
VolumeAttributes: mp,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expVol: &corev1.PersistentVolume{
|
||||||
|
Spec: corev1.PersistentVolumeSpec{
|
||||||
|
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||||
|
AzureFile: &corev1.AzureFilePersistentVolumeSource{
|
||||||
|
SecretName: "ut",
|
||||||
|
SecretNamespace: &secretNamespace,
|
||||||
|
ReadOnly: true,
|
||||||
|
ShareName: "unit-test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "translate from volume handle error",
|
||||||
|
volume: &corev1.PersistentVolume{
|
||||||
|
Spec: corev1.PersistentVolumeSpec{
|
||||||
|
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||||
|
CSI: &corev1.CSIPersistentVolumeSource{
|
||||||
|
VolumeHandle: "unit-test",
|
||||||
|
ReadOnly: true,
|
||||||
|
VolumeAttributes: mp,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "translate from volume handle",
|
||||||
|
volume: &corev1.PersistentVolume{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "file.csi.azure.com-sharename",
|
||||||
|
},
|
||||||
|
Spec: corev1.PersistentVolumeSpec{
|
||||||
|
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||||
|
CSI: &corev1.CSIPersistentVolumeSource{
|
||||||
|
VolumeHandle: "rg#st#pvc-file-dynamic#diskname.vhd",
|
||||||
|
ReadOnly: true,
|
||||||
|
VolumeAttributes: mp,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expVol: &corev1.PersistentVolume{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "file.csi.azure.com-sharename",
|
||||||
|
Annotations: map[string]string{resourceGroupAnnotation: "rg"},
|
||||||
|
},
|
||||||
|
Spec: corev1.PersistentVolumeSpec{
|
||||||
|
PersistentVolumeSource: corev1.PersistentVolumeSource{
|
||||||
|
AzureFile: &corev1.AzureFilePersistentVolumeSource{
|
||||||
|
SecretName: "azure-storage-account-st-secret",
|
||||||
|
ShareName: "pvc-file-dynamic",
|
||||||
|
ReadOnly: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expErr: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range cases {
|
||||||
|
t.Logf("Testing %v", tc.name)
|
||||||
|
got, err := translator.TranslateCSIPVToInTree(tc.volume)
|
||||||
|
if err != nil && !tc.expErr {
|
||||||
|
t.Errorf("Did not expect error but got: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
if err == nil && tc.expErr {
|
||||||
|
t.Errorf("Expected error, but did not get one.")
|
||||||
|
}
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(got, tc.expVol) {
|
||||||
|
t.Errorf("Got parameters: %v, expected :%v", got, tc.expVol)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetStorageAccount(t *testing.T) {
|
func TestGetStorageAccount(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
secretName string
|
secretName string
|
||||||
|
Loading…
Reference in New Issue
Block a user