Skip to content

Commit aebf88b

Browse files
authored
Merge pull request #1188 from andyzhangx/customize-controller-cap
feat: disable ListVolumes and ListSnapshosts by default
2 parents 548d144 + b072e8b commit aebf88b

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

pkg/azuredisk/azuredisk.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ type DriverOptions struct {
5959
EnableDiskOnlineResize bool
6060
AllowEmptyCloudConfig bool
6161
EnableAsyncAttach bool
62+
EnableListVolumes bool
63+
EnableListSnapshots bool
6264
}
6365

6466
// CSIDriver defines the interface for a CSI driver.
@@ -93,6 +95,8 @@ type DriverCore struct {
9395
enableDiskOnlineResize bool
9496
allowEmptyCloudConfig bool
9597
enableAsyncAttach bool
98+
enableListVolumes bool
99+
enableListSnapshots bool
96100
}
97101

98102
// Driver is the v1 implementation of the Azure Disk CSI Driver.
@@ -120,6 +124,8 @@ func newDriverV1(options *DriverOptions) *Driver {
120124
driver.enableDiskOnlineResize = options.EnableDiskOnlineResize
121125
driver.allowEmptyCloudConfig = options.AllowEmptyCloudConfig
122126
driver.enableAsyncAttach = options.EnableAsyncAttach
127+
driver.enableListVolumes = options.EnableListVolumes
128+
driver.enableListSnapshots = options.EnableListVolumes
123129
driver.volumeLocks = volumehelper.NewVolumeLocks()
124130
driver.ioHandler = azureutils.NewOSIOHandler()
125131
driver.hostUtil = hostutil.NewHostUtil()
@@ -184,18 +190,22 @@ func (d *Driver) Run(endpoint, kubeconfig string, disableAVSetNodes, testingMock
184190
klog.Fatalf("Failed to get safe mounter. Error: %v", err)
185191
}
186192

187-
d.AddControllerServiceCapabilities(
188-
[]csi.ControllerServiceCapability_RPC_Type{
189-
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
190-
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME,
191-
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
192-
csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS,
193-
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
194-
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
195-
csi.ControllerServiceCapability_RPC_LIST_VOLUMES,
196-
csi.ControllerServiceCapability_RPC_LIST_VOLUMES_PUBLISHED_NODES,
197-
csi.ControllerServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
198-
})
193+
controllerCap := []csi.ControllerServiceCapability_RPC_Type{
194+
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
195+
csi.ControllerServiceCapability_RPC_PUBLISH_UNPUBLISH_VOLUME,
196+
csi.ControllerServiceCapability_RPC_CREATE_DELETE_SNAPSHOT,
197+
csi.ControllerServiceCapability_RPC_CLONE_VOLUME,
198+
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
199+
csi.ControllerServiceCapability_RPC_SINGLE_NODE_MULTI_WRITER,
200+
}
201+
if d.enableListVolumes {
202+
controllerCap = append(controllerCap, csi.ControllerServiceCapability_RPC_LIST_VOLUMES, csi.ControllerServiceCapability_RPC_LIST_VOLUMES_PUBLISHED_NODES)
203+
}
204+
if d.enableListSnapshots {
205+
controllerCap = append(controllerCap, csi.ControllerServiceCapability_RPC_LIST_SNAPSHOTS)
206+
}
207+
208+
d.AddControllerServiceCapabilities(controllerCap)
199209
d.AddVolumeCapabilityAccessModes(
200210
[]csi.VolumeCapability_AccessMode_Mode{
201211
csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER,
@@ -256,7 +266,7 @@ func (d *Driver) checkDiskExists(ctx context.Context, diskURI string) (*compute.
256266

257267
func (d *Driver) checkDiskCapacity(ctx context.Context, subsID, resourceGroup, diskName string, requestGiB int) (bool, error) {
258268
if d.isGetDiskThrottled() {
259-
klog.Warningf("skip checkDiskCapacity((%s, %s) since it's still in throttling", resourceGroup, diskName)
269+
klog.Warningf("skip checkDiskCapacity(%s, %s) since it's still in throttling", resourceGroup, diskName)
260270
return true, nil
261271
}
262272

pkg/azurediskplugin/main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ var (
5454
enableDiskOnlineResize = flag.Bool("enable-disk-online-resize", true, "boolean flag to enable disk online resize")
5555
allowEmptyCloudConfig = flag.Bool("allow-empty-cloud-config", true, "Whether allow running driver without cloud config")
5656
enableAsyncAttach = flag.Bool("enable-async-attach", false, "boolean flag to enable async attach")
57+
enableListVolumes = flag.Bool("enable-list-volumes", false, "boolean flag to enable ListVolumes on controller")
58+
enableListSnapshots = flag.Bool("enable-list-snapshots", false, "boolean flag to enable ListSnapshots on controller")
5759
)
5860

5961
func main() {
@@ -91,6 +93,8 @@ func handle() {
9193
EnableDiskOnlineResize: *enableDiskOnlineResize,
9294
AllowEmptyCloudConfig: *allowEmptyCloudConfig,
9395
EnableAsyncAttach: *enableAsyncAttach,
96+
EnableListVolumes: *enableListVolumes,
97+
EnableListSnapshots: *enableListSnapshots,
9498
}
9599
driver := azuredisk.NewDriver(&driverOptions)
96100
if driver == nil {

0 commit comments

Comments
 (0)