Skip to content
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

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

Merged
merged 11 commits into from
Jun 1, 2021
76 changes: 63 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 {
medyagh marked this conversation as resolved.
Show resolved Hide resolved
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,48 @@ 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 containers inside
// unpause it before we delete it
if profile.Config.KubernetesConfig.ContainerRuntime != "containerd" {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crio also has this problem., we can check if Not Docker

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

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: profile.Config.KubernetesConfig.ContainerRuntime, Runner: r})
if err != nil {
exit.Error(reason.InternalNewRuntime, "Failed 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