log warning if docker is stuck

pull/6441/head
Medya Gh 2020-01-30 21:36:56 -08:00
parent a6ec05e35a
commit 0e5059ddd0
4 changed files with 23 additions and 15 deletions

1
go.mod
View File

@ -18,6 +18,7 @@ require (
github.com/elazarl/goproxy v0.0.0-20190421051319-9d40249d3c2f
github.com/elazarl/goproxy/ext v0.0.0-20190421051319-9d40249d3c2f // indirect
github.com/evanphx/json-patch v4.5.0+incompatible // indirect
github.com/go-acme/lego v2.5.0+incompatible
github.com/go-ole/go-ole v1.2.4 // indirect
github.com/golang-collections/collections v0.0.0-20130729185459-604e922904d3
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b

1
go.sum
View File

@ -172,6 +172,7 @@ github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeME
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
github.com/globalsign/mgo v0.0.0-20180905125535-1ca0a4f7cbcb/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/globalsign/mgo v0.0.0-20181015135952-eeefdecb41b8/go.mod h1:xkRDCp4j0OGD1HRkm4kmhM+pmpv3AKq5SU7GMg4oO/Q=
github.com/go-acme/lego v2.5.0+incompatible h1:5fNN9yRQfv8ymH3DSsxla+4aYeQt2IgfZqHKVnK8f0s=
github.com/go-acme/lego v2.5.0+incompatible/go.mod h1:yzMNe9CasVUhkquNvti5nAtPmG94USbYxYrZfTkIn0M=
github.com/go-bindata/go-bindata v3.1.1+incompatible/go.mod h1:xK8Dsgwmeed+BBsSy2XTopBn/8uK2HWuGSnA11C3Joo=
github.com/go-critic/go-critic v0.3.5-0.20190526074819-1df300866540/go.mod h1:+sE8vrLDS2M0pZkBk0wy6+nLdKexVDrl/jBqQOTDThA=

View File

@ -24,6 +24,7 @@ import (
"strings"
"github.com/docker/machine/libmachine/drivers"
"github.com/docker/machine/libmachine/log"
"github.com/docker/machine/libmachine/ssh"
"github.com/docker/machine/libmachine/state"
"github.com/golang/glog"
@ -183,7 +184,7 @@ func (d *Driver) GetState() (state.State, error) {
out, err := cmd.CombinedOutput()
o := strings.Trim(string(out), "\n")
if err != nil {
return state.Error, errors.Wrapf(err, "error stop node %s", d.MachineName)
return state.Error, errors.Wrapf(err, "get container %s status", d.MachineName)
}
switch o {
case "running":
@ -212,12 +213,17 @@ func (d *Driver) Kill() error {
// Remove will delete the Kic Node Container
func (d *Driver) Remove() error {
if _, err := d.nodeID(d.MachineName); err != nil {
return errors.Wrapf(err, "not found node %s", d.MachineName)
if _, err := oci.ContainerID(d.OCIBinary, d.MachineName); err != nil {
log.Warnf("could not find the container %s to remove it.", d.MachineName)
}
cmd := exec.Command(d.NodeConfig.OCIBinary, "rm", "-f", "-v", d.MachineName)
if err := cmd.Run(); err != nil {
return errors.Wrapf(err, "error removing node %s", d.MachineName)
o, err := cmd.CombinedOutput()
out := strings.Trim(string(o), "\n")
if err != nil {
if strings.Contains(out, "is already in progress") {
log.Warnf("Docker engine is stuck. please restart docker daemon on your computer.", d.MachineName)
}
return errors.Wrapf(err, "removing container %s, output %s", d.MachineName, out)
}
return nil
}
@ -286,13 +292,3 @@ func (d *Driver) Stop() error {
func (d *Driver) RunSSHCommandFromDriver() error {
return fmt.Errorf("driver does not support RunSSHCommandFromDriver commands")
}
// looks up for a container node by name, will return error if not found.
func (d *Driver) nodeID(nameOrID string) (string, error) {
cmd := exec.Command(d.NodeConfig.OCIBinary, "inspect", "-f", "{{.Id}}", nameOrID)
id, err := cmd.CombinedOutput()
if err != nil {
id = []byte{}
}
return string(id), err
}

View File

@ -171,6 +171,16 @@ func ContainerIPs(ociBinary string, name string) (string, string, error) {
}
// ContainerID returns id of a container name
func ContainerID(ociBinary string, nameOrID string) (string, error) {
cmd := exec.Command(ociBinary, "inspect", "-f", "{{.Id}}", nameOrID)
id, err := cmd.CombinedOutput()
if err != nil {
id = []byte{}
}
return string(id), err
}
// ListOwnedContainers lists all the containres that kic driver created on user's machine using a label
func ListOwnedContainers(ociBinary string) ([]string, error) {
return listContainersByLabel(ociBinary, ClusterLabelKey)