Skip to content

Commit c2fe2e7

Browse files
committed
Flag protect disk validation
1 parent a00c59a commit c2fe2e7

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ var (
100100

101101
diskCacheSyncPeriod = flag.Duration("disk-cache-sync-period", 10*time.Minute, "Period for the disk cache to check the /dev/disk/by-id/ directory and evaluate the symlinks")
102102

103+
enableDiskSizeValidation = flag.Bool("enable-disk-size-validation", false, "If set to true, the driver will validate that the requested disk size is matches the physical disk size. This flag is disabled by default.")
104+
103105
version string
104106
)
105107

@@ -251,7 +253,8 @@ func handle() {
251253
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Millisecond
252254
// TODO(2042): Move more of the constructor args into this struct
253255
args := &driver.GCEControllerServerArgs{
254-
EnableDiskTopology: *diskTopology,
256+
EnableDiskTopology: *diskTopology,
257+
EnableDiskSizeValidation: *enableDiskSizeValidation,
255258
}
256259

257260
controllerServer = driver.NewControllerServer(gceDriver, cloudProvider, initialBackoffDuration, maxBackoffDuration, fallbackRequisiteZones, *enableStoragePoolsFlag, *enableDataCacheFlag, multiZoneVolumeHandleConfig, listVolumesConfig, provisionableDisksConfig, *enableHdHAFlag, args)

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,13 @@ type GCEControllerServer struct {
122122
// new RPC methods that might be introduced in future versions of the spec.
123123
csi.UnimplementedControllerServer
124124

125-
EnableDiskTopology bool
125+
EnableDiskTopology bool
126+
EnableDiskSizeValidation bool
126127
}
127128

128129
type GCEControllerServerArgs struct {
129-
EnableDiskTopology bool
130+
EnableDiskTopology bool
131+
EnableDiskSizeValidation bool
130132
}
131133

132134
type MultiZoneVolumeHandleConfig struct {
@@ -1163,7 +1165,9 @@ func (gceCS *GCEControllerServer) executeControllerPublishVolume(ctx context.Con
11631165
}
11641166
return nil, common.LoggedError("Failed to getDisk: ", err), disk
11651167
}
1166-
pubVolResp.PublishContext[common.ContextDiskSizeGB] = strconv.FormatInt(disk.GetSizeGb(), 10)
1168+
if gceCS.EnableDiskSizeValidation && pubVolResp.GetPublishContext() != nil {
1169+
pubVolResp.PublishContext[common.ContextDiskSizeGB] = strconv.FormatInt(disk.GetSizeGb(), 10)
1170+
}
11671171
instance, err := gceCS.CloudProvider.GetInstanceOrError(ctx, project, instanceZone, instanceName)
11681172
if err != nil {
11691173
if gce.IsGCENotFoundError(err) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, err
178178
provisionableDisksConfig: provisionableDisksConfig,
179179
enableHdHA: enableHdHA,
180180
EnableDiskTopology: args.EnableDiskTopology,
181+
EnableDiskSizeValidation: args.EnableDiskSizeValidation,
181182
}
182183
}
183184

0 commit comments

Comments
 (0)