Skip to content

Commit

Permalink
make lowercase at all the places
Browse files Browse the repository at this point in the history
Signed-off-by: Pawan <pawan@mayadata.io>
  • Loading branch information
pawanpraka1 committed Dec 3, 2020
1 parent 103d548 commit c24ce25
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 36 deletions.
4 changes: 1 addition & 3 deletions pkg/builder/snapbuilder/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ limitations under the License.
package snapbuilder

import (
"strings"

apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
"github.com/openebs/zfs-localpv/pkg/common/errors"
)
Expand Down Expand Up @@ -82,7 +80,7 @@ func (b *Builder) WithName(name string) *Builder {
)
return b
}
b.snap.Object.Name = strings.ToLower(name)
b.snap.Object.Name = name
return b
}

Expand Down
58 changes: 31 additions & 27 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,6 @@ func CreateVolClone(req *csi.CreateVolumeRequest, srcVol string) (string, error)

// CreateSnapClone creates the clone from a snapshot
func CreateSnapClone(req *csi.CreateVolumeRequest, snapshot string) (string, error) {

volName := strings.ToLower(req.GetName())
parameters := req.GetParameters()
// lower case keys, cf CreateZFSVolume()
Expand Down Expand Up @@ -318,7 +317,7 @@ func (cs *controller) CreateVolume(
return nil, err
}

volName := req.GetName()
volName := strings.ToLower(req.GetName())
parameters := req.GetParameters()
// lower case keys, cf CreateZFSVolume()
pool := helpers.GetInsensitiveParameter(&parameters, "poolname")
Expand Down Expand Up @@ -370,7 +369,7 @@ func (cs *controller) DeleteVolume(
return nil, err
}

volumeID := req.GetVolumeId()
volumeID := strings.ToLower(req.GetVolumeId())

// verify if the volume has already been deleted
vol, err := zfs.GetVolume(volumeID)
Expand Down Expand Up @@ -477,7 +476,8 @@ func (cs *controller) ControllerExpandVolume(
ctx context.Context,
req *csi.ControllerExpandVolumeRequest,
) (*csi.ControllerExpandVolumeResponse, error) {
if req.VolumeId == "" {
volumeID := strings.ToLower(req.GetVolumeId())
if volumeID == "" {
return nil, status.Errorf(
codes.InvalidArgument,
"ControllerExpandVolume: no volumeID provided",
Expand All @@ -487,12 +487,12 @@ func (cs *controller) ControllerExpandVolume(
/* round off the new size */
updatedSize := getRoundedCapacity(req.GetCapacityRange().GetRequiredBytes())

vol, err := zfs.GetZFSVolume(req.VolumeId)
vol, err := zfs.GetZFSVolume(volumeID)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"ControllerExpandVolumeRequest: failed to get ZFSVolume in for %s, {%s}",
req.VolumeId,
volumeID,
err.Error(),
)
}
Expand All @@ -502,7 +502,7 @@ func (cs *controller) ControllerExpandVolume(
return nil, status.Errorf(
codes.Internal,
"ControllerExpandVolumeRequest: failed to parse volsize in for %s, {%s}",
req.VolumeId,
volumeID,
err.Error(),
)
}
Expand All @@ -521,7 +521,7 @@ func (cs *controller) ControllerExpandVolume(
return nil, status.Errorf(
codes.Internal,
"failed to handle ControllerExpandVolumeRequest for %s, {%s}",
req.VolumeId,
volumeID,
err.Error(),
)
}
Expand All @@ -532,16 +532,18 @@ func (cs *controller) ControllerExpandVolume(
}

func verifySnapshotRequest(req *csi.CreateSnapshotRequest) error {
if req.Name == "" || req.SourceVolumeId == "" {
snapName := strings.ToLower(req.GetName())
volumeID := strings.ToLower(req.GetSourceVolumeId())

if snapName == "" || volumeID == "" {
return status.Errorf(
codes.InvalidArgument,
"CreateSnapshot error invalid request %s: %s",
req.SourceVolumeId, req.Name,
volumeID, snapName,
)
}

volName := strings.ToLower(req.SourceVolumeId)
snap, err := zfs.GetZFSSnapshot(req.Name)
snap, err := zfs.GetZFSSnapshot(snapName)

if err != nil {
if k8serror.IsNotFound(err) {
Expand All @@ -550,14 +552,14 @@ func verifySnapshotRequest(req *csi.CreateSnapshotRequest) error {
return status.Errorf(
codes.NotFound,
"CreateSnapshot error snap %s %s get failed : %s",
req.Name, req.SourceVolumeId, err.Error(),
snapName, volumeID, err.Error(),
)
}
if snap.Labels[zfs.ZFSVolKey] != volName {
if snap.Labels[zfs.ZFSVolKey] != volumeID {
return status.Errorf(
codes.AlreadyExists,
"CreateSnapshot error snapshot %s already exist for different source vol %s: %s",
req.Name, snap.Labels[zfs.ZFSVolKey], req.SourceVolumeId,
snapName, snap.Labels[zfs.ZFSVolKey], volumeID,
)
}
return nil
Expand All @@ -570,47 +572,49 @@ func (cs *controller) CreateSnapshot(
ctx context.Context,
req *csi.CreateSnapshotRequest,
) (*csi.CreateSnapshotResponse, error) {
snapName := strings.ToLower(req.GetName())
volumeID := strings.ToLower(req.GetSourceVolumeId())

klog.Infof("CreateSnapshot volume %s@%s", req.SourceVolumeId, req.Name)
klog.Infof("CreateSnapshot volume %s@%s", volumeID, snapName)

err := verifySnapshotRequest(req)
if err != nil {
return nil, err
}

snapTimeStamp := time.Now().Unix()
state, err := zfs.GetZFSSnapshotStatus(req.Name)
state, err := zfs.GetZFSSnapshotStatus(snapName)

if err == nil {
return csipayload.NewCreateSnapshotResponseBuilder().
WithSourceVolumeID(req.SourceVolumeId).
WithSnapshotID(req.SourceVolumeId+"@"+req.Name).
WithSourceVolumeID(volumeID).
WithSnapshotID(volumeID+"@"+snapName).
WithCreationTime(snapTimeStamp, 0).
WithReadyToUse(state == zfs.ZFSStatusReady).
Build(), nil
}

vol, err := zfs.GetZFSVolume(req.SourceVolumeId)
vol, err := zfs.GetZFSVolume(volumeID)
if err != nil {
return nil, status.Errorf(
codes.NotFound,
"CreateSnapshot not able to get volume %s: %s, {%s}",
req.SourceVolumeId, req.Name,
volumeID, snapName,
err.Error(),
)
}

labels := map[string]string{zfs.ZFSVolKey: vol.Name}

snapObj, err := snapbuilder.NewBuilder().
WithName(req.Name).
WithName(snapName).
WithLabels(labels).Build()

if err != nil {
return nil, status.Errorf(
codes.Internal,
"failed to create snapshotobject for %s: %s, {%s}",
req.SourceVolumeId, req.Name,
volumeID, snapName,
err.Error(),
)
}
Expand All @@ -622,16 +626,16 @@ func (cs *controller) CreateSnapshot(
return nil, status.Errorf(
codes.Internal,
"failed to handle CreateSnapshotRequest for %s: %s, {%s}",
req.SourceVolumeId, req.Name,
volumeID, snapName,
err.Error(),
)
}

state, _ = zfs.GetZFSSnapshotStatus(req.Name)
state, _ = zfs.GetZFSSnapshotStatus(snapName)

return csipayload.NewCreateSnapshotResponseBuilder().
WithSourceVolumeID(req.SourceVolumeId).
WithSnapshotID(req.SourceVolumeId+"@"+req.Name).
WithSourceVolumeID(volumeID).
WithSnapshotID(volumeID+"@"+snapName).
WithCreationTime(snapTimeStamp, 0).
WithReadyToUse(state == zfs.ZFSStatusReady).
Build(), nil
Expand Down
11 changes: 5 additions & 6 deletions pkg/zfs/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ package zfs
import (
"os"
"strconv"
"strings"

apis "github.com/openebs/zfs-localpv/pkg/apis/openebs.io/zfs/v1"
"github.com/openebs/zfs-localpv/pkg/builder/bkpbuilder"
Expand Down Expand Up @@ -120,7 +119,7 @@ func ProvisionSnapshot(

// DeleteSnapshot deletes the corresponding ZFSSnapshot CR
func DeleteSnapshot(snapname string) (err error) {
err = snapbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Delete(strings.ToLower(snapname))
err = snapbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Delete(snapname)
if err == nil {
klog.Infof("deprovisioned snapshot %s", snapname)
}
Expand All @@ -137,7 +136,7 @@ func GetVolume(volumeID string) (*apis.ZFSVolume, error) {

// DeleteVolume deletes the corresponding ZFSVol CR
func DeleteVolume(volumeID string) (err error) {
err = volbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Delete(strings.ToLower(volumeID))
err = volbuilder.NewKubeclient().WithNamespace(OpenEBSNamespace).Delete(volumeID)
if err == nil {
klog.Infof("deprovisioned volume %s", volumeID)
}
Expand All @@ -160,7 +159,7 @@ func GetVolList(volumeID string) (*apis.ZFSVolumeList, error) {
func GetZFSVolume(volumeID string) (*apis.ZFSVolume, error) {
getOptions := metav1.GetOptions{}
vol, err := volbuilder.NewKubeclient().
WithNamespace(OpenEBSNamespace).Get(strings.ToLower(volumeID), getOptions)
WithNamespace(OpenEBSNamespace).Get(volumeID, getOptions)
return vol, err
}

Expand Down Expand Up @@ -213,15 +212,15 @@ func RemoveZvolFinalizer(vol *apis.ZFSVolume) error {
func GetZFSSnapshot(snapID string) (*apis.ZFSSnapshot, error) {
getOptions := metav1.GetOptions{}
snap, err := snapbuilder.NewKubeclient().
WithNamespace(OpenEBSNamespace).Get(strings.ToLower(snapID), getOptions)
WithNamespace(OpenEBSNamespace).Get(snapID, getOptions)
return snap, err
}

// GetZFSSnapshotStatus returns ZFSSnapshot status
func GetZFSSnapshotStatus(snapID string) (string, error) {
getOptions := metav1.GetOptions{}
snap, err := snapbuilder.NewKubeclient().
WithNamespace(OpenEBSNamespace).Get(strings.ToLower(snapID), getOptions)
WithNamespace(OpenEBSNamespace).Get(snapID, getOptions)

if err != nil {
klog.Errorf("Get snapshot failed %s err: %s", snap.Name, err.Error())
Expand Down

0 comments on commit c24ce25

Please sign in to comment.