mirror of https://github.com/k3s-io/k3s
fix commands running crictl
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.pull/8/head
parent
7ffd171c29
commit
145cd635e2
|
@ -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,
|
||||||
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) {
|
||||||
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
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue