Skip to content

Fix delete command for paused kic driver with containerd/crio runtime #11504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jun 1, 2021
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