@@ -92,7 +92,7 @@ type GCECompute interface {
92
92
ValidateExistingDisk (ctx context.Context , disk * CloudDisk , params common.DiskParameters , reqBytes , limBytes int64 , multiWriter bool ) error
93
93
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 ) error
94
94
DeleteDisk (ctx context.Context , project string , volumeKey * meta.Key ) error
95
- AttachDisk (ctx context.Context , project string , volKey * meta.Key , readWrite , diskType , instanceZone , instanceName string ) error
95
+ AttachDisk (ctx context.Context , project string , volKey * meta.Key , readWrite , diskType , instanceZone , instanceName string , forceAttach bool ) error
96
96
DetachDisk (ctx context.Context , project , deviceName , instanceZone , instanceName string ) error
97
97
GetDiskSourceURI (project string , volKey * meta.Key ) string
98
98
GetDiskTypeURI (project string , volKey * meta.Key , diskType string ) string
@@ -700,7 +700,7 @@ func (cloud *CloudProvider) deleteRegionalDisk(ctx context.Context, project, reg
700
700
return nil
701
701
}
702
702
703
- func (cloud * CloudProvider ) AttachDisk (ctx context.Context , project string , volKey * meta.Key , readWrite , diskType , instanceZone , instanceName string ) error {
703
+ func (cloud * CloudProvider ) AttachDisk (ctx context.Context , project string , volKey * meta.Key , readWrite , diskType , instanceZone , instanceName string , forceAttach bool ) error {
704
704
klog .V (5 ).Infof ("Attaching disk %v to %s" , volKey , instanceName )
705
705
source := cloud .GetDiskSourceURI (project , volKey )
706
706
@@ -714,9 +714,13 @@ func (cloud *CloudProvider) AttachDisk(ctx context.Context, project string, volK
714
714
Mode : readWrite ,
715
715
Source : source ,
716
716
Type : diskType ,
717
+ // This parameter is ignored in the call, the ForceAttach decorator
718
+ // (query parameter) is the important one. We'll set it in both places
719
+ // in case that behavior changes.
720
+ ForceAttach : forceAttach ,
717
721
}
718
722
719
- op , err := cloud .service .Instances .AttachDisk (project , instanceZone , instanceName , attachedDiskV1 ).Context (ctx ).Do ()
723
+ op , err := cloud .service .Instances .AttachDisk (project , instanceZone , instanceName , attachedDiskV1 ).Context (ctx ).ForceAttach ( forceAttach ). Do ()
720
724
if err != nil {
721
725
return fmt .Errorf ("failed cloud service attach disk call: %w" , err )
722
726
}
0 commit comments