Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(EVS): add create EVS shared type disk. #141

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
}
}

// 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 @@
VolumeAttachingOtherServer
VolumeAttachedCurrentServer
VolumeAttachedOtherServer
VolumeAttachedManyServer
VolumeAttachError
)

Expand Down Expand Up @@ -291,6 +300,11 @@
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 @@ -319,7 +333,8 @@
}
}

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 @@
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
Loading