Skip to content

Commit 595d73c

Browse files
cemakddfajmon
authored andcommitted
UPSTREAM: <carry>: OCPBUGS-44769: Fix RWX mode for hyperdisks
Based on kubernetes-sigs#1901
1 parent 8e67ea7 commit 595d73c

File tree

6 files changed

+35
-22
lines changed

6 files changed

+35
-22
lines changed

pkg/common/parameters.go

+13
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ import (
2222
)
2323

2424
const (
25+
// Disk Params
26+
ParameterAccessMode = "access-mode"
27+
2528
// Parameters for StorageClass
2629
ParameterKeyType = "type"
2730
ParameterKeyReplicationType = "replication-type"
@@ -106,6 +109,9 @@ type DiskParameters struct {
106109
// Values: {bool}
107110
// Default: false
108111
MultiZoneProvisioning bool
112+
// Values: READ_WRITE_SINGLE, READ_ONLY_MANY, READ_WRITE_MANY
113+
// Default: READ_WRITE_SINGLE
114+
AccessMode string
109115
}
110116

111117
// SnapshotParameters contains normalized and defaulted parameters for snapshots
@@ -201,6 +207,9 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
201207
if err != nil {
202208
return p, fmt.Errorf("parameters contain invalid provisionedThroughputOnCreate parameter: %w", err)
203209
}
210+
if paramProvisionedThroughputOnCreate < 0 {
211+
return p, fmt.Errorf("parameter provisionedThroughputOnCreate cannot be negative")
212+
}
204213
p.ProvisionedThroughputOnCreate = paramProvisionedThroughputOnCreate
205214
case ParameterAvailabilityClass:
206215
paramAvailabilityClass, err := ConvertStringToAvailabilityClass(v)
@@ -250,6 +259,10 @@ func (pp *ParameterProcessor) ExtractAndDefaultParameters(parameters map[string]
250259
if paramEnableMultiZoneProvisioning {
251260
p.Labels[MultiZoneLabel] = "true"
252261
}
262+
case ParameterAccessMode:
263+
if v != "" {
264+
p.AccessMode = v
265+
}
253266
default:
254267
return p, fmt.Errorf("parameters contains invalid option %q", k)
255268
}

pkg/common/parameters_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,13 @@ func TestExtractAndDefaultParameters(t *testing.T) {
344344
labels: map[string]string{},
345345
expectErr: true,
346346
},
347+
{
348+
name: "invalid storage pool parameters, negative ProvisionedThroughputOnCreate",
349+
enableStoragePools: true,
350+
parameters: map[string]string{ParameterKeyType: "hyperdisk-throughput", ParameterKeyReplicationType: "none", ParameterKeyDiskEncryptionKmsKey: "foo/key", ParameterKeyLabels: "key1=value1,key2=value2", ParameterKeyResourceTags: "parent1/key1/value1,parent2/key2/value2", ParameterKeyProvisionedThroughputOnCreate: "-50Mi"},
351+
labels: map[string]string{},
352+
expectErr: true,
353+
},
347354
{
348355
name: "storage pool parameters, enableStoragePools is false",
349356
enableStoragePools: false,

pkg/gce-cloud-provider/compute/cloud-disk.go

+2
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,8 @@ func (d *CloudDisk) GetMultiWriter() bool {
217217
switch {
218218
case d.disk != nil:
219219
return false
220+
case d.disk != nil && d.disk.AccessMode == "READ_WRITE_MANY":
221+
return true
220222
case d.betaDisk != nil:
221223
return d.betaDisk.MultiWriter
222224
default:

pkg/gce-cloud-provider/compute/gce-compute.go

+5-15
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ func (cloud *CloudProvider) ListSnapshots(ctx context.Context, filter string) ([
324324
func (cloud *CloudProvider) GetDisk(ctx context.Context, project string, key *meta.Key, gceAPIVersion GCEAPIVersion) (*CloudDisk, error) {
325325
klog.V(5).Infof("Getting disk %v", key)
326326

327-
// Override GCEAPIVersion as hyperdisk is only available in beta and we cannot get the disk-type with get disk call.
328-
gceAPIVersion = GCEAPIVersionBeta
329327
switch key.Type() {
330328
case meta.Zonal:
331329
if gceAPIVersion == GCEAPIVersionBeta {
@@ -407,11 +405,6 @@ func (cloud *CloudProvider) ValidateExistingDisk(ctx context.Context, resp *Clou
407405
reqBytes, common.GbToBytes(resp.GetSizeGb()), limBytes)
408406
}
409407

410-
// We are assuming here that a multiWriter disk could be used as non-multiWriter
411-
if multiWriter && !resp.GetMultiWriter() {
412-
return fmt.Errorf("disk already exists with incompatible capability. Need MultiWriter. Got non-MultiWriter")
413-
}
414-
415408
return ValidateDiskParameters(resp, params)
416409
}
417410

@@ -553,9 +546,6 @@ func convertV1DiskToBetaDisk(v1Disk *computev1.Disk) *computebeta.Disk {
553546
AccessMode: v1Disk.AccessMode,
554547
}
555548

556-
// Hyperdisk doesn't currently support multiWriter (https://cloud.google.com/compute/docs/disks/hyperdisks#limitations),
557-
// but if multiWriter + hyperdisk is supported in the future, we want the PDCSI driver to support this feature without
558-
// any additional code change.
559549
if v1Disk.ProvisionedIops > 0 {
560550
betaDisk.ProvisionedIops = v1Disk.ProvisionedIops
561551
}
@@ -619,9 +609,6 @@ func convertBetaDiskToV1Disk(betaDisk *computebeta.Disk) *computev1.Disk {
619609
AccessMode: betaDisk.AccessMode,
620610
}
621611

622-
// Hyperdisk doesn't currently support multiWriter (https://cloud.google.com/compute/docs/disks/hyperdisks#limitations),
623-
// but if multiWriter + hyperdisk is supported in the future, we want the PDCSI driver to support this feature without
624-
// any additional code change.
625612
if betaDisk.ProvisionedIops > 0 {
626613
v1Disk.ProvisionedIops = betaDisk.ProvisionedIops
627614
}
@@ -651,7 +638,8 @@ func (cloud *CloudProvider) insertRegionalDisk(
651638
gceAPIVersion = GCEAPIVersionV1
652639
)
653640

654-
if multiWriter {
641+
// Use beta API for non-hyperdisk types in multi-writer mode.
642+
if multiWriter && !strings.Contains(params.DiskType, "hyperdisk") {
655643
gceAPIVersion = GCEAPIVersionBeta
656644
}
657645

@@ -778,7 +766,9 @@ func (cloud *CloudProvider) insertZonalDisk(
778766
opName string
779767
gceAPIVersion = GCEAPIVersionV1
780768
)
781-
if multiWriter {
769+
770+
// Use beta API for non-hyperdisk types in multi-writer mode.
771+
if multiWriter && !strings.Contains(params.DiskType, "hyperdisk") {
782772
gceAPIVersion = GCEAPIVersionBeta
783773
}
784774

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -606,7 +606,7 @@ func (gceCS *GCEControllerServer) createSingleDisk(ctx context.Context, req *csi
606606
capBytes, _ := getRequestCapacity(capacityRange)
607607
multiWriter, _ := getMultiWriterFromCapabilities(req.GetVolumeCapabilities())
608608
readonly, _ := getReadOnlyFromCapabilities(req.GetVolumeCapabilities())
609-
accessMode := ""
609+
accessMode := params.AccessMode
610610
if readonly && slices.Contains(disksWithModifiableAccessMode, params.DiskType) {
611611
accessMode = readOnlyManyAccessMode
612612
}

test/e2e/tests/single_zone_e2e_test.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -892,8 +892,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
892892
Expect(err).To(BeNil(), "Failed to go through volume lifecycle")
893893
})
894894

895-
// Pending while multi-writer feature is in Alpha
896-
PIt("Should create and delete multi-writer disk", func() {
895+
It("Should create and delete multi-writer disk", func() {
897896
Expect(testContexts).ToNot(BeEmpty())
898897
testContext := getRandomTestContext()
899898

@@ -904,7 +903,7 @@ var _ = Describe("GCE PD CSI Driver", func() {
904903
zone := "us-east1-a"
905904

906905
// Create and Validate Disk
907-
volName, volID := createAndValidateUniqueZonalMultiWriterDisk(client, p, zone, standardDiskType)
906+
volName, volID := createAndValidateUniqueZonalMultiWriterDisk(client, p, zone, hdbDiskType)
908907

909908
defer func() {
910909
// Delete Disk
@@ -917,16 +916,15 @@ var _ = Describe("GCE PD CSI Driver", func() {
917916
}()
918917
})
919918

920-
// Pending while multi-writer feature is in Alpha
921-
PIt("Should complete entire disk lifecycle with multi-writer disk", func() {
919+
It("Should complete entire disk lifecycle with multi-writer disk", func() {
922920
testContext := getRandomTestContext()
923921

924922
p, z, _ := testContext.Instance.GetIdentity()
925923
client := testContext.Client
926924
instance := testContext.Instance
927925

928926
// Create and Validate Disk
929-
volName, volID := createAndValidateUniqueZonalMultiWriterDisk(client, p, z, standardDiskType)
927+
volName, volID := createAndValidateUniqueZonalMultiWriterDisk(client, p, z, hdbDiskType)
930928

931929
defer func() {
932930
// Delete Disk
@@ -1612,6 +1610,9 @@ func deleteVolumeOrError(client *remote.CsiClient, volID string) {
16121610
func createAndValidateUniqueZonalMultiWriterDisk(client *remote.CsiClient, project, zone string, diskType string) (string, string) {
16131611
// Create Disk
16141612
disk := typeToDisk[diskType]
1613+
1614+
disk.params[common.ParameterAccessMode] = "READ_WRITE_MANY"
1615+
16151616
volName := testNamePrefix + string(uuid.NewUUID())
16161617
volume, err := client.CreateVolumeWithCaps(volName, disk.params, defaultMwSizeGb,
16171618
&csi.TopologyRequirement{

0 commit comments

Comments
 (0)