Implement controller publish/transfer logic + node mount/unmount

This commit is contained in:
2024-10-01 22:58:35 -04:00
parent b9f2259674
commit beee5a441d
4 changed files with 112 additions and 11 deletions

View File

@@ -41,14 +41,16 @@ var (
type nodeService struct {
nodeID string
p5x *p5xApi
csi.UnimplementedNodeServer
}
var _ csi.NodeServer = &nodeService{}
func newNodeService(nodeID string) nodeService {
func newNodeService(nodeID string, p5x *p5xApi) nodeService {
return nodeService{
nodeID: nodeID,
p5x: p5x,
}
}
@@ -101,13 +103,21 @@ func (n *nodeService) NodePublishVolume(ctx context.Context, request *csi.NodePu
}
if readOnly {
// Todo add readonly in your mount options
options["mountReadOnly"] = "true"
}
// TODO modify your volume mount logic here
vol, err := n.p5x.GetVolumeByName(request.GetVolumeId())
if err != nil {
return nil, err
}
return nil, status.Error(codes.Unimplemented, "node.NodePublishVolume")
// return &csi.NodePublishVolumeResponse{}, nil
_, err = n.p5x.MountVolume(vol, request.GetTargetPath(), options)
if err != nil {
return nil, err
}
klog.Infof("node.NodePublishVolume: Successfully published volume %s -> %s", request.GetVolumeId(), request.GetTargetPath())
return &csi.NodePublishVolumeResponse{}, nil
}
// NodeUnpublishVolume unmount the volume from the target path
@@ -119,10 +129,18 @@ func (n *nodeService) NodeUnpublishVolume(ctx context.Context, request *csi.Node
return nil, status.Error(codes.InvalidArgument, "Target path not provided")
}
// TODO modify your volume umount logic here
vol, err := n.p5x.GetVolumeByName(request.GetVolumeId())
if err != nil {
return nil, err
}
return nil, status.Error(codes.Unimplemented, "node.NodeUnpublishVolume")
// return &csi.NodeUnpublishVolumeResponse{}, nil
_, err = n.p5x.UnmountVolume(vol)
if err != nil {
return nil, err
}
klog.Infof("node.NodeUnpublishVolume: Successfully unpublished volume %s -> %s", request.GetVolumeId(), request.GetTargetPath())
return &csi.NodeUnpublishVolumeResponse{}, nil
}
// NodeGetVolumeStats get the volume stats