diff --git a/cmd/minikube/cmd/pause.go b/cmd/minikube/cmd/pause.go index 33ef1f9f04..d7b090ce83 100644 --- a/cmd/minikube/cmd/pause.go +++ b/cmd/minikube/cmd/pause.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/viper" "k8s.io/minikube/pkg/minikube/cluster" + "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/cruntime" "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/exit" @@ -84,6 +85,6 @@ func runPause(cmd *cobra.Command, args []string) { } func init() { - pauseCmd.Flags().StringSliceVarP(&namespaces, "--namespaces", "n", cluster.DefaultNamespaces, "namespaces to pause") + pauseCmd.Flags().StringSliceVarP(&namespaces, "--namespaces", "n", constants.DefaultNamespaces, "namespaces to pause") pauseCmd.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "If set, pause all namespaces") } diff --git a/cmd/minikube/cmd/unpause.go b/cmd/minikube/cmd/unpause.go index d27801fc23..e7295b74cd 100644 --- a/cmd/minikube/cmd/unpause.go +++ b/cmd/minikube/cmd/unpause.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/viper" "k8s.io/minikube/pkg/minikube/cluster" + "k8s.io/minikube/pkg/minikube/constants" "k8s.io/minikube/pkg/minikube/cruntime" "k8s.io/minikube/pkg/minikube/driver" "k8s.io/minikube/pkg/minikube/exit" @@ -82,6 +83,6 @@ var unpauseCmd = &cobra.Command{ } func init() { - unpauseCmd.Flags().StringSliceVarP(&namespaces, "--namespaces", "n", cluster.DefaultNamespaces, "namespaces to unpause") + unpauseCmd.Flags().StringSliceVarP(&namespaces, "--namespaces", "n", constants.DefaultNamespaces, "namespaces to unpause") unpauseCmd.Flags().BoolVarP(&allNamespaces, "all-namespaces", "A", false, "If set, unpause all namespaces") } diff --git a/pkg/drivers/kic/kic.go b/pkg/drivers/kic/kic.go index 5bf91e9710..78d2e45828 100644 --- a/pkg/drivers/kic/kic.go +++ b/pkg/drivers/kic/kic.go @@ -36,6 +36,7 @@ import ( "k8s.io/minikube/pkg/minikube/assets" "k8s.io/minikube/pkg/minikube/command" "k8s.io/minikube/pkg/minikube/constants" + "k8s.io/minikube/pkg/minikube/cruntime" "k8s.io/minikube/pkg/minikube/download" "k8s.io/minikube/pkg/minikube/kubelet" ) @@ -320,6 +321,27 @@ func (d *Driver) Stop() error { // to avoid bind address be taken on an upgrade. more info https://github.com/kubernetes/minikube/issues/7171 if err := kubelet.Stop(d.exec); err != nil { glog.Warningf("couldn't stop kubelet. will continue with stop anyways: %v", err) + if err := kubelet.ForceStop(d.exec); err != nil { + glog.Warningf("couldn't force stop kubelet. will continue with stop anyways: %v", err) + } + } + + runtime, err := cruntime.New(cruntime.Config{Type: d.NodeConfig.ContainerRuntime, Runner: d.exec}) + if err != nil { // won't return error because: + // even though we can't stop the cotainers inside, we still wanna stop the minikube container itself + glog.Errorf("unable to get container runtime: %v", err) + } else { + containers, err := runtime.ListContainers(cruntime.ListOptions{Namespaces: constants.DefaultNamespaces}) + if err != nil { + return errors.Wrap(err, "containers") + } + if len(containers) > 0 { + if err := runtime.StopContainers(containers); err != nil { + return errors.Wrap(err, "stop containers") + } + } + glog.Infof("successfully stopped kubernetes!") + } cmd := exec.Command(d.NodeConfig.OCIBinary, "stop", d.MachineName) diff --git a/pkg/drivers/none/none.go b/pkg/drivers/none/none.go index 6e655183a8..a0be67ff56 100644 --- a/pkg/drivers/none/none.go +++ b/pkg/drivers/none/none.go @@ -221,7 +221,8 @@ func (d *Driver) Stop() error { if err := kubelet.Stop(d.exec); err != nil { glog.Warningf("couldn't stop kubelet. will continue with stop anyways: %v", err) } - containers, err := d.runtime.ListContainers(cruntime.ListOptions{}) + containers, err := d.runtime.ListContainers(cruntime.ListOptions{Namespaces: constants.DefaultNamespaces}) + if err != nil { return errors.Wrap(err, "containers") } diff --git a/pkg/minikube/cluster/pause.go b/pkg/minikube/cluster/pause.go index 2f98cf6de3..d7661f1274 100644 --- a/pkg/minikube/cluster/pause.go +++ b/pkg/minikube/cluster/pause.go @@ -24,14 +24,6 @@ import ( "k8s.io/minikube/pkg/minikube/kubelet" ) -// DefaultNamespaces are namespaces used by minikube, including addons -var DefaultNamespaces = []string{ - "kube-system", - "kubernetes-dashboard", - "storage-gluster", - "istio-operator", -} - // Pause pauses a Kubernetes cluster func Pause(cr cruntime.Manager, r command.Runner, namespaces []string) ([]string, error) { ids := []string{} diff --git a/pkg/minikube/constants/constants.go b/pkg/minikube/constants/constants.go index ecaa8cdb98..33ae576f48 100644 --- a/pkg/minikube/constants/constants.go +++ b/pkg/minikube/constants/constants.go @@ -92,4 +92,12 @@ var ( KubernetesReleaseBinaries = []string{"kubelet", "kubeadm", "kubectl"} // ImageCacheDir is the path to the image cache directory ImageCacheDir = localpath.MakeMiniPath("cache", "images") + + // DefaultNamespaces are kubernetes namespaces used by minikube, including addons + DefaultNamespaces = []string{ + "kube-system", + "kubernetes-dashboard", + "storage-gluster", + "istio-operator", + } )