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

bug: fix mismatched quote errors from passing augmented volumeid #40

Merged
merged 1 commit into from
Apr 20, 2022
Merged
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
6 changes: 5 additions & 1 deletion pkg/controller/provisioner.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,11 @@ func (controller *Controller) CreateVolume(ctx context.Context, req *csi.CreateV
}

if sourceId != "" {
_, apistatus, err2 := controller.client.CopyVolume(sourceId, volumeName, parameters[common.PoolConfigKey])
sourceName, err := common.VolumeIdGetName(sourceId)
if err != nil {
return nil, err
}
_, apistatus, err2 := controller.client.CopyVolume(sourceName, volumeName, parameters[common.PoolConfigKey])
if err2 != nil {
klog.Infof("-- CopyVolume apistatus.ReturnCode %v", apistatus.ReturnCode)
if apistatus != nil && apistatus.ReturnCode == snapshotNotFoundErrorCode {
Expand Down
19 changes: 11 additions & 8 deletions pkg/controller/snapshotter.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,26 @@ import (
func (controller *Controller) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {

parameters := req.GetParameters()
name, err := common.TranslateName(req.GetName(), parameters[common.VolumePrefixKey])
snapshotName, err := common.TranslateName(req.GetName(), parameters[common.VolumePrefixKey])
if err != nil {
return nil, status.Error(codes.InvalidArgument, "trnaslate snapshot name contains invalid characters")
return nil, status.Error(codes.InvalidArgument, "translate snapshot name contains invalid characters")
}

if common.ValidateName(name) == false {
if common.ValidateName(snapshotName) == false {
return nil, status.Error(codes.InvalidArgument, "snapshot name contains invalid characters")
}

if req.SourceVolumeId == "" {
sourceVolumeId, err := common.VolumeIdGetName(req.GetSourceVolumeId())
if sourceVolumeId == "" || err != nil {
return nil, status.Error(codes.InvalidArgument, "snapshot SourceVolumeId is not valid")
}

_, respStatus, err := controller.client.CreateSnapshot(req.SourceVolumeId, name)
_, respStatus, err := controller.client.CreateSnapshot(sourceVolumeId, snapshotName)
if err != nil && respStatus.ReturnCode != snapshotAlreadyExists {
return nil, err
}

response, _, err := controller.client.ShowSnapshots(name, "")
response, _, err := controller.client.ShowSnapshots(snapshotName, "")
if err != nil {
return nil, err
}
Expand All @@ -61,7 +62,7 @@ func (controller *Controller) CreateSnapshot(ctx context.Context, req *csi.Creat
return nil, errors.New("snapshot not found")
}

if snapshot.SourceVolumeId != req.SourceVolumeId {
if snapshot.SourceVolumeId != sourceVolumeId {
return nil, status.Error(codes.AlreadyExists, "cannot validate volume with empty ID")
}

Expand All @@ -88,7 +89,9 @@ func (controller *Controller) DeleteSnapshot(ctx context.Context, req *csi.Delet

// ListSnapshots: list existing snapshots up to MaxEntries
func (controller *Controller) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
response, _, err := controller.client.ShowSnapshots(req.SnapshotId, req.SourceVolumeId)
sourceVolumeId, err := common.VolumeIdGetName(req.GetSourceVolumeId())

response, _, err := controller.client.ShowSnapshots(req.SnapshotId, sourceVolumeId)
if err != nil {
return nil, err
}
Expand Down