stop k8s in kic and none
parent
fae3e34319
commit
5f90a319bd
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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{}
|
||||
|
|
|
@ -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",
|
||||
}
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue