Skip to content

Commit 435cb92

Browse files
ayufantmaczukin
authored andcommitted
404 is a success when deleting GCE machine and disk
Signed-off-by: Tomasz Maczukin <tomasz@maczukin.pl>
1 parent 49dfaa7 commit 435cb92

File tree

2 files changed

+24
-9
lines changed

2 files changed

+24
-9
lines changed

drivers/google/compute_util.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package google
33
import (
44
"fmt"
55
"io/ioutil"
6+
"net/http"
67
"net/url"
78
"regexp"
89
"strings"
@@ -478,3 +479,16 @@ func unwrapGoogleError(err error) error {
478479

479480
return err
480481
}
482+
483+
func isNotFound(err error) bool {
484+
googleErr, ok := err.(*googleapi.Error)
485+
if !ok {
486+
return false
487+
}
488+
489+
if googleErr.Code == http.StatusNotFound {
490+
return true
491+
}
492+
493+
return false
494+
}

drivers/google/google.go

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ import (
44
"errors"
55
"fmt"
66
"net"
7-
"net/http"
87
"strings"
98

109
"github.com/docker/machine/libmachine/drivers"
1110
"github.com/docker/machine/libmachine/log"
1211
"github.com/docker/machine/libmachine/mcnflag"
1312
"github.com/docker/machine/libmachine/ssh"
1413
"github.com/docker/machine/libmachine/state"
15-
16-
"google.golang.org/api/googleapi"
1714
)
1815

1916
// Driver is a struct compatible with the docker.hosts.drivers.Driver interface.
@@ -343,7 +340,7 @@ func (d *Driver) Start() error {
343340

344341
instance, err := c.instance()
345342
if err != nil {
346-
if !strings.Contains(err.Error(), "notFound") {
343+
if !isNotFound(err) {
347344
return err
348345
}
349346
}
@@ -399,16 +396,20 @@ func (d *Driver) Remove() error {
399396
}
400397

401398
if err := c.deleteInstance(); err != nil {
402-
googleErr, ok := err.(*googleapi.Error)
403-
if !ok {
399+
if isNotFound(err) {
400+
log.Warn("Remote instance does not exist, proceeding with removing local reference")
401+
} else {
404402
return err
405403
}
406-
if googleErr.Code == http.StatusNotFound {
407-
log.Warn("Remote instance does not exist, proceeding with removing local reference")
404+
}
405+
406+
if err := c.deleteDisk(); err != nil {
407+
if isNotFound(err) {
408+
log.Warn("Remote disk does not exist, proceeding")
408409
} else {
409410
return err
410411
}
411412
}
412413

413-
return c.deleteDisk()
414+
return nil
414415
}

0 commit comments

Comments
 (0)