Unverified Commit bc6e5255 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #63297 from bart0sh/PR0012-kubeadm-fix-exec.Command

Automatic merge from submit-queue (batch tested with PRs 63297, 61883). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Fix commands running crictl **What this PR does / why we need it**: Running "kubeadm reset --cri-socket unix:///var/run/crio/crio.sock" fails with this error: [reset] Cleaning up running containers using crictl with socket unix:///var/run/crio/crio.sock [reset] Failed to list running pods using crictl. Trying using docker instead. The actual error returned by underlying API os/exec is: fork/exec /usr/bin/crictl -r /var/run/crio/crio.sock info: no such file or directory This is caused by passing full command line instead of executable path as a first parameter to the Command API. Fixed by passing correct parameters to the Command API. Improved error output. **Special notes for your reviewer**: This issue was caused by breaking crictl command execution in [PR 58802](https://github.com/kubernetes/kubernetes/pull/58802) **Release note**: ```release-note NONE ```
parents 5ba149e1 145cd635
...@@ -39,12 +39,6 @@ import ( ...@@ -39,12 +39,6 @@ import (
utilsexec "k8s.io/utils/exec" 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 // NewCmdReset returns the "kubeadm reset" command
func NewCmdReset(in io.Reader, out io.Writer) *cobra.Command { func NewCmdReset(in io.Reader, out io.Writer) *cobra.Command {
var skipPreFlight bool var skipPreFlight bool
...@@ -213,28 +207,31 @@ func resetWithCrictl(execer utilsexec.Interface, dockerCheck preflight.Checker, ...@@ -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.Infof("[reset] cleaning up running containers using crictl with socket %s\n", criSocketPath)
glog.V(1).Infoln("[reset] listing running pods using crictl") glog.V(1).Infoln("[reset] listing running pods using crictl")
listcmd := fmt.Sprintf(crictlSandboxesParamsFormat, crictlPath, criSocketPath) params := []string{"-r", criSocketPath, "pods", "--quiet"}
glog.V(1).Infof("[reset] executing comand %q", listcmd) glog.V(1).Infof("[reset] executing command %s %s", crictlPath, strings.Join(params, " "))
output, err := execer.Command(listcmd).CombinedOutput() output, err := execer.Command(crictlPath, params...).CombinedOutput()
if err != nil { 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) resetWithDocker(execer, dockerCheck)
return return
} }
sandboxes := strings.Split(string(output), " ") sandboxes := strings.Split(string(output), " ")
glog.V(1).Infoln("[reset] stopping and removing running containers using crictl") glog.V(1).Infoln("[reset] stopping and removing running containers using crictl")
for _, s := range sandboxes { for _, s := range sandboxes {
stopcmd := fmt.Sprintf(crictlStopParamsFormat, crictlPath, criSocketPath, s) if strings.TrimSpace(s) == "" {
glog.V(1).Infof("[reset] executing command %q", stopcmd) continue
if err := execer.Command(stopcmd).Run(); err != nil { }
glog.Infoln("[reset] failed to stop the running containers using crictl. Trying using docker instead") 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) resetWithDocker(execer, dockerCheck)
return return
} }
removecmd := fmt.Sprintf(crictlRemoveParamsFormat, crictlPath, criSocketPath, s) params = []string{"-r", criSocketPath, "rm", s}
glog.V(1).Infof("[reset] executing command %q", removecmd) glog.V(1).Infof("[reset] executing command %s %s", crictlPath, strings.Join(params, " "))
if err := execer.Command(removecmd).Run(); err != nil { if err := execer.Command(crictlPath, params...).Run(); err != nil {
glog.Infoln("[reset] failed to remove the running containers using crictl. Trying using docker instead") glog.Infof("[reset] failed to remove the running containers using crictl: %s. Trying using docker instead", err)
resetWithDocker(execer, dockerCheck) resetWithDocker(execer, dockerCheck)
return return
} }
......
...@@ -107,7 +107,7 @@ func (criCheck CRICheck) Check() (warnings, errors []error) { ...@@ -107,7 +107,7 @@ func (criCheck CRICheck) Check() (warnings, errors []error) {
errors = append(errors, fmt.Errorf("unable to find command crictl: %s", err)) errors = append(errors, fmt.Errorf("unable to find command crictl: %s", err))
return warnings, errors 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)) errors = append(errors, fmt.Errorf("unable to check if the container runtime at %q is running: %s", criCheck.socket, err))
return warnings, errors return warnings, errors
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment