Merge pull request #11504 from ilya-zuyev/ilyaz/fix_delete_paused
Fix delete command for paused kic driver with containerd/crio runtimepull/11556/head
commit
343015001a
|
@ -210,25 +210,30 @@ 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)
|
||||
|
||||
if !profile.IsValid() || (loadErr != nil || !mm.IsValid()) {
|
||||
invalidProfileDeletionErrs := deleteInvalidProfile(profile)
|
||||
if len(invalidProfileDeletionErrs) > 0 {
|
||||
errs = append(errs, invalidProfileDeletionErrs...)
|
||||
}
|
||||
} else {
|
||||
errs = append(errs, err)
|
||||
}
|
||||
}
|
||||
errs = append(errs, deleteProfileTimeout(profile)...)
|
||||
}
|
||||
return errs
|
||||
}
|
||||
|
||||
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 nil
|
||||
}
|
||||
|
||||
func deleteProfile(ctx context.Context, profile *config.Profile) error {
|
||||
klog.Infof("Deleting %s", profile.Name)
|
||||
register.Reg.SetStep(register.Deleting)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue