diff --git a/pkg/blob/nodeserver.go b/pkg/blob/nodeserver.go index cf7dc2d56..12f900b14 100644 --- a/pkg/blob/nodeserver.go +++ b/pkg/blob/nodeserver.go @@ -350,16 +350,18 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe return nil, err } - // attempt to figure out the name of the kube secret for the storage account key - if len(secretName) == 0 { // if the keyName wasn't already figured out by 'GetAuthEnv' - secretName, exists = pv.ObjectMeta.Annotations[provisionerSecretNameField] - secretNamespace = pv.ObjectMeta.Annotations[provisionerSecretNamespaceField] - if !exists { // if keyName doesn't exist in the PV annotations - klog.Errorf("Failed to discover storage account key name.") - return nil, fmt.Errorf("failed to discover storage account key name") - } + pvc, err := blobcsiutil.GetPVCByName(d.cloud.KubeClient, pv.Spec.ClaimRef.Name, pv.Spec.ClaimRef.Namespace) + if err != nil { + return nil, err } + // check if this pv is already trying to be mounted + pvState, pvStateOk := pvc.ObjectMeta.Annotations["external/edgecache-create-volume"] + if pvStateOk && pvState == "no" { + err = fmt.Errorf("pv is already being provisioned") + klog.Error(err) + return nil, err + } // get authentication method storageAuthType, storageAuthTypeOk := attrib[EcStrgAuthenticationField] diff --git a/pkg/util/pvutil.go b/pkg/util/pvutil.go index fa2eaeffc..877ed3f83 100644 --- a/pkg/util/pvutil.go +++ b/pkg/util/pvutil.go @@ -59,6 +59,15 @@ func GetPVByName(client clientset.Interface, pvName string) (*v1.PersistentVolum return pv, nil } +func GetPVCByName(client clientset.Interface, pvcName string, namespace string) (*v1.PersistentVolumeClaim, error) { + pvc, err := client.CoreV1().PersistentVolumeClaims(namespace).Get(context.TODO(), pvcName, metav1.GetOptions{}) + if err != nil { + klog.Errorf("unable to get PVC %s", pvcName) + return nil, err + } + return pvc, nil +} + var CustomRetry = wait.Backoff{ Steps: 5, Duration: 10 * time.Millisecond,