Skip to content

Commit

Permalink
Merge pull request #3656 from afbjorklund/reset
Browse files Browse the repository at this point in the history
Add DeleteCluster to bootstrapper
  • Loading branch information
tstromberg authored Feb 12, 2019
2 parents ec5107e + 0a91040 commit 0fa4923
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 1 deletion.
18 changes: 17 additions & 1 deletion cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/pkg/errors"
"github.com/spf13/cobra"
"github.com/spf13/viper"
cmdcfg "k8s.io/minikube/cmd/minikube/cmd/config"
cmdUtil "k8s.io/minikube/cmd/util"
"k8s.io/minikube/pkg/minikube/cluster"
pkg_config "k8s.io/minikube/pkg/minikube/config"
Expand All @@ -43,14 +44,29 @@ associated files.`,
os.Exit(1)
}
profile := viper.GetString(pkg_config.MachineProfile)
console.OutStyle("deleting-vm", "Deleting %q Kubernetes cluster ...", profile)
api, err := machine.NewAPIClient()
if err != nil {
console.Fatal("Error getting client: %v", err)
os.Exit(1)
}
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 {
switch err := errors.Cause(err).(type) {
case mcnerror.ErrHostDoesNotExist:
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/bootstrapper/bootstrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Bootstrapper interface {
StartCluster(config.KubernetesConfig) error
UpdateCluster(config.KubernetesConfig) error
RestartCluster(config.KubernetesConfig) error
DeleteCluster(config.KubernetesConfig) error
GetClusterLogsTo(follow bool, out io.Writer) error
SetupCerts(cfg config.KubernetesConfig) error
GetKubeletStatus() (string, error)
Expand Down
10 changes: 10 additions & 0 deletions pkg/minikube/bootstrapper/kubeadm/kubeadm.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,16 @@ func (k *KubeadmBootstrapper) RestartCluster(k8s config.KubernetesConfig) error
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
func (k *KubeadmBootstrapper) PullImages(k8s config.KubernetesConfig) error {
cmd := fmt.Sprintf("sudo kubeadm config images pull --config %s", constants.KubeadmConfigFile)
Expand Down
1 change: 1 addition & 0 deletions pkg/minikube/console/style.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ var styles = map[string]style{
"caching": {Prefix: "🤹 "},
"starting-vm": {Prefix: "🔥 "},
"starting-none": {Prefix: "🤹 "},
"resetting": {Prefix: "🔄 "},
"deleting-vm": {Prefix: "🔥 "},
"copying": {Prefix: "✨ "},
"connectivity": {Prefix: "📶 "},
Expand Down

0 comments on commit 0fa4923

Please sign in to comment.