From 3da4f7308eb4a20b5c81ba5b8c57ab4eb7e6fa40 Mon Sep 17 00:00:00 2001 From: Gagandeep Singh Date: Sun, 11 Oct 2020 22:29:23 -0700 Subject: [PATCH] chore(refactor): Remove MountInfo struct from api (#225) Signed-off-by: Gagandeep Singh --- changelogs/unreleased/225-codegagan | 1 + pkg/apis/openebs.io/zfs/v1/zfsvolume.go | 21 ------------- .../zfs/v1/zz_generated.deepcopy.go | 26 ---------------- pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go | 21 ------------- .../zfs/v1alpha1/zz_generated.deepcopy.go | 26 ---------------- pkg/driver/agent.go | 4 +-- pkg/usage/ping.go | 6 ++-- pkg/zfs/mount.go | 31 ++++++++++++++++--- 8 files changed, 32 insertions(+), 104 deletions(-) create mode 100644 changelogs/unreleased/225-codegagan diff --git a/changelogs/unreleased/225-codegagan b/changelogs/unreleased/225-codegagan new file mode 100644 index 0000000..8ef54de --- /dev/null +++ b/changelogs/unreleased/225-codegagan @@ -0,0 +1 @@ +Remove MountInfo struct from the api files \ No newline at end of file diff --git a/pkg/apis/openebs.io/zfs/v1/zfsvolume.go b/pkg/apis/openebs.io/zfs/v1/zfsvolume.go index 00e0c72..a93bff1 100644 --- a/pkg/apis/openebs.io/zfs/v1/zfsvolume.go +++ b/pkg/apis/openebs.io/zfs/v1/zfsvolume.go @@ -42,27 +42,6 @@ type ZFSVolume struct { Status VolStatus `json:"status,omitempty"` } -// MountInfo contains the volume related info -// for all types of volumes in ZFSVolume -type MountInfo struct { - // FSType of a volume will specify the - // format type - ext4(default), xfs of PV - FSType string `json:"fsType"` - - // AccessMode of a volume will hold the - // access mode of the volume - AccessModes []string `json:"accessModes"` - - // MountPath of the volume will hold the - // path on which the volume is mounted - // on that node - MountPath string `json:"mountPath"` - - // MountOptions specifies the options with - // which mount needs to be attempted - MountOptions []string `json:"mountOptions"` -} - // ZFSVolumeList is a list of ZFSVolume resources // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +resource:path=zfsvolumes diff --git a/pkg/apis/openebs.io/zfs/v1/zz_generated.deepcopy.go b/pkg/apis/openebs.io/zfs/v1/zz_generated.deepcopy.go index a6ac5db..54737fd 100644 --- a/pkg/apis/openebs.io/zfs/v1/zz_generated.deepcopy.go +++ b/pkg/apis/openebs.io/zfs/v1/zz_generated.deepcopy.go @@ -24,32 +24,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MountInfo) DeepCopyInto(out *MountInfo) { - *out = *in - if in.AccessModes != nil { - in, out := &in.AccessModes, &out.AccessModes - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.MountOptions != nil { - in, out := &in.MountOptions, &out.MountOptions - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountInfo. -func (in *MountInfo) DeepCopy() *MountInfo { - if in == nil { - return nil - } - out := new(MountInfo) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SnapStatus) DeepCopyInto(out *SnapStatus) { *out = *in diff --git a/pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go b/pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go index c0bd173..bb14cb5 100644 --- a/pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go +++ b/pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go @@ -41,27 +41,6 @@ type ZFSVolume struct { Status VolStatus `json:"status,omitempty"` } -// MountInfo contains the volume related info -// for all types of volumes in ZFSVolume -type MountInfo struct { - // FSType of a volume will specify the - // format type - ext4(default), xfs of PV - FSType string `json:"fsType"` - - // AccessMode of a volume will hold the - // access mode of the volume - AccessModes []string `json:"accessModes"` - - // MountPath of the volume will hold the - // path on which the volume is mounted - // on that node - MountPath string `json:"mountPath"` - - // MountOptions specifies the options with - // which mount needs to be attempted - MountOptions []string `json:"mountOptions"` -} - // ZFSVolumeList is a list of ZFSVolume resources // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // +resource:path=zfsvolumes diff --git a/pkg/apis/openebs.io/zfs/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/openebs.io/zfs/v1alpha1/zz_generated.deepcopy.go index 57aa736..fa50feb 100644 --- a/pkg/apis/openebs.io/zfs/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/openebs.io/zfs/v1alpha1/zz_generated.deepcopy.go @@ -24,32 +24,6 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *MountInfo) DeepCopyInto(out *MountInfo) { - *out = *in - if in.AccessModes != nil { - in, out := &in.AccessModes, &out.AccessModes - *out = make([]string, len(*in)) - copy(*out, *in) - } - if in.MountOptions != nil { - in, out := &in.MountOptions, &out.MountOptions - *out = make([]string, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new MountInfo. -func (in *MountInfo) DeepCopy() *MountInfo { - if in == nil { - return nil - } - out := new(MountInfo) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *SnapStatus) DeepCopyInto(out *SnapStatus) { *out = *in diff --git a/pkg/driver/agent.go b/pkg/driver/agent.go index 8dbd989..4e214d5 100644 --- a/pkg/driver/agent.go +++ b/pkg/driver/agent.go @@ -91,8 +91,8 @@ func NewNode(d *CSIDriver) csi.NodeServer { // GetVolAndMountInfo get volume and mount info from node csi volume request func GetVolAndMountInfo( req *csi.NodePublishVolumeRequest, -) (*apis.ZFSVolume, *apis.MountInfo, error) { - var mountinfo apis.MountInfo +) (*apis.ZFSVolume, *zfs.MountInfo, error) { + var mountinfo zfs.MountInfo mountinfo.FSType = req.GetVolumeCapability().GetMount().GetFsType() mountinfo.MountPath = req.GetTargetPath() diff --git a/pkg/usage/ping.go b/pkg/usage/ping.go index 5029a32..deefe40 100644 --- a/pkg/usage/ping.go +++ b/pkg/usage/ping.go @@ -17,9 +17,9 @@ limitations under the License. package usage import ( - "time" - + "fmt" "github.com/openebs/zfs-localpv/pkg/common/env" + "time" ) // OpenEBSPingPeriod ping interval of volume io analytics @@ -50,7 +50,7 @@ func PingCheck() { // getPingPeriod sets the duration of health events, defaults to 24 func getPingPeriod() time.Duration { - value := env.GetOrDefault(OpenEBSPingPeriod, string(defaultPingPeriod)) + value := env.GetOrDefault(OpenEBSPingPeriod, fmt.Sprint(defaultPingPeriod)) duration, _ := time.ParseDuration(value) // Sanitychecks for setting time duration of health events // This way, we are checking for negative and zero time duration and we diff --git a/pkg/zfs/mount.go b/pkg/zfs/mount.go index 633924a..682947a 100644 --- a/pkg/zfs/mount.go +++ b/pkg/zfs/mount.go @@ -27,8 +27,29 @@ import ( "k8s.io/kubernetes/pkg/util/mount" ) +// MountInfo contains the volume related info +// for all types of volumes in ZFSVolume +type MountInfo struct { + // FSType of a volume will specify the + // format type - ext4(default), xfs of PV + FSType string `json:"fsType"` + + // AccessMode of a volume will hold the + // access mode of the volume + AccessModes []string `json:"accessModes"` + + // MountPath of the volume will hold the + // path on which the volume is mounted + // on that node + MountPath string `json:"mountPath"` + + // MountOptions specifies the options with + // which mount needs to be attempted + MountOptions []string `json:"mountOptions"` +} + // FormatAndMountZvol formats and mounts the created volume to the desired mount path -func FormatAndMountZvol(devicePath string, mountInfo *apis.MountInfo) error { +func FormatAndMountZvol(devicePath string, mountInfo *MountInfo) error { mounter := &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: mount.NewOsExec()} err := mounter.FormatAndMount(devicePath, mountInfo.MountPath, mountInfo.FSType, mountInfo.MountOptions) @@ -191,7 +212,7 @@ func verifyMountRequest(vol *apis.ZFSVolume, mountpath string) error { } // MountZvol mounts the disk to the specified path -func MountZvol(vol *apis.ZFSVolume, mount *apis.MountInfo) error { +func MountZvol(vol *apis.ZFSVolume, mount *MountInfo) error { volume := vol.Spec.PoolName + "/" + vol.Name err := verifyMountRequest(vol, mount.MountPath) if err != nil { @@ -211,7 +232,7 @@ func MountZvol(vol *apis.ZFSVolume, mount *apis.MountInfo) error { } // MountDataset mounts the zfs dataset to the specified path -func MountDataset(vol *apis.ZFSVolume, mount *apis.MountInfo) error { +func MountDataset(vol *apis.ZFSVolume, mount *MountInfo) error { volume := vol.Spec.PoolName + "/" + vol.Name err := verifyMountRequest(vol, mount.MountPath) if err != nil { @@ -257,7 +278,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 { +func MountFilesystem(vol *apis.ZFSVolume, mount *MountInfo) error { switch vol.Spec.VolumeType { case VolTypeDataset: return MountDataset(vol, mount) @@ -267,7 +288,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 { +func MountBlock(vol *apis.ZFSVolume, mountinfo *MountInfo) error { target := mountinfo.MountPath devicePath := ZFSDevPath + vol.Spec.PoolName + "/" + vol.Name mountopt := []string{"bind"}