From 0e5059ddd05fb8c179c41b07c82e9f3c2bdc244a Mon Sep 17 00:00:00 2001 From: Medya Gh Date: Thu, 30 Jan 2020 21:36:56 -0800 Subject: [PATCH] log warning if docker is stuck --- go.mod | 1 + go.sum | 1 + pkg/drivers/kic/kic.go | 26 +++++++++++--------------- pkg/drivers/kic/oci/oci.go | 10 ++++++++++ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index c31b89c1c9..09e880afb3 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 40b885f371..77a6bfb595 100644 --- a/go.sum +++ b/go.sum @@ -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= diff --git a/pkg/drivers/kic/kic.go b/pkg/drivers/kic/kic.go index c461d2c3d6..cfc6b33f33 100644 --- a/pkg/drivers/kic/kic.go +++ b/pkg/drivers/kic/kic.go @@ -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 -} diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index 29805c1e9c..1ea1f53c3c 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -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)