Skip to content

Commit

Permalink
refact(cstor-csi): modularise CSI implementation (#58)
Browse files Browse the repository at this point in the history
Signed-off-by: Payes <[email protected]>
  • Loading branch information
payes authored and vishnuitta committed Dec 6, 2019
1 parent cc5d4a3 commit 90923f3
Show file tree
Hide file tree
Showing 19,194 changed files with 4,910,914 additions and 1,175 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
605 changes: 30 additions & 575 deletions Gopkg.lock

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,3 +41,7 @@ required = [
[prune]
unused-packages = true
go-tests = true

[[constraint]]
branch = "master"
name = "github.com/kubernetes-csi/csi-lib-iscsi"
4 changes: 2 additions & 2 deletions deploy/csi-operator-ubuntu-18.04.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ spec:
- name: device-dir
mountPath: /dev
- name: pods-mount-dir
mountPath: /var/lib/kubelet/pods
mountPath: /var/lib/kubelet/
# needed so that any mounts setup inside this container are
# propagated back to the host machine.
mountPropagation: "Bidirectional"
Expand All @@ -571,7 +571,7 @@ spec:
type: DirectoryOrCreate
- name: pods-mount-dir
hostPath:
path: /var/lib/kubelet/pods
path: /var/lib/kubelet/
type: Directory
- name: iscsiadm-bin
hostPath:
Expand Down
4 changes: 2 additions & 2 deletions deploy/csi-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,7 @@ spec:
- name: device-dir
mountPath: /dev
- name: pods-mount-dir
mountPath: /var/lib/kubelet/pods
mountPath: /var/lib/kubelet/
# needed so that any mounts setup inside this container are
# propagated back to the host machine.
mountPropagation: "Bidirectional"
Expand All @@ -568,7 +568,7 @@ spec:
type: DirectoryOrCreate
- name: pods-mount-dir
hostPath:
path: /var/lib/kubelet/pods
path: /var/lib/kubelet/
type: Directory
- name: iscsiadm-bin
hostPath:
Expand Down
19 changes: 12 additions & 7 deletions pkg/apis/openebs.io/core/v1alpha1/csivolume.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,29 +67,34 @@ type VolumeInfo struct {

// FSType of a volume will specify the
// format type - ext4(default), xfs of PV
FSType string `json:"fsType"`
FSType string `json:"fsType,omitempty"`

// AccessMode of a volume will hold the
// access mode of the volume
AccessModes []string `json:"accessModes"`
AccessModes []string `json:"accessModes,omitempty"`

// MountPath of the volume will hold the
// StagingPath of the volume will hold the
// path on which the volume is mounted
// on that node
MountPath string `json:"mountPath"`
StagingTargetPath string `json:"stagingTargetPath,omitempty"`

// TargetPath of the volume will hold the
// path on which the volume is bind mounted
// on that node
TargetPath string `json:"targetPath,omitempty"`

// ReadOnly specifies if the volume needs
// to be mounted in ReadOnly mode
ReadOnly bool `json:"readOnly"`
ReadOnly bool `json:"readOnly,omitempty"`

// MountOptions specifies the options with
// which mount needs to be attempted
MountOptions []string `json:"mountOptions"`
MountOptions []string `json:"mountOptions,omitempty"`

// Device Path specifies the device path
// which is returned when the iSCSI
// login is successful
DevicePath string `json:"devicePath"`
DevicePath string `json:"devicePath,omitempty"`
}

// ISCSIInfo has ISCSI protocol specific info,
Expand Down
15 changes: 0 additions & 15 deletions pkg/iscsi/v1alpha1/iscsi_extra_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi"
apis "github.com/openebs/cstor-csi/pkg/apis/openebs.io/core/v1alpha1"
"k8s.io/kubernetes/pkg/util/mount"
"k8s.io/kubernetes/pkg/volume/util"
)

func getISCSIInfo(vol *apis.CSIVolume) (*iscsiDisk, error) {
Expand Down Expand Up @@ -69,20 +68,6 @@ func getISCSIInfoFromPV(req *csi.NodePublishVolumeRequest) (*iscsiDisk, error) {
InitiatorName: initiatorName}, nil
}

func getISCSIDiskMounter(iscsiInfo *iscsiDisk, vol *apis.CSIVolume) *iscsiDiskMounter {

return &iscsiDiskMounter{
iscsiDisk: iscsiInfo,
fsType: vol.Spec.Volume.FSType,
readOnly: vol.Spec.Volume.ReadOnly,
mountOptions: vol.Spec.Volume.MountOptions,
mounter: &mount.SafeFormatAndMount{Interface: mount.New(""), Exec: mount.NewOsExec()},
exec: mount.NewOsExec(),
targetPath: vol.Spec.Volume.MountPath,
deviceUtil: util.NewDeviceHandler(util.NewIOHandler()),
}
}

func getISCSIDiskUnmounter(req *csi.NodeUnpublishVolumeRequest) *iscsiDiskUnmounter {
return &iscsiDiskUnmounter{
iscsiDisk: &iscsiDisk{
Expand Down
18 changes: 0 additions & 18 deletions pkg/iscsi/v1alpha1/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package iscsi

import (
apis "github.com/openebs/cstor-csi/pkg/apis/openebs.io/core/v1alpha1"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/kubernetes/pkg/util/mount"
)

Expand All @@ -27,22 +25,6 @@ func UnmountAndDetachDisk(vol *apis.CSIVolume, path string) error {
return util.DetachDisk(*diskUnmounter, path)
}

// AttachAndMountDisk logs in to the iSCSI Volume
// and mounts the disk to the specified path
func AttachAndMountDisk(vol *apis.CSIVolume) (string, error) {
if len(vol.Spec.Volume.MountPath) == 0 {
return "", status.Error(codes.InvalidArgument, "Target path missing in request")
}
iscsiInfo, err := getISCSIInfo(vol)
if err != nil {
return "", err
}
diskMounter := getISCSIDiskMounter(iscsiInfo, vol)

util := &ISCSIUtil{}
return util.AttachDisk(*diskMounter)
}

// Unmount unmounts the path provided
func Unmount(path string) error {
diskUnmounter := &iscsiDiskUnmounter{
Expand Down
Loading

0 comments on commit 90923f3

Please sign in to comment.