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

refactor pkg/zfs/mount.go Remove MountInfo struct from api #225

Merged
merged 4 commits into from
Oct 12, 2020
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
1 change: 1 addition & 0 deletions changelogs/unreleased/225-codegagan
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove MountInfo struct from the api files
21 changes: 0 additions & 21 deletions pkg/apis/openebs.io/zfs/v1/zfsvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions pkg/apis/openebs.io/zfs/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 0 additions & 21 deletions pkg/apis/openebs.io/zfs/v1alpha1/zfsvolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 0 additions & 26 deletions pkg/apis/openebs.io/zfs/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
6 changes: 3 additions & 3 deletions pkg/usage/ping.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
31 changes: 26 additions & 5 deletions pkg/zfs/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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)
Expand All @@ -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"}
Expand Down