Skip to content

Commit

Permalink
Support for additional Bus Types
Browse files Browse the repository at this point in the history
- Adds support for busType: nvme, sata, scsi_paravirtual, scsi_lsi_logic_parallel, scsi_lsi_logic_sas, scsi_buslogic
  • Loading branch information
ricardo-larosa committed May 2, 2023
1 parent 8bd7760 commit 2008b42
Show file tree
Hide file tree
Showing 216 changed files with 21,661 additions and 253 deletions.
13 changes: 12 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,21 @@ kubectl apply -f https://raw.githubusercontent.com/vmware/cloud-director-named-d
| Storage Type | Independent Shareable Named Disks of VCD |
|Provisioning|<ul><li>Static Provisioning</li><li>Dynamic Provisioning</li></ul>|
|Access Modes|<ul><li>ReadOnlyMany</li><li>ReadWriteOnce</li></ul>|
|Volume|Block|
|Volume|<ul><li>Block</ul></li>|
|VolumeMode|<ul><li>FileSystem</li></ul>|
|Topology|<ul><li>Static Provisioning: reuses VCD topology capabilities</li><li>Dynamic Provisioning: places disk in the OVDC of the `ClusterAdminUser` based on the StorageProfile specified.</li></ul>|

## Supported Bus Types
| Bus Type | `bustype` Parameter in `StorageClass` |
| :--------- | :----------------------- |
| Paravirtual (SCSI) | `scsi_paravirtual` (default) |
| LSI Logic Parallel (SCSI) | `scsi_lsi_logic_parallel` |
| LSI Logic SAS (SCSI) | `scsi_lsi_logic_sas` |
| Bus Logic (SCSI) | `scsi_buslogic` |
| SATA | `sata` |
| NVME | `nvme` |


## Contributing
Please see [CONTRIBUTING.md](CONTRIBUTING.md) for instructions on how to contribute.

Expand Down
8 changes: 7 additions & 1 deletion artifacts/default-csi-node-crs-airgap.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ spec:
mountPath: /etc/kubernetes/vcloud
- name: vcloud-basic-auth-volume
mountPath: /etc/kubernetes/vcloud/basic-auth
- mountPath: /run
name: host-run-dir
mountPropagation: "HostToContainer"
volumes:
- name: socket-dir
hostPath:
Expand Down Expand Up @@ -147,4 +150,7 @@ spec:
- name: vcloud-basic-auth-volume
secret:
secretName: vcloud-basic-auth
---
- name: host-run-dir
hostPath:
path: /run
type: Directory
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,23 @@ require (
)

require (
github.com/jaypipes/ghw v0.10.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.19.0
k8s.io/api v0.22.1
k8s.io/apimachinery v0.22.1
)

