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

[cinder-csi-plugin] Allow disabling particular driver services #1021

Closed
wants to merge 1 commit into from
Closed
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
72 changes: 46 additions & 26 deletions cmd/cinder-csi-plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,23 @@ import (
"fmt"
"os"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/cloud-provider-openstack/pkg/csi/cinder"
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
"k8s.io/cloud-provider-openstack/pkg/util/mount"

"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/component-base/logs"
"k8s.io/klog"
)

var (
endpoint string
nodeID string
cloudconfig string
cluster string
cloudconfig string
cluster string
endpoint string
nodeID string
runControllerService bool
runNodeService bool
)

func init() {
Expand Down Expand Up @@ -73,16 +76,20 @@ func main() {

cmd.Flags().AddGoFlagSet(flag.CommandLine)

cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id")
cmd.MarkPersistentFlagRequired("nodeid")
cmd.PersistentFlags().StringVar(&cloudconfig, "cloud-config", "", "CSI driver cloud config")
cmd.MarkPersistentFlagRequired("cloud-config")

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

cmd.PersistentFlags().StringVar(&endpoint, "endpoint", "", "CSI endpoint")
cmd.MarkPersistentFlagRequired("endpoint")

cmd.PersistentFlags().StringVar(&cloudconfig, "cloud-config", "", "CSI driver cloud config")
cmd.MarkPersistentFlagRequired("cloud-config")
cmd.PersistentFlags().StringVar(&nodeID, "nodeid", "", "node id")
cmd.MarkPersistentFlagRequired("nodeid")

cmd.PersistentFlags().StringVar(&cluster, "cluster", "", "The identifier of the cluster that the plugin is running in.")
cmd.PersistentFlags().BoolVar(&runControllerService, "run-controller-service", true, "If set to false then the CSI driver does not activate its controller service (default: true)")

cmd.PersistentFlags().BoolVar(&runNodeService, "run-node-service", true, "If set to false then the CSI driver does not activate its node service (default: true)")

openstack.AddExtraFlags(pflag.CommandLine)

Expand All @@ -98,30 +105,43 @@ func main() {
}

func handle() {

d := cinder.NewDriver(nodeID, endpoint, cluster)

//Intiliaze mount
mount, err := mount.GetMountProvider()
// Initialize cloud
openstack.InitOpenStackProvider(cloudconfig)
cloud, err := openstack.GetOpenStackProvider()
if err != nil {
klog.V(3).Infof("Failed to GetMountProvider: %v", err)
klog.Warningf("Failed to GetOpenStackProvider: %v", err)
return
}

//Intiliaze Metadatda
metadatda, err := openstack.GetMetadataProvider()
if err != nil {
klog.V(3).Infof("Failed to GetMetadataProvider: %v", err)
// Initialize driver services
var (
ids = cinder.NewIdentityServer(d)
cs *cinder.ControllerServer
ns *cinder.NodeServer
)

if runControllerService {
cs = cinder.NewControllerServer(d, cloud)
}

// Initiliaze cloud
openstack.InitOpenStackProvider(cloudconfig)
cloud, err := openstack.GetOpenStackProvider()
if runNodeService {
// Initialize mount
mount, err := mount.GetMountProvider()
if err != nil {
klog.V(3).Infof("Failed to GetMountProvider: %v", err)
}

if err != nil {
klog.Warningf("Failed to GetOpenStackProvider: %v", err)
return
// Initialize Metadatda
metadata, err := openstack.GetMetadataProvider()
if err != nil {
klog.V(3).Infof("Failed to GetMetadataProvider: %v", err)
}

ns = cinder.NewNodeServer(d, mount, metadata, cloud)
}

d.SetupDriver(cloud, mount, metadatda)
d.SetupDriver(ids, cs, ns)
d.Run()
}
13 changes: 13 additions & 0 deletions docs/using-cinder-csi-plugin.md
Original file line number Diff line number Diff line change
Expand Up @@ -560,3 +560,16 @@ CSIVolumeID
$ csc node get-id --endpoint tcp://127.0.0.1:10000
CSINodeID
```

### Disabling particular driver services

Traditionally, you run the CSI controllers with the OpenStack Cinder driver in the same Kubernetes cluster.
Though, there may be cases where you will only want to run a subset of the available driver services (for example, one scenario is running the controllers outside of the cluster they are serving (while the OpenStack Cinder driver still runs inside the served cluster), but there might be others scenarios).
The CSI driver consists out of these services:

* The **controller** service starts the GRPC server that serves `CreateVolume`, `DeleteVolume`, etc. It is depending on the OpenStack cloud config + credentials and talks with the OpenStack API.
* The **identity** service is responsible to provide identity services like capability information of the CSI plugin.
* The **node** service implements the various operations for volumes that are run locally from the node, for example `NodePublishVolume`, `NodeStageVolume`, etc. It does not do operations like `CreateVolume` or `ControllerPublish`. Also, it runs directly on the OpenStack VM instances. It is also depending on the OpenStack cloud config + credentials.

The CSI driver has two command line flags, `--run-controller-service` and `--run-node-service` which both default to `true`.
You can disable the individual services by setting the respective flags to `false`.
26 changes: 13 additions & 13 deletions pkg/csi/cinder/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ import (
"k8s.io/klog"
)

type controllerServer struct {
type ControllerServer struct {
Driver *CinderDriver
Cloud openstack.IOpenStack
}

func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {

// Volume Name
volName := req.GetName()
Expand Down Expand Up @@ -120,7 +120,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return getCreateVolumeResponse(vol), nil
}

func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
func (cs *ControllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {

// Volume Delete
volID := req.GetVolumeId()
Expand All @@ -142,7 +142,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
return &csi.DeleteVolumeResponse{}, nil
}

func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {
func (cs *ControllerServer) ControllerPublishVolume(ctx context.Context, req *csi.ControllerPublishVolumeRequest) (*csi.ControllerPublishVolumeResponse, error) {

// Volume Attach
instanceID := req.GetNodeId()
Expand Down Expand Up @@ -202,7 +202,7 @@ func (cs *controllerServer) ControllerPublishVolume(ctx context.Context, req *cs
}, nil
}

func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
func (cs *ControllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {

// Volume Detach
instanceID := req.GetNodeId()
Expand Down Expand Up @@ -245,7 +245,7 @@ func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *
return &csi.ControllerUnpublishVolumeResponse{}, nil
}

func (cs *controllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {
func (cs *ControllerServer) ListVolumes(ctx context.Context, req *csi.ListVolumesRequest) (*csi.ListVolumesResponse, error) {

vlist, err := cs.Cloud.ListVolumes()
if err != nil {
Expand All @@ -268,7 +268,7 @@ func (cs *controllerServer) ListVolumes(ctx context.Context, req *csi.ListVolume
}, nil
}

func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
func (cs *ControllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateSnapshotRequest) (*csi.CreateSnapshotResponse, error) {
name := req.Name
volumeId := req.SourceVolumeId

Expand Down Expand Up @@ -333,7 +333,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
}, nil
}

func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {
func (cs *ControllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteSnapshotRequest) (*csi.DeleteSnapshotResponse, error) {

id := req.SnapshotId

Expand All @@ -354,7 +354,7 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
return &csi.DeleteSnapshotResponse{}, nil
}

func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {
func (cs *ControllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnapshotsRequest) (*csi.ListSnapshotsResponse, error) {

if len(req.GetSnapshotId()) != 0 {
snap, err := cs.Cloud.GetSnapshotByID(req.SnapshotId)
Expand Down Expand Up @@ -429,15 +429,15 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap

// ControllerGetCapabilities implements the default GRPC callout.
// Default supports all capabilities
func (cs *controllerServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
func (cs *ControllerServer) ControllerGetCapabilities(ctx context.Context, req *csi.ControllerGetCapabilitiesRequest) (*csi.ControllerGetCapabilitiesResponse, error) {
klog.V(5).Infof("Using default ControllerGetCapabilities")

return &csi.ControllerGetCapabilitiesResponse{
Capabilities: cs.Driver.cscap,
}, nil
}

func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
func (cs *ControllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {

reqVolCap := req.GetVolumeCapabilities()

Expand Down Expand Up @@ -478,11 +478,11 @@ func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req
return resp, nil
}

func (cs *controllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
func (cs *ControllerServer) GetCapacity(ctx context.Context, req *csi.GetCapacityRequest) (*csi.GetCapacityResponse, error) {
return nil, status.Error(codes.Unimplemented, fmt.Sprintf("GetCapacity is not yet implemented"))
}

func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
func (cs *ControllerServer) ControllerExpandVolume(ctx context.Context, req *csi.ControllerExpandVolumeRequest) (*csi.ControllerExpandVolumeResponse, error) {
klog.V(4).Infof("ControllerExpandVolume: called with args %+v", *req)

volumeID := req.GetVolumeId()
Expand Down
2 changes: 1 addition & 1 deletion pkg/csi/cinder/controllerserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
)

var fakeCs *controllerServer
var fakeCs *ControllerServer
var osmock *openstack.OpenStackMock

// Init Controller Server
Expand Down
21 changes: 8 additions & 13 deletions pkg/csi/cinder/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ import (
"github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"k8s.io/cloud-provider-openstack/pkg/csi/cinder/openstack"
"k8s.io/cloud-provider-openstack/pkg/util/mount"
"k8s.io/klog"
)

Expand All @@ -44,9 +42,9 @@ type CinderDriver struct {
cloudconfig string
cluster string

ids *identityServer
cs *controllerServer
ns *nodeServer
ids *IdentityServer
cs *ControllerServer
ns *NodeServer

vcap []*csi.VolumeCapability_AccessMode
cscap []*csi.ControllerServiceCapability
Expand Down Expand Up @@ -135,15 +133,12 @@ func (d *CinderDriver) GetVolumeCapabilityAccessModes() []*csi.VolumeCapability_
return d.vcap
}

func (d *CinderDriver) SetupDriver(cloud openstack.IOpenStack, mount mount.IMount, metadata openstack.IMetadata) {

d.ids = NewIdentityServer(d)
d.cs = NewControllerServer(d, cloud)
d.ns = NewNodeServer(d, mount, metadata, cloud)

func (d *CinderDriver) SetupDriver(ids *IdentityServer, cs *ControllerServer, ns *NodeServer) {
d.ids = ids
d.cs = cs
d.ns = ns
}

func (d *CinderDriver) Run() {

RunControllerandNodePublishServer(d.endpoint, d.ids, d.cs, d.ns)
RunControllerAndNodePublishServer(d.endpoint, d.ids, d.cs, d.ns)
}
8 changes: 4 additions & 4 deletions pkg/csi/cinder/identityserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ import (
"k8s.io/klog"
)

type identityServer struct {
type IdentityServer struct {
Driver *CinderDriver
}

func (ids *identityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
func (ids *IdentityServer) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) {
klog.V(5).Infof("Using default GetPluginInfo")

if ids.Driver.name == "" {
Expand All @@ -46,7 +46,7 @@ func (ids *identityServer) GetPluginInfo(ctx context.Context, req *csi.GetPlugin
}, nil
}

func (ids *identityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
func (ids *IdentityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) {
klog.V(5).Infof("Probe() called with req %+v", req)
oProvider, err := openstack.GetOpenStackProvider()
if err != nil {
Expand All @@ -60,7 +60,7 @@ func (ids *identityServer) Probe(ctx context.Context, req *csi.ProbeRequest) (*c
return &csi.ProbeResponse{}, nil
}

func (ids *identityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
func (ids *IdentityServer) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCapabilitiesRequest) (*csi.GetPluginCapabilitiesResponse, error) {
klog.V(5).Infof("GetPluginCapabilities called with req %+v", req)
return &csi.GetPluginCapabilitiesResponse{
Capabilities: []*csi.PluginCapability{
Expand Down
Loading