Skip to content

Commit

Permalink
nodeserver, pvc_annotator: readd check to block stage volume from re …
Browse files Browse the repository at this point in the history
…adding annotations
  • Loading branch information
chaireez committed Aug 3, 2023
1 parent 5982ae7 commit f79888b
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
6 changes: 5 additions & 1 deletion pkg/blob/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,11 @@ func (d *Driver) NodeStageVolume(ctx context.Context, req *csi.NodeStageVolumeRe

err = annotator.SendProvisionVolume(pv, d.cloud.Config.AzureAuthConfig, providedAuth)
if err != nil {
return nil, err
if err == cv.ErrVolumeAlreadyBeingProvisioned {
klog.V(2).Infof("NodeStageVolume: volume has already been provisioned")
} else {
return nil, err
}
}

if err = d.edgeCacheManager.MountVolume(accountName, containerName, targetPath); err != nil {
Expand Down
25 changes: 24 additions & 1 deletion pkg/edgecache/cachevolume/pvc_annotator.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package cachevolume

import (
"errors"
"fmt"

"golang.org/x/exp/maps"
Expand All @@ -41,7 +42,8 @@ const (
)

var (
validStorageAuthentications = []string{"WorkloadIdentity", "AccountKey"}
validStorageAuthentications = []string{"WorkloadIdentity", "AccountKey"}
ErrVolumeAlreadyBeingProvisioned = errors.New("pv is already being provisioned")
)

type BlobAuth struct {
Expand Down Expand Up @@ -122,13 +124,34 @@ func (c *PVCAnnotator) buildAnnotations(pv *v1.PersistentVolume, cfg config.Azur
return annotations, nil
}

func (c *PVCAnnotator) needsToBeProvisioned(pvc *v1.PersistentVolumeClaim) bool {
// check if pv connected to the pvc has already been passed to be created
pvState, pvStateOk := pvc.ObjectMeta.Annotations[createVolumeAnnotation]
if pvStateOk && pvState == "no" {
return false
}

return true
}

func (c *PVCAnnotator) SendProvisionVolume(pv *v1.PersistentVolume, cloudConfig config.AzureAuthConfig, providedAuth BlobAuth) error {
pvc, err := blobcsiutil.GetPVCByName(c.client, pv.Spec.ClaimRef.Name, pv.Spec.ClaimRef.Namespace)
if err != nil {
return err
}

if prepare := c.needsToBeProvisioned(pvc); !prepare {
klog.Info("pv is already being provisioned")
return ErrVolumeAlreadyBeingProvisioned
}

if valid := c.requestAuthIsValid(providedAuth.authType); !valid {
err := fmt.Errorf("requested storage auth %s is not a member of valid auths %+v", providedAuth.authType, validStorageAuthentications)
klog.Error(err)
return err
}


Check failure on line 154 in pkg/edgecache/cachevolume/pvc_annotator.go

View workflow job for this annotation

GitHub Actions / Go Lint

File is not `gofmt`-ed with `-s` (gofmt)
annotations, err := c.buildAnnotations(pv, cloudConfig, providedAuth)
if err != nil {
return err
Expand Down

0 comments on commit f79888b

Please sign in to comment.