Skip to content

Commit

Permalink
fix(multi-attach): remove volume attach-detach functionality (#134)
Browse files Browse the repository at this point in the history
Signed-off-by: Payes Anand <[email protected]>
  • Loading branch information
payes authored Jan 8, 2021
1 parent e3e4c56 commit adaaa44
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 82 deletions.
2 changes: 1 addition & 1 deletion deploy/csi-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ spec:
# To determine at runtime which mode a volume uses, pod info and its
# "csi.storage.k8s.io/ephemeral" entry are needed.
podInfoOnMount: true
attachRequired: true
attachRequired: false
---

kind: ClusterRoleBinding
Expand Down
2 changes: 1 addition & 1 deletion deploy/csidriver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ spec:
# To determine at runtime which mode a volume uses, pod info and its
# "csi.storage.k8s.io/ephemeral" entry are needed.
podInfoOnMount: true
attachRequired: true
attachRequired: false
11 changes: 2 additions & 9 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -211,11 +211,7 @@ func (cs *controller) ControllerPublishVolume(
req *csi.ControllerPublishVolumeRequest,
) (*csi.ControllerPublishVolumeResponse, error) {

if err := prepareVolumeForNode(req); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

return &csi.ControllerPublishVolumeResponse{}, nil
return nil, status.Error(codes.Unimplemented, "")
}

// ControllerUnpublishVolume removes a previously
Expand All @@ -226,10 +222,7 @@ func (cs *controller) ControllerUnpublishVolume(
ctx context.Context,
req *csi.ControllerUnpublishVolumeRequest,
) (*csi.ControllerUnpublishVolumeResponse, error) {
if err := utils.DeleteCStorVolumeAttachmentCR(req.GetVolumeId() + "-" + req.GetNodeId()); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &csi.ControllerUnpublishVolumeResponse{}, nil
return nil, status.Error(codes.Unimplemented, "")
}

// ControllerExpandVolume resizes previously provisioned volume
Expand Down
71 changes: 0 additions & 71 deletions pkg/driver/controller_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,11 @@ package driver

import (
"fmt"
"time"

"github.com/container-storage-interface/spec/lib/go/csi"
apis "github.com/openebs/cstor-csi/pkg/apis/cstor/v1"
"github.com/openebs/cstor-csi/pkg/cstor/volumeattachment"
utils "github.com/openebs/cstor-csi/pkg/utils"
"github.com/pkg/errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
k8serror "k8s.io/apimachinery/pkg/api/errors"
)

// SupportedVolumeCapabilityAccessModes contains the list of supported access
Expand Down Expand Up @@ -56,7 +51,6 @@ func newControllerCapabilities() []*csi.ControllerServiceCapability {
var capabilities []*csi.ControllerServiceCapability
for _, cap := range []csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME,
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
Expand Down Expand Up @@ -201,68 +195,3 @@ func (cs *controller) validateDeleteVolumeReq(req *csi.DeleteVolumeRequest) erro
}
return nil
}

func prepareVolumeForNode(
req *csi.ControllerPublishVolumeRequest,
) error {
volumeID := req.GetVolumeId()
nodeID := req.GetNodeId()

if err := utils.PatchCVCNodeID(volumeID, nodeID); err != nil {
return err
}

labels := map[string]string{
"nodeID": nodeID,
"Volname": volumeID,
}

// If the access type is block, do nothing for stage
var accessType string
switch req.GetVolumeCapability().GetAccessType().(type) {
case *csi.VolumeCapability_Block:
accessType = "block"
case *csi.VolumeCapability_Mount:
accessType = "mount"
}

vol, err := volumeattachment.NewBuilder().
WithName(volumeID + "-" + nodeID).
WithLabels(labels).
WithVolName(req.GetVolumeId()).
WithAccessType(accessType).
WithFSType(req.GetVolumeCapability().GetMount().GetFsType()).
WithReadOnly(req.GetReadonly()).Build()
if err != nil {
return err
}
if isCVCBound, err := utils.IsCVCBound(volumeID); err != nil {
return status.Error(codes.Internal, err.Error())
} else if !isCVCBound {
utils.TransitionVolList[volumeID] = apis.CStorVolumeAttachmentStatusWaitingForCVCBound
time.Sleep(10 * time.Second)
return errors.New("Waiting for CVC to be bound")
}

if err = utils.FetchAndUpdateISCSIDetails(volumeID, vol); err != nil {
return err
}

oldvol, err := utils.GetCStorVolumeAttachment(vol.Name)
if err != nil && !k8serror.IsNotFound(err) {
return err
} else if err == nil && oldvol != nil {
if oldvol.DeletionTimestamp != nil {
return errors.Errorf("Volume still mounted on node: %s", nodeID)
}
return nil
}

if err = utils.DeleteOldCStorVolumeAttachmentCRs(volumeID); err != nil {
return status.Error(codes.Internal, err.Error())
}
if err = utils.CreateCStorVolumeAttachmentCR(vol, nodeID); err != nil {
return status.Error(codes.Internal, err.Error())
}
return nil
}
7 changes: 7 additions & 0 deletions pkg/driver/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ func (ns *node) NodeStageVolume(
}
defer removeVolumeFromTransitionList(volumeID)

