Skip to content

Commit

Permalink
nodeserver: only try to mount volume if provisioning hasnt started al…
Browse files Browse the repository at this point in the history
…ready
  • Loading branch information
chaireze committed Jun 27, 2023
1 parent e1960ae commit 00e210f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
9 changes: 9 additions & 0 deletions pkg/util/pvutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 00e210f

Please sign in to comment.