Skip to content

Commit a6bd669

Browse files
committed
Flag protect disk validation
1 parent aa1cf88 commit a6bd669

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
@@ -97,6 +97,8 @@ var (
9797

9898
diskTopology = flag.Bool("disk-topology", false, "If set to true, the driver will add a disk-type.gke.io/[disk-type] topology label when the StorageClass has the use-allowed-disk-topology parameter set to true. That topology label is included in the Topologies returned in CreateVolumeResponse. This flag is disabled by default.")
9999

100+
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.")
101+
100102
version string
101103
)
102104

@@ -248,7 +250,8 @@ func handle() {
248250
maxBackoffDuration := time.Duration(*errorBackoffMaxDurationMs) * time.Millisecond
249251
// TODO(2042): Move more of the constructor args into this struct
250252
args := &driver.GCEControllerServerArgs{
251-
EnableDiskTopology: *diskTopology,
253+
EnableDiskTopology: *diskTopology,
254+
EnableDiskSizeValidation: *enableDiskSizeValidation,
252255
}
253256

254257
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
@@ -177,6 +177,7 @@ func NewControllerServer(gceDriver *GCEDriver, cloudProvider gce.GCECompute, err
177177
provisionableDisksConfig: provisionableDisksConfig,
178178
enableHdHA: enableHdHA,
179179
EnableDiskTopology: args.EnableDiskTopology,
180+
EnableDiskSizeValidation: args.EnableDiskSizeValidation,
180181
}
181182
}
182183

0 commit comments

Comments
 (0)