Skip to content

Commit

Permalink
Merge pull request #11504 from ilya-zuyev/ilyaz/fix_delete_paused
Browse files Browse the repository at this point in the history
Fix delete command for paused kic driver with containerd/crio runtime
  • Loading branch information
sharifelgamal committed Jun 1, 2021
2 parents 764ab76 + eff0bc7 commit 3430150
Showing 1 changed file with 64 additions and 13 deletions.
77 changes: 64 additions & 13 deletions cmd/minikube/cmd/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,23 +210,28 @@ func DeleteProfiles(profiles []*config.Profile) []error {
klog.Infof("DeleteProfiles")
var errs []error
for _, profile := range profiles {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()
err := deleteProfile(ctx, profile)
if err != nil {
mm, loadErr := machine.LoadMachine(profile.Name)
errs = append(errs, deleteProfileTimeout(profile)...)
}
return errs
}

if !profile.IsValid() || (loadErr != nil || !mm.IsValid()) {
invalidProfileDeletionErrs := deleteInvalidProfile(profile)
if len(invalidProfileDeletionErrs) > 0 {
errs = append(errs, invalidProfileDeletionErrs...)
}
} else {
errs = append(errs, err)
func deleteProfileTimeout(profile *config.Profile) []error {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
defer cancel()

if err := deleteProfile(ctx, profile); err != nil {

mm, loadErr := machine.LoadMachine(profile.Name)
if !profile.IsValid() || (loadErr != nil || !mm.IsValid()) {
invalidProfileDeletionErrs := deleteInvalidProfile(profile)
if len(invalidProfileDeletionErrs) > 0 {
return invalidProfileDeletionErrs
}
} else {
return []error{err}
}
}
return errs
return nil
}

func deleteProfile(ctx context.Context, profile *config.Profile) error {
Expand All @@ -239,6 +244,9 @@ func deleteProfile(ctx context.Context, profile *config.Profile) error {

// if driver is oci driver, delete containers and volumes
if driver.IsKIC(profile.Config.Driver) {
if err := unpauseIfNeeded(profile); err != nil {
klog.Warningf("failed to unpause %s : %v", profile.Name, err)
}
out.Step(style.DeletingHost, `Deleting "{{.profile_name}}" in {{.driver_name}} ...`, out.V{"profile_name": profile.Name, "driver_name": profile.Config.Driver})
for _, n := range profile.Config.Nodes {
machineName := config.MachineName(*profile.Config, n)
Expand Down Expand Up @@ -295,6 +303,49 @@ func deleteProfile(ctx context.Context, profile *config.Profile) error {
return nil
}

func unpauseIfNeeded(profile *config.Profile) error {
// there is a known issue with removing kicbase container with paused containerd/crio containers inside
// unpause it before we delete it
crName := profile.Config.KubernetesConfig.ContainerRuntime
if crName == "docker" {
return nil
}

api, err := machine.NewAPIClient()
if err != nil {
return err
}
defer api.Close()

host, err := machine.LoadHost(api, profile.Name)
if err != nil {
return err
}

r, err := machine.CommandRunner(host)
if err != nil {
exit.Error(reason.InternalCommandRunner, "Failed to get command runner", err)
}

cr, err := cruntime.New(cruntime.Config{Type: crName, Runner: r})
if err != nil {
exit.Error(reason.InternalNewRuntime, "Failed to create runtime", err)
}

paused, err := cluster.CheckIfPaused(cr, nil)
if err != nil {
return err
}

if !paused {
return nil
}

klog.Infof("Unpause cluster %q", profile.Name)
_, err = cluster.Unpause(cr, r, nil)
return err
}

func deleteHosts(api libmachine.API, cc *config.ClusterConfig) {
register.Reg.SetStep(register.Deleting)

Expand Down

0 comments on commit 3430150

Please sign in to comment.