mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 03:41:45 +00:00
Merge pull request #108000 from RomanBednar/af-namespace-fix
AzureFile: Volume without secretNamespace fails to mount after translating to CSI
This commit is contained in:
commit
bbc2dbb980
@ -129,9 +129,21 @@ func (t *azureFileCSITranslator) TranslateInTreePVToCSI(pv *v1.PersistentVolume)
|
||||
resourceGroup = v
|
||||
}
|
||||
}
|
||||
namespace := defaultSecretNamespace
|
||||
|
||||
// Secret is required when mounting a volume but pod presence cannot be assumed - we should not try to read pod now.
|
||||
namespace := ""
|
||||
// Try to read SecretNamespace from source pv.
|
||||
if azureSource.SecretNamespace != nil {
|
||||
namespace = *azureSource.SecretNamespace
|
||||
} else {
|
||||
// Try to read namespace from ClaimRef which should be always present.
|
||||
if pv.Spec.ClaimRef != nil {
|
||||
namespace = pv.Spec.ClaimRef.Namespace
|
||||
}
|
||||
}
|
||||
|
||||
if len(namespace) == 0 {
|
||||
return nil, fmt.Errorf("could not find a secret namespace in PersistentVolumeSource or ClaimRef")
|
||||
}
|
||||
|
||||
volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, azureSource.ShareName, pv.ObjectMeta.Name, namespace)
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user