Add DeleteCluster to bootstrapper
This matches StartCluster, and is used to revert the changes done to reset the VM machine state. Even if it fails, continue to deleting the VM... Make sure to handle the case of missing config.pull/3656/head
parent
ec5107ea96
commit
0a91040434
|
@ -23,6 +23,7 @@ import (
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/viper"
|
"github.com/spf13/viper"
|
||||||
|
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
|
||||||
cmdUtil "k8s.io/minikube/cmd/util"
|
cmdUtil "k8s.io/minikube/cmd/util"
|
||||||
"k8s.io/minikube/pkg/minikube/cluster"
|
"k8s.io/minikube/pkg/minikube/cluster"
|
||||||
pkg_config "k8s.io/minikube/pkg/minikube/config"
|
pkg_config "k8s.io/minikube/pkg/minikube/config"
|
||||||
|
@ -43,7 +44,6 @@ associated files.`,
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
profile := viper.GetString(pkg_config.MachineProfile)
|
profile := viper.GetString(pkg_config.MachineProfile)
|
||||||
console.OutStyle("deleting-vm", "Deleting %q Kubernetes cluster ...", profile)
|
|
||||||
api, err := machine.NewAPIClient()
|
api, err := machine.NewAPIClient()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
console.Fatal("Error getting client: %v", err)
|
console.Fatal("Error getting client: %v", err)
|
||||||
|
@ -51,6 +51,22 @@ associated files.`,
|
||||||
}
|
}
|
||||||
defer api.Close()
|
defer api.Close()
|
||||||
|
|
||||||
|
cc, err := pkg_config.Load()
|
||||||
|
if err != nil && !os.IsNotExist(err) {
|
||||||
|
console.ErrLn("Error loading profile config: %v", err)
|
||||||
|
} else if err == nil {
|
||||||
|
kc := cc.KubernetesConfig
|
||||||
|
bsName := viper.GetString(cmdcfg.Bootstrapper) // Name ?
|
||||||
|
console.OutStyle("resetting", "Reverting Kubernetes %s using %s ...", kc.KubernetesVersion, bsName)
|
||||||
|
clusterBootstrapper, err := GetClusterBootstrapper(api, viper.GetString(cmdcfg.Bootstrapper))
|
||||||
|
if err != nil {
|
||||||
|
if err = clusterBootstrapper.DeleteCluster(kc); err != nil {
|
||||||
|
console.ErrLn("Failed to delete cluster: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
console.OutStyle("deleting-vm", "Deleting %q Kubernetes VM ...", profile)
|
||||||
if err = cluster.DeleteHost(api); err != nil {
|
if err = cluster.DeleteHost(api); err != nil {
|
||||||
switch err := errors.Cause(err).(type) {
|
switch err := errors.Cause(err).(type) {
|
||||||
case mcnerror.ErrHostDoesNotExist:
|
case mcnerror.ErrHostDoesNotExist:
|
||||||
|
|
|
@ -31,6 +31,7 @@ type Bootstrapper interface {
|
||||||
StartCluster(config.KubernetesConfig) error
|
StartCluster(config.KubernetesConfig) error
|
||||||
UpdateCluster(config.KubernetesConfig) error
|
UpdateCluster(config.KubernetesConfig) error
|
||||||
RestartCluster(config.KubernetesConfig) error
|
RestartCluster(config.KubernetesConfig) error
|
||||||
|
DeleteCluster(config.KubernetesConfig) error
|
||||||
GetClusterLogsTo(follow bool, out io.Writer) error
|
GetClusterLogsTo(follow bool, out io.Writer) error
|
||||||
SetupCerts(cfg config.KubernetesConfig) error
|
SetupCerts(cfg config.KubernetesConfig) error
|
||||||
GetKubeletStatus() (string, error)
|
GetKubeletStatus() (string, error)
|
||||||
|
|
|
@ -253,6 +253,16 @@ func (k *KubeadmBootstrapper) RestartCluster(k8s config.KubernetesConfig) error
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// DeleteCluster removes the components that were started earlier
|
||||||
|
func (k *KubeadmBootstrapper) DeleteCluster(k8s config.KubernetesConfig) error {
|
||||||
|
cmd := fmt.Sprintf("sudo kubeadm reset --config %s", constants.KubeadmConfigFile)
|
||||||
|
if err := k.c.Run(cmd); err != nil {
|
||||||
|
return errors.Wrapf(err, "running cmd: %s", cmd)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
// PullImages downloads images that will be used by RestartCluster
|
// PullImages downloads images that will be used by RestartCluster
|
||||||
func (k *KubeadmBootstrapper) PullImages(k8s config.KubernetesConfig) error {
|
func (k *KubeadmBootstrapper) PullImages(k8s config.KubernetesConfig) error {
|
||||||
cmd := fmt.Sprintf("sudo kubeadm config images pull --config %s", constants.KubeadmConfigFile)
|
cmd := fmt.Sprintf("sudo kubeadm config images pull --config %s", constants.KubeadmConfigFile)
|
||||||
|
|
|
@ -57,6 +57,7 @@ var styles = map[string]style{
|
||||||
"caching": {Prefix: "🤹 "},
|
"caching": {Prefix: "🤹 "},
|
||||||
"starting-vm": {Prefix: "🔥 "},
|
"starting-vm": {Prefix: "🔥 "},
|
||||||
"starting-none": {Prefix: "🤹 "},
|
"starting-none": {Prefix: "🤹 "},
|
||||||
|
"resetting": {Prefix: "🔄 "},
|
||||||
"deleting-vm": {Prefix: "🔥 "},
|
"deleting-vm": {Prefix: "🔥 "},
|
||||||
"copying": {Prefix: "✨ "},
|
"copying": {Prefix: "✨ "},
|
||||||
"connectivity": {Prefix: "📶 "},
|
"connectivity": {Prefix: "📶 "},
|
||||||
|
|
Loading…
Reference in New Issue