Skip to content

Commit 2c903e1

Browse files
committed
Allow disabling controller or node service
1 parent f727f3a commit 2c903e1

File tree

7 files changed

+71
-25
lines changed

7 files changed

+71
-25
lines changed

cmd/main.go

+35-13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"time"
2323

2424
"k8s.io/klog"
25+
"k8s.io/utils/mount"
2526

2627
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
2728
metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
@@ -30,9 +31,11 @@ import (
3031
)
3132

3233
var (
33-
endpoint = flag.String("endpoint", "unix:/tmp/csi.sock", "CSI endpoint")
34-
gceConfigFilePath = flag.String("cloud-config", "", "Path to GCE cloud provider config")
35-
vendorVersion string
34+
cloudConfigFilePath = flag.String("cloud-config", "", "Path to GCE cloud provider config")
35+
endpoint = flag.String("endpoint", "unix:/tmp/csi.sock", "CSI endpoint")
36+
runControllerService = flag.Bool("run-controller-service", true, "If set to false then the CSI driver does not activate its controller service (default: true)")
37+
runNodeService = flag.Bool("run-node-service", true, "If set to false then the CSI driver does not activate its node service (default: true)")
38+
vendorVersion string
3639
)
3740

3841
const (
@@ -57,6 +60,8 @@ func main() {
5760
}
5861

5962
func handle() {
63+
var err error
64+
6065
if vendorVersion == "" {
6166
klog.Fatalf("vendorVersion must be set at compile time")
6267
}
@@ -68,20 +73,37 @@ func handle() {
6873
ctx, cancel := context.WithCancel(context.Background())
6974
defer cancel()
7075

71-
cloudProvider, err := gce.CreateCloudProvider(ctx, vendorVersion, *gceConfigFilePath)
72-
if err != nil {
73-
klog.Fatalf("Failed to get cloud provider: %v", err)
76+
//Initialize requirements for the controller service
77+
var (
78+
cloudProvider gce.GCECompute
79+
)
80+
if *runControllerService {
81+
cloudProvider, err = gce.CreateCloudProvider(ctx, vendorVersion, *cloudConfigFilePath)
82+
if err != nil {
83+
klog.Fatalf("Failed to get cloud provider: %v", err)
84+
}
85+
} else if *cloudConfigFilePath != "" {
86+
klog.Warningf("controller service is disabled but cloud config given - it has no effect")
7487
}
7588

76-
mounter := mountmanager.NewSafeMounter()
77-
deviceUtils := mountmanager.NewDeviceUtils()
78-
statter := mountmanager.NewStatter()
79-
ms, err := metadataservice.NewMetadataService()
80-
if err != nil {
81-
klog.Fatalf("Failed to set up metadata service: %v", err)
89+
//Initialize requirements for the node service
90+
var (
91+
mounter *mount.SafeFormatAndMount
92+
deviceUtils mountmanager.DeviceUtils
93+
statter mountmanager.Statter
94+
meta metadataservice.MetadataService
95+
)
96+
if *runNodeService {
97+
mounter = mountmanager.NewSafeMounter()
98+
deviceUtils = mountmanager.NewDeviceUtils()
99+
statter = mountmanager.NewStatter()
100+
meta, err = metadataservice.NewMetadataService()
101+
if err != nil {
102+
klog.Fatalf("Failed to set up metadata service: %v", err)
103+
}
82104
}
83105

84-
err = gceDriver.SetupGCEDriver(cloudProvider, mounter, deviceUtils, ms, statter, driverName, vendorVersion)
106+
err = gceDriver.SetupGCEDriver(cloudProvider, mounter, deviceUtils, meta, statter, driverName, vendorVersion)
85107
if err != nil {
86108
klog.Fatalf("Failed to initialize GCE CSI Driver: %v", err)
87109
}

deploy/kubernetes/base/controller.yaml

+3-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ spec:
1717
# since it replaces GCE Metadata Server with GKE Metadata Server. Remove
1818
# this requirement when issue is resolved and before any exposure of
1919
# metrics ports
20-
hostNetwork: true
20+
hostNetwork: true
2121
serviceAccountName: csi-gce-pd-controller-sa
2222
priorityClassName: csi-gce-pd-controller
2323
containers:
@@ -27,6 +27,8 @@ spec:
2727
- "--v=5"
2828
- "--csi-address=/csi/csi.sock"
2929
- "--feature-gates=Topology=true"
30+
# - "--run-controller-service=false" # disable the controller service of the CSI driver
31+
# - "--run-node-service=false" # disable the node service of the CSI driver
3032
volumeMounts:
3133
- name: socket-dir
3234
mountPath: /csi

docs/kubernetes/user-guides/driver-install.md

+20-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ compute.instances.get
1818
compute.instances.attachDisk
1919
compute.instances.detachDisk
2020
roles/compute.storageAdmin
21-
roles/iam.serviceAccountUser
21+
roles/iam.serviceAccountUser
2222
```
2323

2424
If there is a pre-existing service account with these roles for use then the
@@ -79,4 +79,22 @@ iam.serviceAccounts.delete
7979
```
8080

8181
These permissions are not required if you already have a service account ready
82-
for use by the PD Driver.
82+
for use by the PD Driver.
83+
84+
## Disabling particular CSI driver services
85+
86+
Traditionally, you run the CSI controllers with the GCE PD driver in the same Kubernetes cluster.
87+
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 GCE PD driver still runs inside the served cluster), but there might be others scenarios).
88+
The CSI driver consists out of these services:
89+
90+
* The **controller** service starts the GRPC server that serves `CreateVolume`, `DeleteVolume`, etc. It is depending on the GCP service account credentials and talks with the GCP API.
91+
* The **identity** service is responsible to provide identity services like capability information of the CSI plugin.
92+
* 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, as it runs directly on the GCE instances, it is depending on the GCE metadata service.
93+
94+
The CSI driver has two command line flags, `--run-controller-service` and `--run-node-service` which both default to `true`.
95+
You can disable the individual services by setting the respective flags to `false`.
96+
97+
Note: If you want to run the CSI controllers outside of the cluster you have to specify both the `zone` and `projectId` parameters in the GCE cloud provider config.
98+
The `zone` is the name of one of the availability zones the served Kubernetes cluster is deployed to.
99+
It is used to derive the GCP region and to discover the other availability zones in this region.
100+
The `project-id` is the GCP project ID in which the controller is operating.

pkg/gce-pd-csi-driver/gce-pd-driver.go

+8-2
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,14 @@ func (gceDriver *GCEDriver) SetupGCEDriver(cloudProvider gce.GCECompute, mounter
8080

8181
// Set up RPC Servers
8282
gceDriver.ids = NewIdentityServer(gceDriver)
83-
gceDriver.ns = NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter)
84-
gceDriver.cs = NewControllerServer(gceDriver, cloudProvider)
83+
84+
if mounter != nil && deviceUtils != nil && meta != nil && statter != nil {
85+
gceDriver.ns = NewNodeServer(gceDriver, mounter, deviceUtils, meta, statter)
86+
}
87+
88+
if cloudProvider != nil {
89+
gceDriver.cs = NewControllerServer(gceDriver, cloudProvider)
90+
}
8591

8692
return nil
8793
}

pkg/gce-pd-csi-driver/gce-pd-driver_test.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"testing"
1919

2020
gce "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/compute"
21-
metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
2221
)
2322

2423
func initGCEDriver(t *testing.T, cloudDisks []*gce.CloudDisk) *GCEDriver {
@@ -44,7 +43,7 @@ func initBlockingGCEDriver(t *testing.T, cloudDisks []*gce.CloudDisk, readyToExe
4443
func initGCEDriverWithCloudProvider(t *testing.T, cloudProvider gce.GCECompute) *GCEDriver {
4544
vendorVersion := "test-vendor"
4645
gceDriver := GetGCEDriver()
47-
err := gceDriver.SetupGCEDriver(cloudProvider, nil, nil, metadataservice.NewFakeService(), nil, driver, vendorVersion)
46+
err := gceDriver.SetupGCEDriver(cloudProvider, nil, nil, nil, nil, driver, vendorVersion)
4847
if err != nil {
4948
t.Fatalf("Failed to setup GCE Driver: %v", err)
5049
}

pkg/gce-pd-csi-driver/identity_test.go

+3-4
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,12 @@ import (
2020
"context"
2121

2222
csi "github.com/container-storage-interface/spec/lib/go/csi"
23-
metadataservice "sigs.k8s.io/gcp-compute-persistent-disk-csi-driver/pkg/gce-cloud-provider/metadata"
2423
)
2524

2625
func TestGetPluginInfo(t *testing.T) {
2726
vendorVersion := "test-vendor"
2827
gceDriver := GetGCEDriver()
29-
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), nil, driver, vendorVersion)
28+
err := gceDriver.SetupGCEDriver(nil, nil, nil, nil, nil, driver, vendorVersion)
3029
if err != nil {
3130
t.Fatalf("Failed to setup GCE Driver: %v", err)
3231
}
@@ -48,7 +47,7 @@ func TestGetPluginInfo(t *testing.T) {
4847

4948
func TestGetPluginCapabilities(t *testing.T) {
5049
gceDriver := GetGCEDriver()
51-
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), nil, driver, "test-vendor")
50+
err := gceDriver.SetupGCEDriver(nil, nil, nil, nil, nil, driver, "test-vendor")
5251
if err != nil {
5352
t.Fatalf("Failed to setup GCE Driver: %v", err)
5453
}
@@ -80,7 +79,7 @@ func TestGetPluginCapabilities(t *testing.T) {
8079

8180
func TestProbe(t *testing.T) {
8281
gceDriver := GetGCEDriver()
83-
err := gceDriver.SetupGCEDriver(nil, nil, nil, metadataservice.NewFakeService(), nil, driver, "test-vendor")
82+
err := gceDriver.SetupGCEDriver(nil, nil, nil, nil, nil, driver, "test-vendor")
8483
if err != nil {
8584
t.Fatalf("Failed to setup GCE Driver: %v", err)
8685
}

pkg/gce-pd-csi-driver/node_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func getCustomTestGCEDriver(t *testing.T, mounter *mount.SafeFormatAndMount, dev
5151

5252
func getTestBlockingGCEDriver(t *testing.T, readyToExecute chan chan struct{}) *GCEDriver {
5353
gceDriver := GetGCEDriver()
54-
err := gceDriver.SetupGCEDriver(nil, mountmanager.NewFakeSafeBlockingMounter(readyToExecute), mountmanager.NewFakeDeviceUtils(), metadataservice.NewFakeService(), nil, driver, "test-vendor")
54+
err := gceDriver.SetupGCEDriver(nil, mountmanager.NewFakeSafeBlockingMounter(readyToExecute), mountmanager.NewFakeDeviceUtils(), metadataservice.NewFakeService(), mountmanager.NewFakeStatter(), driver, "test-vendor")
5555
if err != nil {
5656
t.Fatalf("Failed to setup GCE Driver: %v", err)
5757
}

0 commit comments

Comments
 (0)