diff --git a/staging/src/k8s.io/csi-translation-lib/plugins/azure_file_test.go b/staging/src/k8s.io/csi-translation-lib/plugins/azure_file_test.go index 19ba1f5225b..80a6519da13 100644 --- a/staging/src/k8s.io/csi-translation-lib/plugins/azure_file_test.go +++ b/staging/src/k8s.io/csi-translation-lib/plugins/azure_file_test.go @@ -223,6 +223,25 @@ func TestTranslateAzureFileInTreePVToCSI(t *testing.T) { volume: &corev1.PersistentVolume{}, expErr: true, }, + { + name: "return error if secret namespace could not be found", + volume: &corev1.PersistentVolume{ + ObjectMeta: metav1.ObjectMeta{ + Name: "uuid", + Annotations: map[string]string{resourceGroupAnnotation: "rg"}, + }, + Spec: corev1.PersistentVolumeSpec{ + PersistentVolumeSource: corev1.PersistentVolumeSource{ + AzureFile: &corev1.AzureFilePersistentVolumeSource{ + ShareName: "sharename", + SecretName: "secretname", + ReadOnly: true, + }, + }, + }, + }, + expErr: true, + }, { name: "azure file volume", volume: &corev1.PersistentVolume{ @@ -299,6 +318,51 @@ func TestTranslateAzureFileInTreePVToCSI(t *testing.T) { }, }, }, + { + name: "get secret namespace from ClaimRef when it's missing in pv spec source", + volume: &corev1.PersistentVolume{ + ObjectMeta: metav1.ObjectMeta{ + Name: "uuid", + Annotations: map[string]string{resourceGroupAnnotation: "rg"}, + }, + Spec: corev1.PersistentVolumeSpec{ + PersistentVolumeSource: corev1.PersistentVolumeSource{ + AzureFile: &corev1.AzureFilePersistentVolumeSource{ + ShareName: "sharename", + SecretName: "secretname", + //SecretNamespace: &secretNamespace, + ReadOnly: true, + }, + }, + ClaimRef: &corev1.ObjectReference{ + Namespace: secretNamespace, + }, + }, + }, + expVol: &corev1.PersistentVolume{ + ObjectMeta: metav1.ObjectMeta{ + Name: "uuid", + Annotations: map[string]string{resourceGroupAnnotation: "rg"}, + }, + Spec: corev1.PersistentVolumeSpec{ + PersistentVolumeSource: corev1.PersistentVolumeSource{ + CSI: &corev1.CSIPersistentVolumeSource{ + Driver: "file.csi.azure.com", + ReadOnly: true, + NodeStageSecretRef: &corev1.SecretReference{ + Name: "secretname", + Namespace: secretNamespace, + }, + VolumeAttributes: map[string]string{shareNameField: "sharename"}, + VolumeHandle: "rg#secretname#sharename#uuid#secretnamespace", + }, + }, + ClaimRef: &corev1.ObjectReference{ + Namespace: secretNamespace, + }, + }, + }, + }, } for _, tc := range cases {