if err := ns.prepareVolumeForNode(req); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

if vol, err = utils.GetCStorVolumeAttachment(volumeID + "-" + utils.NodeIDENV); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
Expand Down Expand Up @@ -281,6 +285,9 @@ func (ns *node) NodeUnstageVolume(
logrus.Infof("cstor-csi: volume %s path: %s has been unmounted.",
volumeID, stagingTargetPath)

if err := utils.DeleteCStorVolumeAttachmentCR(req.GetVolumeId() + "-" + ns.driver.config.NodeID); err != nil {
return nil, status.Error(codes.Internal, err.Error())
}
return &csi.NodeUnstageVolumeResponse{}, nil
}

Expand Down
70 changes: 70 additions & 0 deletions pkg/driver/node_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,19 @@ import (
"path/filepath"
"strings"

"time"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/csi-lib-iscsi/iscsi"
apis "github.com/openebs/cstor-csi/pkg/apis/cstor/v1"
"github.com/openebs/cstor-csi/pkg/cstor/volumeattachment"
iscsiutils "github.com/openebs/cstor-csi/pkg/iscsi"
utils "github.com/openebs/cstor-csi/pkg/utils"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
k8serror "k8s.io/apimachinery/pkg/api/errors"
)

func getTargetIP(url string) string {
Expand Down Expand Up @@ -311,3 +316,68 @@ func (ns *node) validateNodeUnStageReq(
}
return nil
}

func (ns *node) prepareVolumeForNode(
req *csi.NodeStageVolumeRequest,
) error {
volumeID := req.GetVolumeId()
nodeID := ns.driver.config.NodeID

if err := utils.PatchCVCNodeID(volumeID, nodeID); err != nil {
return err
}

labels := map[string]string{
"nodeID": nodeID,
"Volname": volumeID,
}

// If the access type is block, do nothing for stage
var accessType string
switch req.GetVolumeCapability().GetAccessType().(type) {
case *csi.VolumeCapability_Block:
accessType = "block"
case *csi.VolumeCapability_Mount:
accessType = "mount"
}

vol, err := volumeattachment.NewBuilder().
WithName(volumeID + "-" + nodeID).
WithLabels(labels).
WithVolName(req.GetVolumeId()).
WithAccessType(accessType).
WithFSType(req.GetVolumeCapability().GetMount().GetFsType()).
WithReadOnly(false).Build()
if err != nil {
return err
}
if isCVCBound, err := utils.IsCVCBound(volumeID); err != nil {
return status.Error(codes.Internal, err.Error())
} else if !isCVCBound {
utils.TransitionVolList[volumeID] = apis.CStorVolumeAttachmentStatusWaitingForCVCBound
time.Sleep(10 * time.Second)
return errors.New("Waiting for CVC to be bound")
}

if err = utils.FetchAndUpdateISCSIDetails(volumeID, vol); err != nil {
return err
}

oldvol, err := utils.GetCStorVolumeAttachment(vol.Name)
if err != nil && !k8serror.IsNotFound(err) {
return err
} else if err == nil && oldvol != nil {
if oldvol.DeletionTimestamp != nil {
return errors.Errorf("Volume still mounted on node: %s", nodeID)
}
return nil
}

if err = utils.DeleteOldCStorVolumeAttachmentCRs(volumeID); err != nil {
return status.Error(codes.Internal, err.Error())
}
if err = utils.CreateCStorVolumeAttachmentCR(vol, nodeID); err != nil {
return status.Error(codes.Internal, err.Error())
}
return nil
}

0 comments on commit adaaa44

Please sign in to comment.