From 1dcb0255592e4b5ece3eb727341a5734402ef068 Mon Sep 17 00:00:00 2001 From: Brendan Burns Date: Thu, 11 Dec 2014 13:00:26 -0800 Subject: [PATCH] Handle PD already being attached to the machine. --- pkg/cloudprovider/gce/gce.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/cloudprovider/gce/gce.go b/pkg/cloudprovider/gce/gce.go index a3fde21749e..469a9878c34 100644 --- a/pkg/cloudprovider/gce/gce.go +++ b/pkg/cloudprovider/gce/gce.go @@ -376,6 +376,21 @@ func (gce *GCECloud) AttachDisk(diskName string, readOnly bool) error { } attachedDisk := gce.convertDiskToAttachedDisk(disk, readWrite) _, err = gce.service.Instances.AttachDisk(gce.projectID, gce.zone, gce.instanceID, attachedDisk).Do() + if err != nil { + // Check if the disk is already attached to this instance. We do this only + // in the error case, since it is expected to be exceptional. + instance, err := gce.service.Instances.Get(gce.projectID, gce.zone, gce.instanceID).Do() + if err != nil { + return err + } + for _, disk := range instance.Disks { + if disk.InitializeParams.DiskName == diskName { + // Disk is already attached, we're good to go. + return nil + } + } + + } return err }