Merge pull request #4330 from tmaczukin/make-404-success-when-deleting-gce-machine-and-disk

404 is a success when deleting GCE machine and disk
This commit is contained in:
David Gageot
2018-01-28 09:51:37 -08:00
committed by GitHub
2 changed files with 25 additions and 10 deletions

View File

@@ -3,6 +3,7 @@ package google
import (
"fmt"
"io/ioutil"
"net/http"
"net/url"
"regexp"
"strings"
@@ -487,3 +488,16 @@ func unwrapGoogleError(err error) error {
return err
}
func isNotFound(err error) bool {
googleErr, ok := err.(*googleapi.Error)
if !ok {
return false
}
if googleErr.Code == http.StatusNotFound {
return true
}
return false
}

View File

@@ -4,7 +4,6 @@ import (
"errors"
"fmt"
"net"
"net/http"
"strings"
"github.com/docker/machine/libmachine/drivers"
@@ -12,8 +11,6 @@ import (
"github.com/docker/machine/libmachine/mcnflag"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"google.golang.org/api/googleapi"
)
// Driver is a struct compatible with the docker.hosts.drivers.Driver interface.
@@ -343,7 +340,7 @@ func (d *Driver) Start() error {
instance, err := c.instance()
if err != nil {
if !strings.Contains(err.Error(), "notFound") {
if !isNotFound(err) {
return err
}
}
@@ -399,16 +396,20 @@ func (d *Driver) Remove() error {
}
if err := c.deleteInstance(); err != nil {
googleErr, ok := err.(*googleapi.Error)
if !ok {
return err
}
if googleErr.Code == http.StatusNotFound {
if isNotFound(err) {
log.Warn("Remote instance does not exist, proceeding with removing local reference")
} else {
return err
}
}
return c.deleteDisk()
if err := c.deleteDisk(); err != nil {
if isNotFound(err) {
log.Warn("Remote disk does not exist, proceeding")
} else {
return err
}
}
return nil
}