Skip to content

Commit

Permalink
Add support to only run selected CSI services (kubernetes#2316)
Browse files Browse the repository at this point in the history
* Add support to only run selected CSI services of the cinder CSI driver

* Add support to only run selected CSI services of the manila CSI driver

* Clean up source files to successfully complete linting

* Update description of the `nodeid` command line parameter

* Update documentation for the CSI service parameters

This commit updates the documentation for the CSI controller and node service providing parameters.
  • Loading branch information
NotTheEvilOne authored and kayrus committed Sep 18, 2024
1 parent c21ee1a commit de20c18
Show file tree
Hide file tree
Showing 13 changed files with 169 additions and 81 deletions.
34 changes: 24 additions & 10 deletions cmd/cinder-csi-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,13 @@ import (
)

var (
endpoint string
nodeID string
cloudConfig []string
cluster string
httpEndpoint string
endpoint string
nodeID string
cloudConfig []string
cluster string
httpEndpoint string
provideControllerService bool
provideNodeService bool
)

func main() {
Expand Down Expand Up @@ -65,6 +67,10 @@ func main() {

cmd.PersistentFlags().StringVar(&cluster, "cluster", "", "The identifier of the cluster that the plugin is running in.")
cmd.PersistentFlags().StringVar(&httpEndpoint, "http-endpoint", "", "The TCP network address where the HTTP server for diagnostics, including metrics and leader election health check, will listen (example: `:8080`). The default is empty string, which means the server is disabled.")

cmd.PersistentFlags().BoolVar(&provideControllerService, "provide-controller-service", true, "If set to true then the CSI driver does provide the controller service (default: true)")
cmd.PersistentFlags().BoolVar(&provideNodeService, "provide-node-service", true, "If set to true then the CSI driver does provide the node service (default: true)")

openstack.AddExtraFlags(pflag.CommandLine)

code := cli.Run(cmd)
Expand All @@ -80,12 +86,20 @@ func handle() {
klog.Warningf("Failed to GetOpenStackProvider: %v", err)
return
}
//Initialize mount
mount := mount.GetMountProvider()

//Initialize Metadata
metadata := metadata.GetMetadataProvider(cloud.GetMetadataOpts().SearchOrder)
if provideControllerService {
d.SetupControllerService(cloud)
}

if provideNodeService {
//Initialize mount
mount := mount.GetMountProvider()

//Initialize Metadata
metadata := metadata.GetMetadataProvider(cloud.GetMetadataOpts().SearchOrder)

d.SetupNodeService(cloud, mount, metadata)
}

d.SetupDriver(cloud, mount, metadata)
d.Run()
}
62 changes: 40 additions & 22 deletions cmd/manila-csi-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ var (
clusterID string

// Runtime options
endpoint string
runtimeConfigFile string
userAgentData []string
endpoint string
runtimeConfigFile string
userAgentData []string
provideControllerService bool
provideNodeService bool
)

func validateShareProtocolSelector(v string) error {
Expand Down Expand Up @@ -75,23 +77,39 @@ func main() {
manilaClientBuilder := &manilaclient.ClientBuilder{UserAgent: "manila-csi-plugin", ExtraUserAgentData: userAgentData}
csiClientBuilder := &csiclient.ClientBuilder{}

d, err := manila.NewDriver(
&manila.DriverOpts{
DriverName: driverName,
NodeID: nodeID,
NodeAZ: nodeAZ,
WithTopology: withTopology,
ShareProto: protoSelector,
ServerCSIEndpoint: endpoint,
FwdCSIEndpoint: fwdEndpoint,
ManilaClientBuilder: manilaClientBuilder,
CSIClientBuilder: csiClientBuilder,
ClusterID: clusterID,
},
)
opts := &manila.DriverOpts{
DriverName: driverName,
WithTopology: withTopology,
ShareProto: protoSelector,
ServerCSIEndpoint: endpoint,
FwdCSIEndpoint: fwdEndpoint,
ManilaClientBuilder: manilaClientBuilder,
CSIClientBuilder: csiClientBuilder,
ClusterID: clusterID,
}

if provideNodeService {
opts.NodeID = nodeID
opts.NodeAZ = nodeAZ
}

d, err := manila.NewDriver(opts)
if err != nil {
klog.Fatalf("driver initialization failed: %v", err)
klog.Fatalf("Driver initialization failed: %v", err)
}

if provideControllerService {
err = d.SetupControllerService()
if err != nil {
klog.Fatalf("Driver controller service initialization failed: %v", err)
}
}

if provideNodeService {
err = d.SetupNodeService()
if err != nil {
klog.Fatalf("Driver node service initialization failed: %v", err)
}
}

runtimeconfig.RuntimeConfigFilename = runtimeConfigFile
Expand All @@ -105,10 +123,7 @@ func main() {

cmd.PersistentFlags().StringVar(&driverName, "drivername", "manila.csi.openstack.org", "name of the driver")

cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "this node's ID")
if err := cmd.MarkPersistentFlagRequired("nodeid"); err != nil {
klog.Fatalf("Unable to mark flag nodeid to be required: %v", err)
}
cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "this node's ID. This value is required if the node service is provided by this CSI driver instance.")

cmd.PersistentFlags().StringVar(&nodeAZ, "nodeaz", "", "this node's availability zone")

Expand All @@ -132,6 +147,9 @@ func main() {

cmd.PersistentFlags().StringVar(&clusterID, "cluster-id", "", "The identifier of the cluster that the plugin is running in.")

cmd.PersistentFlags().BoolVar(&provideControllerService, "provide-controller-service", true, "If set to true then the CSI driver does provide the controller service (default: true)")
cmd.PersistentFlags().BoolVar(&provideNodeService, "provide-node-service", true, "If set to true then the CSI driver does provide the node service (default: true)")

code := cli.Run(cmd)
os.Exit(code)
}
25 changes: 24 additions & 1 deletion docs/cinder-csi-plugin/using-cinder-csi-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,29 @@ In addition to the standard set of klog flags, `cinder-csi-plugin` accepts the f

This will be added as metadata to every Cinder volume created by this plugin.
</dd>

<dt>--http-endpoint &lt;HTTP server&gt;</dt>
<dd>
This argument is optional.

The TCP network address where the HTTP server for providing metrics for diagnostics, will listen (example: `:8080`).

The default is empty string, which means the server is disabled.
</dd>

<dt>--provide-controller-service &lt;enabled&gt;</dt>
<dd>
If set to true then the CSI driver does provide the controller service.

The default is to provide the controller service.
</dd>

<dt>--provide-node-service &lt;enabled&gt;</dt>
<dd>
If set to true then the CSI driver does provide the node service.

The default is to provide the node service.
</dd>
</dl>

## Driver Config
Expand Down Expand Up @@ -262,7 +285,7 @@ To build cinder-csi-plugin image

```
$ export ARCH=amd64 # Defaults to amd64
$ make image-cinder-csi-plugin
$ make build-local-image-cinder-csi-plugin
```

### Testing
Expand Down
6 changes: 4 additions & 2 deletions docs/manila-csi-plugin/using-manila-csi-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ Option | Default value | Description
`--share-protocol-selector` | _none_ | Specifies which Manila share protocol to use for this instance of the driver. See [supported protocols](#share-protocol-support-matrix) for valid values.
`--fwdendpoint` | _none_ | [CSI Node Plugin](https://github.com/container-storage-interface/spec/blob/master/spec.md#rpc-interface) endpoint to which all Node Service RPCs are forwarded. Must be able to handle the file-system specified in `share-protocol-selector`. Check out the [Deployment](#deployment) section to see why this is necessary.
`--cluster-id` | _none_ | The identifier of the cluster that the plugin is running in. If set then the plugin will add "manila.csi.openstack.org/cluster: \<clusterID\>" to metadata of created shares.
`--provide-controller-service` | `true` | If set to true then the CSI driver does provide the controller service.
`--provide-node-service` | `true` | If set to true then the CSI driver does provide the node service.

### Controller Service volume parameters

Expand All @@ -56,7 +58,7 @@ Parameter | Required | Description
`cephfs-kernelMountOptions` | _no_ | Relevant for CephFS Manila shares. Specifies mount options for CephFS kernel client. See [CSI CephFS docs](https://github.com/ceph/ceph-csi/blob/csi-v1.0/docs/deploy-cephfs.md#configuration) for further information.
`cephfs-fuseMountOptions` | _no_ | Relevant for CephFS Manila shares. Specifies mount options for CephFS FUSE client. See [CSI CephFS docs](https://github.com/ceph/ceph-csi/blob/csi-v1.0/docs/deploy-cephfs.md#configuration) for further information.
`cephfs-clientID` | _no_ | Relevant for CephFS Manila shares. Specifies the cephx client ID when creating an access rule for the provisioned share. The same cephx client ID may be shared with multiple Manila shares. If no value is provided, client ID for the provisioned Manila share will be set to some unique value (PersistentVolume name).
`nfs-shareClient` | _no_ | Relevant for NFS Manila shares. Specifies what address has access to the NFS share. Defaults to `0.0.0.0/0`, i.e. anyone.
`nfs-shareClient` | _no_ | Relevant for NFS Manila shares. Specifies what address has access to the NFS share. Defaults to `0.0.0.0/0`, i.e. anyone.

### Node Service volume context

Expand Down Expand Up @@ -199,7 +201,7 @@ CSI Manila Helm chart is located in `charts/manila-csi-plugin`.

First, modify `values.yaml` to suite your environment, and then simply install the Helm chart with `$ helm install ./charts/manila-csi-plugin`.

Note that the release name generated by `helm install` may not be suitable due to their length. The chart generates object names with the release name included in them, which may cause the names to exceed 63 characters and result in chart installation failure. You may use `--name` flag to set the release name manually. See [helm installation docs](https://helm.sh/docs/helm/#helm-install) for more info. Alternatively, you may also use `nameOverride` or `fullnameOverride` variables in `values.yaml` to override the respective names.
Note that the release name generated by `helm install` may not be suitable due to their length. The chart generates object names with the release name included in them, which may cause the names to exceed 63 characters and result in chart installation failure. You may use `--name` flag to set the release name manually. See [helm installation docs](https://helm.sh/docs/helm/#helm-install) for more info. Alternatively, you may also use `nameOverride` or `fullnameOverride` variables in `values.yaml` to override the respective names.

**Manual deployment**

Expand Down
18 changes: 1 addition & 17 deletions pkg/csi/cinder/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,14 @@ func init() {
osmock = new(openstack.OpenStackMock)
openstack.OsInstance = osmock

d := NewDriver(FakeEndpoint, FakeCluster)
d := NewDriver(&DriverOpts{Endpoint: FakeEndpoint, ClusterID: FakeCluster})

fakeCs = NewControllerServer(d, openstack.OsInstance)
}
}

// Test CreateVolume
func TestCreateVolume(t *testing.T) {

// mock OpenStack
properties := map[string]string{"cinder.csi.openstack.org/cluster": FakeCluster}
// CreateVolume(name string, size int, vtype, availability string, snapshotID string, tags *map[string]string) (string, string, int, error)
Expand Down Expand Up @@ -89,7 +88,6 @@ func TestCreateVolume(t *testing.T) {

// Test CreateVolume with additional param
func TestCreateVolumeWithParam(t *testing.T) {

// mock OpenStack
properties := map[string]string{"cinder.csi.openstack.org/cluster": FakeCluster}
// CreateVolume(name string, size int, vtype, availability string, snapshotID string, tags *map[string]string) (string, string, int, error)
Expand Down Expand Up @@ -141,7 +139,6 @@ func TestCreateVolumeWithParam(t *testing.T) {
}

func TestCreateVolumeWithExtraMetadata(t *testing.T) {

// mock OpenStack
properties := map[string]string{
"cinder.csi.openstack.org/cluster": FakeCluster,
Expand Down Expand Up @@ -188,7 +185,6 @@ func TestCreateVolumeWithExtraMetadata(t *testing.T) {
}

func TestCreateVolumeFromSnapshot(t *testing.T) {

properties := map[string]string{"cinder.csi.openstack.org/cluster": FakeCluster}
// CreateVolume(name string, size int, vtype, availability string, snapshotID string, tags *map[string]string) (string, string, int, error)
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, "", FakeSnapshotID, "", &properties).Return(&FakeVolFromSnapshot, nil)
Expand Down Expand Up @@ -236,7 +232,6 @@ func TestCreateVolumeFromSnapshot(t *testing.T) {
}

func TestCreateVolumeFromSourceVolume(t *testing.T) {

properties := map[string]string{"cinder.csi.openstack.org/cluster": FakeCluster}
// CreateVolume(name string, size int, vtype, availability string, snapshotID string, tags *map[string]string) (string, string, int, error)
osmock.On("CreateVolume", FakeVolName, mock.AnythingOfType("int"), FakeVolType, "", "", FakeVolID, &properties).Return(&FakeVolFromSourceVolume, nil)
Expand Down Expand Up @@ -285,7 +280,6 @@ func TestCreateVolumeFromSourceVolume(t *testing.T) {

// Test CreateVolumeDuplicate
func TestCreateVolumeDuplicate(t *testing.T) {

// Init assert
assert := assert.New(t)

Expand Down Expand Up @@ -318,7 +312,6 @@ func TestCreateVolumeDuplicate(t *testing.T) {

// Test DeleteVolume
func TestDeleteVolume(t *testing.T) {

// DeleteVolume(volumeID string) error
osmock.On("DeleteVolume", FakeVolID).Return(nil)

Expand All @@ -345,7 +338,6 @@ func TestDeleteVolume(t *testing.T) {

// Test ControllerPublishVolume
func TestControllerPublishVolume(t *testing.T) {

// AttachVolume(instanceID, volumeID string) (string, error)
osmock.On("AttachVolume", FakeNodeID, FakeVolID).Return(FakeVolID, nil)
// WaitDiskAttached(instanceID string, volumeID string) error
Expand Down Expand Up @@ -387,7 +379,6 @@ func TestControllerPublishVolume(t *testing.T) {

// Test ControllerUnpublishVolume
func TestControllerUnpublishVolume(t *testing.T) {

// DetachVolume(instanceID, volumeID string) error
osmock.On("DetachVolume", FakeNodeID, FakeVolID).Return(nil)
// WaitDiskDetached(instanceID string, volumeID string) error
Expand Down Expand Up @@ -416,7 +407,6 @@ func TestControllerUnpublishVolume(t *testing.T) {
}

func TestListVolumes(t *testing.T) {

osmock.On("ListVolumes", 2, FakeVolID).Return(FakeVolListMultiple, "", nil)

// Init assert
Expand Down Expand Up @@ -461,7 +451,6 @@ func TestListVolumes(t *testing.T) {

// Test CreateSnapshot
func TestCreateSnapshot(t *testing.T) {

osmock.On("CreateSnapshot", FakeSnapshotName, FakeVolID, &map[string]string{cinderCSIClusterIDKey: "cluster"}).Return(&FakeSnapshotRes, nil)
osmock.On("ListSnapshots", map[string]string{"Name": FakeSnapshotName}).Return(FakeSnapshotListEmpty, "", nil)
osmock.On("WaitSnapshotReady", FakeSnapshotID).Return(nil)
Expand Down Expand Up @@ -490,7 +479,6 @@ func TestCreateSnapshot(t *testing.T) {

// Test CreateSnapshot with extra metadata
func TestCreateSnapshotWithExtraMetadata(t *testing.T) {

properties := map[string]string{
"cinder.csi.openstack.org/cluster": FakeCluster,
"csi.storage.k8s.io/volumesnapshot/name": FakeSnapshotName,
Expand Down Expand Up @@ -532,7 +520,6 @@ func TestCreateSnapshotWithExtraMetadata(t *testing.T) {

// Test DeleteSnapshot
func TestDeleteSnapshot(t *testing.T) {

// DeleteSnapshot(volumeID string) error
osmock.On("DeleteSnapshot", FakeSnapshotID).Return(nil)

Expand All @@ -558,7 +545,6 @@ func TestDeleteSnapshot(t *testing.T) {
}

func TestListSnapshots(t *testing.T) {

osmock.On("ListSnapshots", map[string]string{"Limit": "1", "Marker": FakeVolID, "Status": "available"}).Return(FakeSnapshotsRes, "", nil)
assert := assert.New(t)

Expand All @@ -574,7 +560,6 @@ func TestListSnapshots(t *testing.T) {
}

func TestControllerExpandVolume(t *testing.T) {

tState := []string{"available", "in-use"}
// ExpandVolume(volumeID string, status string, size int)
osmock.On("ExpandVolume", FakeVolID, openstack.VolumeAvailableStatus, 5).Return(nil)
Expand Down Expand Up @@ -611,7 +596,6 @@ func TestControllerExpandVolume(t *testing.T) {
}

func TestValidateVolumeCapabilities(t *testing.T) {

// GetVolume(volumeID string)
osmock.On("GetVolume", FakeVolID).Return(FakeVol1)

Expand Down
Loading

0 comments on commit de20c18

Please sign in to comment.