diff --git a/pkg/drivers/kic/kic.go b/pkg/drivers/kic/kic.go index 7c6ab52aafa37515565ac495ea7a3981e3edad1d..05f9d1cb3c9bda3de494adb959c82fda2770284a 100644 --- a/pkg/drivers/kic/kic.go +++ b/pkg/drivers/kic/kic.go @@ -282,6 +282,10 @@ func (d *Driver) Remove() error { } } + + if id, err := oci.ContainerID(d.OCIBinary, d.MachineName); err == nil && id != "" { + return fmt.Errorf("expected no container ID be found for %q after delete. but got %q", d.MachineName, id) + } return nil } @@ -370,6 +374,11 @@ func (d *Driver) Stop() error { return nil } +// RunSSHCommandFromDriver implements direct ssh control to the driver +func (d *Driver) RunSSHCommandFromDriver() error { + return fmt.Errorf("driver does not support RunSSHCommandFromDriver commands") +} + // killAPIServerProc will kill an api server proc if it exists // to ensure this never happens https://github.com/kubernetes/minikube/issues/7521 func killAPIServerProc(runner command.Runner) error { diff --git a/pkg/drivers/kic/oci/oci.go b/pkg/drivers/kic/oci/oci.go index df76d9add26b645c9bc68f5f0c8927251c8810e5..ea739fff9036664b9fa4dff528e7cea4699fa819 100644 --- a/pkg/drivers/kic/oci/oci.go +++ b/pkg/drivers/kic/oci/oci.go @@ -497,15 +497,17 @@ func ContainerStatus(ociBin string, name string) (string, error) { // to ensure the containers process and networking bindings are all closed // to avoid containers getting stuck before delete https://github.com/kubernetes/minikube/issues/7657 func ShutDown(ociBin string, name string) error { - cmd := exec.Command(ociBin, "exec", "--privileged", "-t", name, "sudo", "init", "0") + cmd := exec.Command(ociBin, "exec", "--privileged", "-t", name, "/bin/bash", "-c", "sudo init 0") if out, err := cmd.CombinedOutput(); err != nil { - return errors.Wrapf(err, "shutdown %s: output %q", name, out) + glog.Infof("error shutdown %s output %q : %v", name, out, err) } - + // helps with allowing docker realize the container is exited and report its status correctly. + time.Sleep(time.Second * 1) // wait till it is stoped stopped := func() error { st, err := ContainerStatus(ociBin, name) if st == "exited" { + glog.Infof("container %s status is %s", name, st) return nil } if err != nil { diff --git a/pkg/drivers/kic/oci/types.go b/pkg/drivers/kic/oci/types.go index 6d063e0fd47dcd5c8d51f05e9186ca50f98368f2..8c43ce7d8b1cae1675a16f3a4dad0149331c4a3d 100644 --- a/pkg/drivers/kic/oci/types.go +++ b/pkg/drivers/kic/oci/types.go @@ -31,8 +31,6 @@ const ( nodeRoleLabelKey = "role.minikube.sigs.k8s.io" // CreatedByLabelKey is applied to any container/volume that is created by minikube created_by.minikube.sigs.k8s.io=true CreatedByLabelKey = "created_by.minikube.sigs.k8s.io" - // ShutownCmd is the command halt and stop the container - ShutownCmd = "sudo init 0" ) // CreateParams are parameters needed to create a container diff --git a/pkg/minikube/machine/stop.go b/pkg/minikube/machine/stop.go index 7e6024417e18e5d82c4025b31af1704c155527de..fbe213016d4295c4c48c3e92456af255b73553ec 100644 --- a/pkg/minikube/machine/stop.go +++ b/pkg/minikube/machine/stop.go @@ -80,8 +80,8 @@ func trySSHPowerOff(h *host.Host) error { out.T(out.Shutdown, `Powering off "{{.profile_name}}" via SSH ...`, out.V{"profile_name": h.Name}) if driver.IsKIC(h.DriverName) { - out, err := h.RunSSHCommand(oci.ShutownCmd) - glog.Infof("shutdown cmd %q result: out=%s, err=%v", oci.ShutownCmd, out, err) + err := oci.ShutDown(h.DriverName, h.Name) + glog.Infof("shutdown container: err=%v", err) } else { out, err := h.RunSSHCommand("sudo poweroff") // poweroff always results in an error, since the host disconnects.