diff --git a/cmd/kubeadm/app/cmd/reset.go b/cmd/kubeadm/app/cmd/reset.go index 4defa95bd80..a38c999fb1b 100644 --- a/cmd/kubeadm/app/cmd/reset.go +++ b/cmd/kubeadm/app/cmd/reset.go @@ -39,12 +39,6 @@ import ( utilsexec "k8s.io/utils/exec" ) -var ( - crictlSandboxesParamsFormat = "%s -r %s sandboxes --quiet | xargs -r" - crictlStopParamsFormat = "%s -r %s stops %s" - crictlRemoveParamsFormat = "%s -r %s rms %s" -) - // NewCmdReset returns the "kubeadm reset" command func NewCmdReset(in io.Reader, out io.Writer) *cobra.Command { var skipPreFlight bool @@ -213,28 +207,31 @@ func resetWithCrictl(execer utilsexec.Interface, dockerCheck preflight.Checker, glog.Infof("[reset] cleaning up running containers using crictl with socket %s\n", criSocketPath) glog.V(1).Infoln("[reset] listing running pods using crictl") - listcmd := fmt.Sprintf(crictlSandboxesParamsFormat, crictlPath, criSocketPath) - glog.V(1).Infof("[reset] executing comand %q", listcmd) - output, err := execer.Command(listcmd).CombinedOutput() + params := []string{"-r", criSocketPath, "pods", "--quiet"} + glog.V(1).Infof("[reset] executing command %s %s", crictlPath, strings.Join(params, " ")) + output, err := execer.Command(crictlPath, params...).CombinedOutput() if err != nil { - glog.Infoln("[reset] failed to list running pods using crictl. Trying using docker instead") + glog.Infof("[reset] failed to list running pods using crictl: %s. Trying using docker instead", err) resetWithDocker(execer, dockerCheck) return } sandboxes := strings.Split(string(output), " ") glog.V(1).Infoln("[reset] stopping and removing running containers using crictl") for _, s := range sandboxes { - stopcmd := fmt.Sprintf(crictlStopParamsFormat, crictlPath, criSocketPath, s) - glog.V(1).Infof("[reset] executing command %q", stopcmd) - if err := execer.Command(stopcmd).Run(); err != nil { - glog.Infoln("[reset] failed to stop the running containers using crictl. Trying using docker instead") + if strings.TrimSpace(s) == "" { + continue + } + params = []string{"-r", criSocketPath, "stop", s} + glog.V(1).Infof("[reset] executing command %s %s", crictlPath, strings.Join(params, " ")) + if err := execer.Command(crictlPath, params...).Run(); err != nil { + glog.Infof("[reset] failed to stop the running containers using crictl: %s. Trying using docker instead", err) resetWithDocker(execer, dockerCheck) return } - removecmd := fmt.Sprintf(crictlRemoveParamsFormat, crictlPath, criSocketPath, s) - glog.V(1).Infof("[reset] executing command %q", removecmd) - if err := execer.Command(removecmd).Run(); err != nil { - glog.Infoln("[reset] failed to remove the running containers using crictl. Trying using docker instead") + params = []string{"-r", criSocketPath, "rm", s} + glog.V(1).Infof("[reset] executing command %s %s", crictlPath, strings.Join(params, " ")) + if err := execer.Command(crictlPath, params...).Run(); err != nil { + glog.Infof("[reset] failed to remove the running containers using crictl: %s. Trying using docker instead", err) resetWithDocker(execer, dockerCheck) return } diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index 4336a019d0c..34cf9bdccf8 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -107,7 +107,7 @@ func (criCheck CRICheck) Check() (warnings, errors []error) { errors = append(errors, fmt.Errorf("unable to find command crictl: %s", err)) return warnings, errors } - if err := criCheck.exec.Command(fmt.Sprintf("%s -r %s info", crictlPath, criCheck.socket)).Run(); err != nil { + if err := criCheck.exec.Command(crictlPath, "-r", criCheck.socket, "info").Run(); err != nil { errors = append(errors, fmt.Errorf("unable to check if the container runtime at %q is running: %s", criCheck.socket, err)) return warnings, errors }