mirror of https://github.com/k3s-io/k3s
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 ```pull/8/head
commit
bc6e5255a4
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue