azure_file: try to get secret namespace from ClaimRef

This is the actual fix - attempt to obtain a namespace from ClaimRef.
Or fail if namespace could not be found instead of using "default".
This commit is contained in:
Roman Bednar 2022-02-07 11:13:11 +01:00
parent a2b0eddc44
commit 507c63c610

View File

@ -129,9 +129,21 @@ func (t *azureFileCSITranslator) TranslateInTreePVToCSI(pv *v1.PersistentVolume)
resourceGroup = v 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 { if azureSource.SecretNamespace != nil {
namespace = *azureSource.SecretNamespace 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) volumeID := fmt.Sprintf(volumeIDTemplate, resourceGroup, accountName, azureSource.ShareName, pv.ObjectMeta.Name, namespace)