Skip to content

Commit 0b04e01

Browse files
committed
Add support to restrict multi-zone compatible disk types
1 parent 29ad315 commit 0b04e01

File tree

6 files changed

+21
-6
lines changed

6 files changed

+21
-6
lines changed

cmd/gce-pd-csi-driver/main.go

+7-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ var (
7272

7373
enableStoragePoolsFlag = flag.Bool("enable-storage-pools", false, "If set to true, the CSI Driver will allow volumes to be provisioned in Storage Pools")
7474

75+
multiZoneDiskTypesFlag = flag.String("multi-zone-disk-types", "", "Comma separated list of allowed disk types that can use the multi-zone volumeHandle")
76+
7577
version string
7678
)
7779

@@ -150,9 +152,12 @@ func handle() {
150152
// Initialize identity server
151153
identityServer := driver.NewIdentityServer(gceDriver)
152154

153-
// Initilaize requisite zones
155+
// Initialize requisite zones
154156
fallbackRequisiteZones := strings.Split(*fallbackRequisiteZonesFlag, ",")
155157

158+
// Initilaize multi-zone disk types
159+
multiZoneDiskTypes := strings.Split(*multiZoneDiskTypesFlag, ",")
160+
156161
// Initialize requirements for the controller service
157162
var controllerServer *driver.GCEControllerServer
158163
if *runControllerService {
@@ -162,7 +167,7 @@ func handle() {
162167
}
163168
initialBackoffDuration := time.Duration(*errorBackoffInitialDurationMs) * time.Millisecond
164169
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Millisecond
165-
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag)
170+
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, multiZoneDiskTypes)
166171
} else if *cloudConfigFilePath != "" {
167172
klog.Warningf("controller service is disabled but cloud config given - it has no effect")
168173
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ type GCEControllerServer struct {
103103

104104
// If set to true, the CSI Driver will allow volumes to be provisioned in Storage Pools.
105105
enableStoragePools bool
106+
107+
// A set of supported disk types that are compatible with multi-zone volumeHandles.
108+
multiZoneDiskTypes []string
106109
}
107110

108111
type csiErrorBackoffId string
@@ -643,6 +646,10 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
643646
return nil, common.LoggedError("Failed to get instance: ", err), disk
644647
}
645648

649+
if volKey.Type() == meta.Zonal && volKey.Zone == common.MultiZoneValue && slices.Contains(gceCS.multiZoneDiskTypes, disk.GetPDType()) {
650+
return nil, status.Errorf(codes.InvalidArgument, "Disk type %v is unsupported with multi-zone volumeID: %v", disk.GetPDType(), volumeID), disk
651+
}
652+
646653
readWrite := "READ_WRITE"
647654
if readOnly {
648655
readWrite = "READ_ONLY"

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func NewNodeServer(gceDriver *GCEDriver, mounter *mount.SafeFormatAndMount, devi
152152
}
153153
}
154154

155-
func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, errorBackoffInitialDuration, errorBackoffMaxDuration time.Duration, fallbackRequisiteZones []string, enableStoragePools bool) *GCEControllerServer {
155+
func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, errorBackoffInitialDuration, errorBackoffMaxDuration time.Duration, fallbackRequisiteZones []string, enableStoragePools bool, multiZoneDiskTypes []string) *GCEControllerServer {
156156
return &GCEControllerServer{
157157
Driver: gceDriver,
158158
CloudProvider: cloudProvider,
@@ -161,6 +161,7 @@ func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, err
161161
errorBackoff: newCsiErrorBackoff(errorBackoffInitialDuration, errorBackoffMaxDuration),
162162
fallbackRequisiteZones: fallbackRequisiteZones,
163163
enableStoragePools: enableStoragePools,
164+
multiZoneDiskTypes: multiZoneDiskTypes,
164165
}
165166
}
166167

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

+2-1
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ func initGCEDriverWithCloudProvider(t *testing.T, cloudProvider gce.GCECompute)
4848
errorBackoffMaxDuration := 5 * time.Minute
4949
fallbackRequisiteZones := []string{}
5050
enableStoragePools := false
51+
multiZoneDiskTypes := []string{}
5152

52-
controllerServer := NewControllerServer(gceDriver, cloudProvider, errorBackoffInitialDuration, errorBackoffMaxDuration, fallbackRequisiteZones, enableStoragePools)
53+
controllerServer := NewControllerServer(gceDriver, cloudProvider, errorBackoffInitialDuration, errorBackoffMaxDuration, fallbackRequisiteZones, enableStoragePools, multiZoneDiskTypes)
5354
err := gceDriver.SetupGCEDriver(driver, vendorVersion, nil, nil, controllerServer, nil)
5455
if err != nil {
5556
t.Fatalf("Failed to setup GCE Driver: %v", err)

test/e2e/utils/utils.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ func GCEClientAndDriverSetup(instance *remote.InstanceInfo, computeEndpoint stri
6363
workspace := remote.NewWorkspaceDir("gce-pd-e2e-")
6464
// Log at V(6) as the compute API calls are emitted at that level and it's
6565
// useful to see what's happening when debugging tests.
66-
driverRunCmd := fmt.Sprintf("sh -c '/usr/bin/nohup %s/gce-pd-csi-driver -v=6 --endpoint=%s %s 2> %s/prog.out < /dev/null > /dev/null &'",
66+
driverRunCmd := fmt.Sprintf("sh -c '/usr/bin/nohup %s/gce-pd-csi-driver -v=6 --endpoint=%s --multi-zone-disk-types=pd-balanced,pd-ssd %s 2> %s/prog.out < /dev/null > /dev/null &'",
6767
workspace, endpoint, strings.Join(extra_flags, " "), workspace)
6868

6969
config := &remote.ClientConfig{

test/sanity/sanity_test.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,14 @@ func TestSanity(t *testing.T) {
6363

6464
fallbackRequisiteZones := []string{}
6565
enableStoragePools := false
66+
multiZoneDiskTypes := []string{}
6667

6768
mounter := mountmanager.NewFakeSafeMounter()
6869
deviceUtils := deviceutils.NewFakeDeviceUtils(true)
6970

7071
//Initialize GCE Driver
7172
identityServer := driver.NewIdentityServer(gceDriver)
72-
controllerServer := driver.NewControllerServer(gceDriver, cloudProvider, 0, 5*time.Minute, fallbackRequisiteZones, enableStoragePools)
73+
controllerServer := driver.NewControllerServer(gceDriver, cloudProvider, 0, 5*time.Minute, fallbackRequisiteZones, enableStoragePools, multiZoneDiskTypes)
7374
nodeServer := driver.NewNodeServer(gceDriver, mounter, deviceUtils, metadataservice.NewFakeService(), mountmanager.NewFakeStatter(mounter))
7475
err = gceDriver.SetupGCEDriver(driverName, vendorVersion, extraLabels, identityServer, controllerServer, nodeServer)
7576
if err != nil {

0 commit comments

Comments
 (0)