@@ -99,7 +99,7 @@ type GCECompute interface {
99
99
GetDefaultProject () string
100
100
GetDefaultZone () string
101
101
// Disk Methods
102
- GetDisk (ctx context.Context , project string , volumeKey * meta.Key , gceAPIVersion GCEAPIVersion ) (* CloudDisk , error )
102
+ GetDisk (ctx context.Context , project string , volumeKey * meta.Key ) (* CloudDisk , error )
103
103
RepairUnderspecifiedVolumeKey (ctx context.Context , project string , volumeKey * meta.Key ) (string , * meta.Key , error )
104
104
ValidateExistingDisk (ctx context.Context , disk * CloudDisk , params common.DiskParameters , reqBytes , limBytes int64 , multiWriter bool ) error
105
105
InsertDisk (ctx context.Context , project string , volKey * meta.Key , params common.DiskParameters , capBytes int64 , capacityRange * csi.CapacityRange , replicaZones []string , snapshotID string , volumeContentSourceVolumeID string , multiWriter bool , accessMode string ) error
@@ -321,28 +321,16 @@ func (cloud *CloudProvider) ListSnapshots(ctx context.Context, filter string) ([
321
321
return items , "" , nil
322
322
}
323
323
324
- func (cloud * CloudProvider ) GetDisk (ctx context.Context , project string , key * meta.Key , gceAPIVersion GCEAPIVersion ) (* CloudDisk , error ) {
324
+ func (cloud * CloudProvider ) GetDisk (ctx context.Context , project string , key * meta.Key ) (* CloudDisk , error ) {
325
325
klog .V (5 ).Infof ("Getting disk %v" , key )
326
326
327
- // Override GCEAPIVersion as hyperdisk is only available in beta and we cannot get the disk-type with get disk call.
328
- gceAPIVersion = GCEAPIVersionBeta
329
327
switch key .Type () {
330
328
case meta .Zonal :
331
- if gceAPIVersion == GCEAPIVersionBeta {
332
- disk , err := cloud .getZonalBetaDiskOrError (ctx , project , key .Zone , key .Name )
333
- return CloudDiskFromBeta (disk ), err
334
- } else {
335
- disk , err := cloud .getZonalDiskOrError (ctx , project , key .Zone , key .Name )
336
- return CloudDiskFromV1 (disk ), err
337
- }
329
+ disk , err := cloud .getZonalBetaDiskOrError (ctx , project , key .Zone , key .Name )
330
+ return CloudDiskFromBeta (disk ), err
338
331
case meta .Regional :
339
- if gceAPIVersion == GCEAPIVersionBeta {
340
- disk , err := cloud .getRegionalBetaDiskOrError (ctx , project , key .Region , key .Name )
341
- return CloudDiskFromBeta (disk ), err
342
- } else {
343
- disk , err := cloud .getRegionalDiskOrError (ctx , project , key .Region , key .Name )
344
- return CloudDiskFromV1 (disk ), err
345
- }
332
+ disk , err := cloud .getRegionalBetaDiskOrError (ctx , project , key .Region , key .Name )
333
+ return CloudDiskFromBeta (disk ), err
346
334
default :
347
335
return nil , fmt .Errorf ("key was neither zonal nor regional, got: %v" , key .String ())
348
336
}
@@ -553,9 +541,6 @@ func convertV1DiskToBetaDisk(v1Disk *computev1.Disk) *computebeta.Disk {
553
541
AccessMode : v1Disk .AccessMode ,
554
542
}
555
543
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.
559
544
if v1Disk .ProvisionedIops > 0 {
560
545
betaDisk .ProvisionedIops = v1Disk .ProvisionedIops
561
546
}
@@ -619,9 +604,6 @@ func convertBetaDiskToV1Disk(betaDisk *computebeta.Disk) *computev1.Disk {
619
604
AccessMode : betaDisk .AccessMode ,
620
605
}
621
606
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.
625
607
if betaDisk .ProvisionedIops > 0 {
626
608
v1Disk .ProvisionedIops = betaDisk .ProvisionedIops
627
609
}
@@ -646,16 +628,11 @@ func (cloud *CloudProvider) insertRegionalDisk(
646
628
description string ,
647
629
multiWriter bool ) error {
648
630
var (
649
- err error
650
- opName string
651
- gceAPIVersion = GCEAPIVersionV1
631
+ err error
632
+ opName string
652
633
)
653
634
654
- if multiWriter {
655
- gceAPIVersion = GCEAPIVersionBeta
656
- }
657
-
658
- diskToCreate := & computev1.Disk {
635
+ diskToCreate := & computebeta.Disk {
659
636
Name : volKey .Name ,
660
637
SizeGb : common .BytesToGbRoundUp (capBytes ),
661
638
Description : description ,
@@ -684,7 +661,7 @@ func (cloud *CloudProvider) insertRegionalDisk(
684
661
diskToCreate .ReplicaZones = replicaZones
685
662
}
686
663
if params .DiskEncryptionKMSKey != "" {
687
- diskToCreate .DiskEncryptionKey = & computev1 .CustomerEncryptionKey {
664
+ diskToCreate .DiskEncryptionKey = & computebeta .CustomerEncryptionKey {
688
665
KmsKeyName : params .DiskEncryptionKMSKey ,
689
666
}
690
667
}
@@ -694,29 +671,21 @@ func (cloud *CloudProvider) insertRegionalDisk(
694
671
}
695
672
696
673
if len (resourceTags ) > 0 {
697
- diskToCreate .Params = & computev1 .DiskParams {
674
+ diskToCreate .Params = & computebeta .DiskParams {
698
675
ResourceManagerTags : resourceTags ,
699
676
}
700
677
}
701
678
702
- if gceAPIVersion == GCEAPIVersionBeta {
703
- var insertOp * computebeta.Operation
704
- betaDiskToCreate := convertV1DiskToBetaDisk (diskToCreate )
705
- betaDiskToCreate .MultiWriter = multiWriter
706
- insertOp , err = cloud .betaService .RegionDisks .Insert (project , volKey .Region , betaDiskToCreate ).Context (ctx ).Do ()
707
- if insertOp != nil {
708
- opName = insertOp .Name
709
- }
710
- } else {
711
- var insertOp * computev1.Operation
712
- insertOp , err = cloud .service .RegionDisks .Insert (project , volKey .Region , diskToCreate ).Context (ctx ).Do ()
713
- if insertOp != nil {
714
- opName = insertOp .Name
715
- }
679
+ var insertOp * computebeta.Operation
680
+ diskToCreate .MultiWriter = multiWriter
681
+ insertOp , err = cloud .betaService .RegionDisks .Insert (project , volKey .Region , diskToCreate ).Context (ctx ).Do ()
682
+ if insertOp != nil {
683
+ opName = insertOp .Name
716
684
}
685
+
717
686
if err != nil {
718
687
if IsGCEError (err , "alreadyExists" ) {
719
- disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
688
+ disk , err := cloud .GetDisk (ctx , project , volKey )
720
689
if err != nil {
721
690
// failed to GetDisk, however the Disk may already exist
722
691
// the error code should be non-Final
@@ -742,7 +711,7 @@ func (cloud *CloudProvider) insertRegionalDisk(
742
711
// the error code returned should be non-final
743
712
if err != nil {
744
713
if IsGCEError (err , "alreadyExists" ) {
745
- disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
714
+ disk , err := cloud .GetDisk (ctx , project , volKey )
746
715
if err != nil {
747
716
return common .NewTemporaryError (codes .Unavailable , fmt .Errorf ("error when getting disk: %w" , err ))
748
717
}
@@ -774,15 +743,11 @@ func (cloud *CloudProvider) insertZonalDisk(
774
743
multiWriter bool ,
775
744
accessMode string ) error {
776
745
var (
777
- err error
778
- opName string
779
- gceAPIVersion = GCEAPIVersionV1
746
+ err error
747
+ opName string
780
748
)
781
- if multiWriter {
782
- gceAPIVersion = GCEAPIVersionBeta
783
- }
784
749
785
- diskToCreate := & computev1 .Disk {
750
+ diskToCreate := & computebeta .Disk {
786
751
Name : volKey .Name ,
787
752
SizeGb : common .BytesToGbRoundUp (capBytes ),
788
753
Description : description ,
@@ -824,7 +789,7 @@ func (cloud *CloudProvider) insertZonalDisk(
824
789
}
825
790
826
791
if params .DiskEncryptionKMSKey != "" {
827
- diskToCreate .DiskEncryptionKey = & computev1 .CustomerEncryptionKey {
792
+ diskToCreate .DiskEncryptionKey = & computebeta .CustomerEncryptionKey {
828
793
KmsKeyName : params .DiskEncryptionKMSKey ,
829
794
}
830
795
}
@@ -836,31 +801,21 @@ func (cloud *CloudProvider) insertZonalDisk(
836
801
}
837
802
838
803
if len (resourceTags ) > 0 {
839
- diskToCreate .Params = & computev1 .DiskParams {
804
+ diskToCreate .Params = & computebeta .DiskParams {
840
805
ResourceManagerTags : resourceTags ,
841
806
}
842
807
}
843
- diskToCreate .AccessMode = accessMode
844
808
845
- if gceAPIVersion == GCEAPIVersionBeta {
846
- var insertOp * computebeta.Operation
847
- betaDiskToCreate := convertV1DiskToBetaDisk (diskToCreate )
848
- betaDiskToCreate .MultiWriter = multiWriter
849
- insertOp , err = cloud .betaService .Disks .Insert (project , volKey .Zone , betaDiskToCreate ).Context (ctx ).Do ()
850
- if insertOp != nil {
851
- opName = insertOp .Name
852
- }
853
- } else {
854
- var insertOp * computev1.Operation
855
- insertOp , err = cloud .service .Disks .Insert (project , volKey .Zone , diskToCreate ).Context (ctx ).Do ()
856
- if insertOp != nil {
857
- opName = insertOp .Name
858
- }
809
+ diskToCreate .AccessMode = accessMode
810
+ var insertOp * computebeta.Operation
811
+ insertOp , err = cloud .betaService .Disks .Insert (project , volKey .Zone , diskToCreate ).Context (ctx ).Do ()
812
+ if insertOp != nil {
813
+ opName = insertOp .Name
859
814
}
860
815
861
816
if err != nil {
862
817
if IsGCEError (err , "alreadyExists" ) {
863
- disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
818
+ disk , err := cloud .GetDisk (ctx , project , volKey )
864
819
if err != nil {
865
820
// failed to GetDisk, however the Disk may already exist
866
821
// the error code should be non-Final
@@ -887,7 +842,7 @@ func (cloud *CloudProvider) insertZonalDisk(
887
842
// failed to wait for Op to finish, however, the Op possibly is still running as expected
888
843
// the error code returned should be non-final
889
844
if IsGCEError (err , "alreadyExists" ) {
890
- disk , err := cloud .GetDisk (ctx , project , volKey , gceAPIVersion )
845
+ disk , err := cloud .GetDisk (ctx , project , volKey )
891
846
if err != nil {
892
847
return common .NewTemporaryError (codes .Unavailable , fmt .Errorf ("error when getting disk: %w" , err ))
893
848
}
@@ -1186,7 +1141,7 @@ func (cloud *CloudProvider) waitForAttachOnDisk(ctx context.Context, project str
1186
1141
start := time .Now ()
1187
1142
return wait .ExponentialBackoff (AttachDiskBackoff , func () (bool , error ) {
1188
1143
klog .V (6 ).Infof ("Polling disks.get for attach of disk %v to instance %v to complete for %v" , volKey .Name , instanceName , time .Since (start ))
1189
- disk , err := cloud .GetDisk (ctx , project , volKey , GCEAPIVersionV1 )
1144
+ disk , err := cloud .GetDisk (ctx , project , volKey )
1190
1145
if err != nil {
1191
1146
return false , fmt .Errorf ("GetDisk failed to get disk: %w" , err )
1192
1147
}
@@ -1436,7 +1391,7 @@ func (cloud *CloudProvider) DeleteImage(ctx context.Context, project, imageName
1436
1391
// k8s.io/apimachinery/quantity package for better size handling
1437
1392
func (cloud * CloudProvider ) ResizeDisk (ctx context.Context , project string , volKey * meta.Key , requestBytes int64 ) (int64 , error ) {
1438
1393
klog .V (5 ).Infof ("Resizing disk %v to size %v" , volKey , requestBytes )
1439
- cloudDisk , err := cloud .GetDisk (ctx , project , volKey , GCEAPIVersionV1 )
1394
+ cloudDisk , err := cloud .GetDisk (ctx , project , volKey )
1440
1395
if err != nil {
1441
1396
return - 1 , fmt .Errorf ("failed to get disk: %w" , err )
1442
1397
}
0 commit comments