Skip to content

Commit

Permalink
feat(EVS): add create EVS shared type disk.
Browse files Browse the repository at this point in the history
  • Loading branch information
Zippo-Wang committed Feb 26, 2024
1 parent 7d162ae commit e89fd6a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions docs/evs/evs.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ For sidecar version compatibility, please refer compatibility matrix for each si
* `dssId` Optional. ID of the dedicated distributed storage used when creating a dedicated file system.
It is located under `parameters`.

* `multiattach` Optional. Whether it is a shared disk. default to `"false"`. It is located under `parameters`.

* `scsi` Optional. The device type of the EVS disks to be created. Defaults to `"false"`.
It is located under `parameters`.
- `"true"`: the disk device type will be SCSI, which allows ECS OSs to directly access underlying storage media.
Expand Down
20 changes: 19 additions & 1 deletion pkg/evs/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,20 @@ func (cs *ControllerServer) CreateVolume(_ context.Context, req *csi.CreateVolum
}
}

// Check if the volume can be shared
multiattach, err := strconv.ParseBool(parameters["multiattach"])
if err != nil {
log.Errorf("failed to transform string to boolean: %s", err)
return nil, err
}

metadata := cs.parseMetadata(req, snapshotID)
createOpts := &cloudvolumes.CreateOpts{
Volume: cloudvolumes.VolumeOpts{
Name: volName,
Size: sizeGB,
VolumeType: volumeType,
Multiattach: multiattach,
AvailabilityZone: volumeAz,
SnapshotID: snapshotID,
Metadata: metadata,
Expand Down Expand Up @@ -254,6 +262,7 @@ const (
VolumeAttachingOtherServer
VolumeAttachedCurrentServer
VolumeAttachedOtherServer
VolumeAttachedManyServer
VolumeAttachError
)

Expand Down Expand Up @@ -291,6 +300,11 @@ func (cs *ControllerServer) ControllerPublishVolume(_ context.Context, req *csi.
return buildPublishVolumeResponse(volume, instanceID), nil
case VolumeAttachedOtherServer:
return nil, status.Errorf(codes.Internal, "Error, volume: %s is in used by another server", volumeID)
case VolumeAttachedManyServer:
if err := services.AttachVolumeCompleted(credentials, instanceID, volumeID); err != nil {
return nil, status.Errorf(codes.Internal, "Failed to publish volume %s to ECS %s with error %v",
volumeID, instanceID, err)
}
default:
return nil, status.Errorf(codes.Internal, "Error, status: %s was found in volume: %s, ",
volume.Status, volume.ID)
Expand Down Expand Up @@ -320,6 +334,7 @@ func buildPublishVolumeResponse(volume *cloudvolumes.Volume, instanceID string)
}

func volumeAttachmentStatus(volume *cloudvolumes.Volume, instanceID string) VolumeAttachmentStatus {

Check failure on line 336 in pkg/evs/controllerserver.go

View workflow job for this annotation

GitHub Actions / lint

cyclomatic complexity 16 of func `volumeAttachmentStatus` is high (> 15) (gocyclo)
shareType := volume.Multiattach
attachment := false // use to decide whether volume has attached on current instance
for _, v := range volume.Attachments {
if v.ServerID == instanceID {
Expand All @@ -341,9 +356,12 @@ func volumeAttachmentStatus(volume *cloudvolumes.Volume, instanceID string) Volu
if services.EvsInUseStatus == volumeStatus && attachment {
return VolumeAttachedCurrentServer
}
if services.EvsInUseStatus == volumeStatus && !attachment {
if services.EvsInUseStatus == volumeStatus && !attachment && !shareType {
return VolumeAttachedOtherServer
}
if services.EvsInUseStatus == volumeStatus && !attachment && shareType {
return VolumeAttachedManyServer
}
return VolumeAttachError
}

Expand Down
1 change: 1 addition & 0 deletions pkg/evs/services/volumes.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ func CreateCinderCompleted(c *config.CloudCredentials, opts *cloudvolumes.Create
Name: opts.Volume.Name,
Size: opts.Volume.Size,
VolumeType: opts.Volume.VolumeType,
Multiattach: opts.Volume.Multiattach,
AvailabilityZone: opts.Volume.AvailabilityZone,
SnapshotID: opts.Volume.SnapshotID,
Metadata: opts.Volume.Metadata,
Expand Down

0 comments on commit e89fd6a

Please sign in to comment.