feat(zfspv) Add golint check to travis (#175)

Signed-off-by: vaniisgh <vanisingh@live.co.uk>
This commit is contained in:
vaniisgh 2020-07-07 18:21:02 +05:30 committed by GitHub
parent 8b7ad5cb45
commit 8bbf3d7d2f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
34 changed files with 321 additions and 266 deletions

View file

@ -17,8 +17,9 @@ limitations under the License.
package zfs
import (
"k8s.io/klog"
"os/exec"
"k8s.io/klog"
)
/*
@ -27,8 +28,8 @@ import (
* volume refers to the same block because of the way ZFS clone works, it will
* also have the same UUID.
*/
func btrfsGenerateUuid(volume string) error {
device := ZFS_DEVPATH + volume
func btrfsGenerateUUID(volume string) error {
device := ZFSDevPath + volume
// for mounting the cloned volume for btrfs, a new UUID has to be generated
cmd := exec.Command("btrfstune", "-f", "-u", device)

View file

@ -183,7 +183,7 @@ func MountZvol(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
return err
}
devicePath := ZFS_DEVPATH + volume
devicePath := ZFSDevPath + volume
err = FormatAndMountZvol(devicePath, mount)
if err != nil {
@ -244,7 +244,7 @@ func MountDataset(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
// MountFilesystem mounts the disk to the specified path
func MountFilesystem(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
switch vol.Spec.VolumeType {
case VOLTYPE_DATASET:
case VolTypeDataset:
return MountDataset(vol, mount)
default:
return MountZvol(vol, mount)
@ -254,7 +254,7 @@ func MountFilesystem(vol *apis.ZFSVolume, mount *apis.MountInfo) error {
// MountBlock mounts the block disk to the specified path
func MountBlock(vol *apis.ZFSVolume, mountinfo *apis.MountInfo) error {
target := mountinfo.MountPath
devicePath := ZFS_DEVPATH + vol.Spec.PoolName + "/" + vol.Name
devicePath := ZFSDevPath + vol.Spec.PoolName + "/" + vol.Name
mountopt := []string{"bind"}
mounter := &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: mount.NewOsExec()}

View file

@ -26,7 +26,7 @@ import (
)
func xfsTempMount(volume string) error {
device := ZFS_DEVPATH + volume
device := ZFSDevPath + volume
pvol := strings.Split(volume, "/")
// create a temporary directory to mount the xfs file system
@ -70,8 +70,8 @@ func xfsTempMount(volume string) error {
* There might be something there in the xfs log, we have to clear them
* so that filesystem is clean and we can generate the UUID for it.
*/
func xfsGenerateUuid(volume string) error {
device := ZFS_DEVPATH + volume
func xfsGenerateUUID(volume string) error {
device := ZFSDevPath + volume
// temporary mount the volume with nouuid to replay the logs
err := xfsTempMount(volume)

View file

@ -28,8 +28,8 @@ import (
// zfs related constants
const (
ZFS_DEVPATH = "/dev/zvol/"
FSTYPE_ZFS = "zfs"
ZFSDevPath = "/dev/zvol/"
FSTypeZFS = "zfs"
)
// zfs command related constants
@ -46,14 +46,14 @@ const (
// constants to define volume type
const (
VOLTYPE_DATASET = "DATASET"
VOLTYPE_ZVOL = "ZVOL"
VolTypeDataset = "DATASET"
VolTypeZVol = "ZVOL"
)
// PropertyChanged return whether volume property is changed
func PropertyChanged(oldVol *apis.ZFSVolume, newVol *apis.ZFSVolume) bool {
if oldVol.Spec.VolumeType == VOLTYPE_DATASET &&
newVol.Spec.VolumeType == VOLTYPE_DATASET &&
if oldVol.Spec.VolumeType == VolTypeDataset &&
newVol.Spec.VolumeType == VolTypeDataset &&
oldVol.Spec.RecordSize != newVol.Spec.RecordSize {
return true
}
@ -70,10 +70,10 @@ func GetVolumeType(fstype string) string {
* otherwise a zvol will be created
*/
switch fstype {
case FSTYPE_ZFS:
return VOLTYPE_DATASET
case FSTypeZFS:
return VolTypeDataset
default:
return VOLTYPE_ZVOL
return VolTypeZVol
}
}
@ -129,7 +129,7 @@ func buildCloneCreateArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSCloneArg)
if vol.Spec.VolumeType == VOLTYPE_DATASET {
if vol.Spec.VolumeType == VolTypeDataset {
if len(vol.Spec.Capacity) != 0 {
quotaProperty := "quota=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, "-o", quotaProperty)
@ -251,7 +251,7 @@ func buildVolumeSetArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSSetArg)
if vol.Spec.VolumeType == VOLTYPE_DATASET &&
if vol.Spec.VolumeType == VolTypeDataset &&
len(vol.Spec.RecordSize) != 0 {
recordsizeProperty := "recordsize=" + vol.Spec.RecordSize
ZFSVolArg = append(ZFSVolArg, recordsizeProperty)
@ -279,7 +279,7 @@ func buildVolumeResizeArgs(vol *apis.ZFSVolume) []string {
ZFSVolArg = append(ZFSVolArg, ZFSSetArg)
if vol.Spec.VolumeType == VOLTYPE_DATASET {
if vol.Spec.VolumeType == VolTypeDataset {
quotaProperty := "quota=" + vol.Spec.Capacity
ZFSVolArg = append(ZFSVolArg, quotaProperty)
} else {
@ -320,7 +320,7 @@ func CreateVolume(vol *apis.ZFSVolume) error {
if err := getVolume(volume); err != nil {
var args []string
if vol.Spec.VolumeType == VOLTYPE_DATASET {
if vol.Spec.VolumeType == VolTypeDataset {
args = buildDatasetCreateArgs(vol)
} else {
args = buildZvolCreateArgs(vol)
@ -365,10 +365,16 @@ func CreateClone(vol *apis.ZFSVolume) error {
}
if vol.Spec.FsType == "xfs" {
return xfsGenerateUuid(volume)
return xfsGenerateUUID(volume)
}
if vol.Spec.FsType == "btrfs" {
return btrfsGenerateUuid(volume)
return btrfsGenerateUUID(volume)
}
if vol.Spec.FsType == "btrfs" {
return btrfsGenerateUUID(volume)
}
if vol.Spec.FsType == "btrfs" {
return btrfsGenerateUUID(volume)
}
return nil
}
@ -428,7 +434,7 @@ func MountZFSDataset(vol *apis.ZFSVolume, mountpath string) error {
// SetDatasetLegacyMount sets the dataset mountpoint to legacy if not set
func SetDatasetLegacyMount(vol *apis.ZFSVolume) error {
if vol.Spec.VolumeType != VOLTYPE_DATASET {
if vol.Spec.VolumeType != VolTypeDataset {
return nil
}
@ -471,7 +477,7 @@ func SetVolumeProp(vol *apis.ZFSVolume) error {
if len(vol.Spec.Compression) == 0 &&
len(vol.Spec.Dedup) == 0 &&
(vol.Spec.VolumeType != VOLTYPE_DATASET ||
(vol.Spec.VolumeType != VolTypeDataset ||
len(vol.Spec.RecordSize) == 0) {
//nothing to set, just return
return nil
@ -587,11 +593,11 @@ func DestroySnapshot(snap *apis.ZFSSnapshot) error {
// GetVolumeDevPath returns devpath for the given volume
func GetVolumeDevPath(vol *apis.ZFSVolume) (string, error) {
volume := vol.Spec.PoolName + "/" + vol.Name
if vol.Spec.VolumeType == VOLTYPE_DATASET {
if vol.Spec.VolumeType == VolTypeDataset {
return volume, nil
}
devicePath := ZFS_DEVPATH + volume
devicePath := ZFSDevPath + volume
// evaluate the symlink to get the dev path for zvol
dev, err := filepath.EvalSymlinks(devicePath)