require (
github.com/StackExchange/wmi v1.2.1 // indirect
github.com/antihax/optional v1.0.0 // indirect
github.com/apparentlymart/go-cidr v1.1.0 // indirect
github.com/araddon/dateparse v0.0.0-20190622164848-0fb0a474d195 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/fsnotify/fsnotify v1.6.0 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-logr/logr v0.4.0 // indirect
github.com/go-ole/go-ole v1.2.6 // indirect
github.com/go-openapi/errors v0.20.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.2 // indirect
Expand All @@ -45,13 +49,16 @@ require (
github.com/hashicorp/go-version v1.2.0 // indirect
github.com/imdario/mergo v0.3.5 // indirect
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/jaypipes/pcidb v1.0.0 // indirect
github.com/json-iterator/go v1.1.11 // indirect
github.com/kr/pretty v0.2.1 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mitchellh/go-homedir v1.1.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/nxadm/tail v1.4.8 // indirect
github.com/peterhellberg/link v1.1.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sirupsen/logrus v1.8.1 // indirect
golang.org/x/net v0.7.0 // indirect
Expand All @@ -63,6 +70,7 @@ require (
google.golang.org/protobuf v1.26.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
howett.net/plist v1.0.0 // indirect
k8s.io/client-go v0.22.1 // indirect
k8s.io/utils v0.0.0-20210707171843-4b05e18ac7d9 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.1.2 // indirect
Expand Down
99 changes: 95 additions & 4 deletions go.sum

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion manifests/csi-node-crs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ spec:
mountPath: /etc/kubernetes/vcloud
- name: vcloud-basic-auth-volume
mountPath: /etc/kubernetes/vcloud/basic-auth
- mountPath: /run
name: host-run-dir
mountPropagation: "HostToContainer"
volumes:
- name: socket-dir
hostPath:
Expand Down Expand Up @@ -147,4 +150,7 @@ spec:
- name: vcloud-basic-auth-volume
secret:
secretName: vcloud-basic-auth
---
- name: host-run-dir
hostPath:
path: /run
type: Directory
8 changes: 7 additions & 1 deletion manifests/csi-node-crs.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ spec:
mountPath: /etc/kubernetes/vcloud
- name: vcloud-basic-auth-volume
mountPath: /etc/kubernetes/vcloud/basic-auth
- mountPath: /run
name: host-run-dir
mountPropagation: "HostToContainer"
volumes:
- name: socket-dir
hostPath:
Expand Down Expand Up @@ -147,4 +150,7 @@ spec:
- name: vcloud-basic-auth-volume
secret:
secretName: vcloud-basic-auth
---
- name: host-run-dir
hostPath:
path: /run
type: Directory
8 changes: 7 additions & 1 deletion manifests/csi-node.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ spec:
mountPath: /etc/kubernetes/vcloud
- name: vcloud-basic-auth-volume
mountPath: /etc/kubernetes/vcloud/basic-auth
- mountPath: /run
name: host-run-dir
mountPropagation: "HostToContainer"
volumes:
- name: socket-dir
hostPath:
Expand Down Expand Up @@ -142,4 +145,7 @@ spec:
- name: vcloud-basic-auth-volume
secret:
secretName: vcloud-basic-auth
---
- name: host-run-dir
hostPath:
path: /run
type: Directory
8 changes: 7 additions & 1 deletion manifests/csi-node.yaml.template
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ spec:
mountPath: /etc/kubernetes/vcloud
- name: vcloud-basic-auth-volume
mountPath: /etc/kubernetes/vcloud/basic-auth
- mountPath: /run
name: host-run-dir
mountPropagation: "HostToContainer"
volumes:
- name: socket-dir
hostPath:
Expand Down Expand Up @@ -142,4 +145,7 @@ spec:
- name: vcloud-basic-auth-volume
secret:
secretName: vcloud-basic-auth
---
- name: host-run-dir
hostPath:
path: /run
type: Directory
67 changes: 36 additions & 31 deletions pkg/csi/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ package csi
import (
"context"
"fmt"
"math"

"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/vmware/cloud-director-named-disk-csi-driver/pkg/util"
"github.com/vmware/cloud-director-named-disk-csi-driver/pkg/vcdcsiclient"
Expand All @@ -16,7 +18,6 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/klog"
"math"
)

const (
Expand All @@ -27,7 +28,6 @@ const (

const (
BusTypeParameter = "busType"
BusSubTypeParameter = "busSubType"
StorageProfileParameter = "storageProfile"
FileSystemParameter = "filesystem"
EphemeralVolumeContext = "csi.storage.k8s.io/ephemeral"
Expand All @@ -36,15 +36,8 @@ const (
VMFullNameAttribute = "vmID"
DiskUUIDAttribute = "diskUUID"
FileSystemAttribute = "filesystem"
)

var (
// BusTypesFromValues is a map of different possible BusTypes from id to string
BusTypesFromValues = map[string]string{
"5": "IDE",
"6": "SCSI",
"20": "SATA",
}
DefaultFSType = "ext4"
DefaultBusType = "scsi_paravirtual"
)

type controllerServer struct {
Expand Down Expand Up @@ -97,7 +90,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context,
}

volumeCapabilities := req.GetVolumeCapabilities()
if volumeCapabilities == nil || len(volumeCapabilities) == 0 {
if len(volumeCapabilities) == 0 { // should omit nil check; len() for []*github.com/container-storage-interface/spec/lib/go/csi.VolumeCapability is defined as zero (S1009)
return nil, status.Error(codes.InvalidArgument, "CreateVolume: VolumeCapabilities should be provided")
}
for _, volumeCapability := range volumeCapabilities {
Expand All @@ -117,39 +110,51 @@ func (cs *controllerServer) CreateVolume(ctx context.Context,
klog.Infof("CreateVolume: requesting volume [%s] with size [%d] MiB, shareable [%v]",
diskName, sizeMB, shareable)

busType := vcdcsiclient.VCDBusTypeSCSI
busSubType := vcdcsiclient.VCDBusSubTypeVirtualSCSI
var (
storageProfile string
fsType string
busType string
tuple vcdcsiclient.BusTuple
ok bool
)

storageProfile, _ := req.Parameters[StorageProfileParameter]
if busType, ok = req.Parameters[BusTypeParameter]; !ok {
busType = DefaultBusType
klog.Infof("No parameter [%s] specified for raw disk [%s]. Hence defaulting to [%s].", BusTypeParameter, diskName, DefaultBusType)
}

disk, err := cs.DiskManager.CreateDisk(diskName, sizeMB, busType,
busSubType, cs.DiskManager.ClusterID, storageProfile, shareable)
tuple, ok = vcdcsiclient.BusTypesSet[busType]
if !ok {
return nil, fmt.Errorf("invalid busType: [%s]", busType)
}

if storageProfile, ok = req.Parameters[StorageProfileParameter]; !ok {
klog.Infof("No parameter [%s] specified for raw disk [%s]. ", StorageProfileParameter, diskName)
}

if fsType, ok = req.Parameters[FileSystemParameter]; !ok {
fsType = DefaultFSType
klog.Infof("No parameter [%s] specified for raw disk [%s]. Hence defaulting to [%s].", FileSystemParameter, diskName, DefaultFSType)
}

disk, err := cs.DiskManager.CreateDisk(diskName, sizeMB, tuple.BusType, tuple.BusSubType, "", storageProfile, shareable)
if err != nil {
if rdeErr := cs.DiskManager.AddToErrorSet(util.DiskCreateError, "", diskName, map[string]interface{}{"Detailed Error": err.Error()}); rdeErr != nil {
klog.Errorf("unable to add error [%s] into [CSI.Errors] in RDE [%s], %v", util.DiskCreateError, cs.DiskManager.ClusterID, rdeErr)
}
return nil, fmt.Errorf("unable to create disk [%s] with sise [%d]MB: [%v]",
diskName, sizeMB, err)
return nil, fmt.Errorf("unable to create disk [%s] with size [%d]MB: [%v]", diskName, sizeMB, err)
}
if removeErrorRdeErr := cs.DiskManager.RemoveFromErrorSet(util.DiskCreateError, "", diskName); removeErrorRdeErr != nil {
klog.Errorf("unable to remove error [%s] from [CSI.Errors] in RDE [%s]", util.DiskCreateError, cs.DiskManager.ClusterID)
}
klog.Infof("Successfully created disk [%s] of size [%d]MB", diskName, sizeMB)

attributes := make(map[string]string)
attributes[BusTypeParameter] = BusTypesFromValues[disk.BusType]
attributes[BusSubTypeParameter] = disk.BusSubType
attributes[StorageProfileParameter] = disk.StorageProfile.Name
attributes[DiskIDAttribute] = disk.Id

fsType := ""
ok := false
if fsType, ok = req.Parameters[FileSystemParameter]; !ok {
fsType = "ext4"
klog.Infof("No FS specified for raw disk [%s]. Hence defaulting to [%s].", diskName, fsType)
attributes := map[string]string{
BusTypeParameter: vcdcsiclient.BusSubTypesFromValues[disk.BusSubType], // BusSubType defines better the busType since SATA and NVME share the same ID=20
StorageProfileParameter: disk.StorageProfile.Name,
DiskIDAttribute: disk.Id,
FileSystemParameter: fsType,
}
attributes[FileSystemParameter] = fsType

resp := &csi.CreateVolumeResponse{
Volume: &csi.Volume{
Expand Down
Loading

0 comments on commit 2008b42

Please sign in to comment.