diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index 1441e5e2821..98b583df054 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -103,7 +103,7 @@ type ContainerAttacher interface { // CommandRunner encapsulates the command runner interfaces for testability. type ContainerCommandRunner interface { // TODO(vmarmol): Merge RunInContainer and ExecInContainer. - // Runs the command in the container of the specified pod using nsinit. + // Runs the command in the container of the specified pod. RunInContainer(containerID ContainerID, cmd []string) ([]byte, error) // Runs the command in the container of the specified pod using nsenter. // Attaches the processes stdin, stdout, and stderr. Optionally uses a diff --git a/pkg/kubelet/dockertools/docker_test.go b/pkg/kubelet/dockertools/docker_test.go index 1a7366560ec..8d454b11dc3 100644 --- a/pkg/kubelet/dockertools/docker_test.go +++ b/pkg/kubelet/dockertools/docker_test.go @@ -177,39 +177,6 @@ func TestVersion(t *testing.T) { } } -func TestExecSupportExists(t *testing.T) { - fakeDocker := &FakeDockerClient{VersionInfo: docker.Env{"Version=1.3.0", "ApiVersion=1.15"}} - runner := &DockerManager{client: fakeDocker} - useNativeExec, err := runner.nativeExecSupportExists() - if err != nil { - t.Errorf("got error while checking for exec support - %s", err) - } - if !useNativeExec { - t.Errorf("invalid exec support check output. Expected true") - } -} - -func TestExecSupportNotExists(t *testing.T) { - fakeDocker := &FakeDockerClient{VersionInfo: docker.Env{"Version=1.1.2", "ApiVersion=1.14"}} - runner := &DockerManager{client: fakeDocker} - useNativeExec, _ := runner.nativeExecSupportExists() - if useNativeExec { - t.Errorf("invalid exec support check output.") - } -} - -func TestDockerContainerCommand(t *testing.T) { - runner := &DockerManager{} - containerID := kubecontainer.DockerID("1234").ContainerID() - command := []string{"ls"} - cmd, _ := runner.getRunInContainerCommand(containerID, command) - if cmd.Dir != "/var/lib/docker/execdriver/native/"+containerID.ID { - t.Errorf("unexpected command CWD: %s", cmd.Dir) - } - if !reflect.DeepEqual(cmd.Args, []string{"/usr/sbin/nsinit", "exec", "ls"}) { - t.Errorf("unexpected command args: %s", cmd.Args) - } -} func TestParseImageName(t *testing.T) { tests := []struct { imageName string diff --git a/pkg/kubelet/dockertools/manager.go b/pkg/kubelet/dockertools/manager.go index c88b0b6d241..3f335815c8f 100644 --- a/pkg/kubelet/dockertools/manager.go +++ b/pkg/kubelet/dockertools/manager.go @@ -60,7 +60,7 @@ import ( const ( DockerType = "docker" - minimumDockerAPIVersion = "1.18" + minimumDockerAPIVersion = "1.20" // ndots specifies the minimum number of dots that a domain name must contain for the resolver to consider it as FQDN (fully-qualified) // we want to able to consider SRV lookup names like _dns._udp.kube-dns.default.svc to be considered relative. @@ -964,21 +964,6 @@ func (dm *DockerManager) checkVersionCompatibility() error { return nil } -// The first version of docker that supports exec natively is 1.3.0 == API 1.15 -var dockerAPIVersionWithExec = "1.15" - -func (dm *DockerManager) nativeExecSupportExists() (bool, error) { - version, err := dm.APIVersion() - if err != nil { - return false, err - } - result, err := version.Compare(dockerAPIVersionWithExec) - if result >= 0 { - return true, err - } - return false, err -} - func (dm *DockerManager) defaultSecurityOpt() ([]string, error) { version, err := dm.APIVersion() if err != nil { @@ -995,32 +980,8 @@ func (dm *DockerManager) defaultSecurityOpt() ([]string, error) { return nil, nil } -func (dm *DockerManager) getRunInContainerCommand(containerID kubecontainer.ContainerID, cmd []string) (*exec.Cmd, error) { - args := append([]string{"exec"}, cmd...) - command := exec.Command("/usr/sbin/nsinit", args...) - command.Dir = fmt.Sprintf("/var/lib/docker/execdriver/native/%s", containerID.ID) - return command, nil -} - -func (dm *DockerManager) runInContainerUsingNsinit(containerID kubecontainer.ContainerID, cmd []string) ([]byte, error) { - c, err := dm.getRunInContainerCommand(containerID, cmd) - if err != nil { - return nil, err - } - return c.CombinedOutput() -} - -// RunInContainer uses nsinit to run the command inside the container identified by containerID +// RunInContainer run the command inside the container identified by containerID func (dm *DockerManager) RunInContainer(containerID kubecontainer.ContainerID, cmd []string) ([]byte, error) { - // If native exec support does not exist in the local docker daemon use nsinit. - useNativeExec, err := dm.nativeExecSupportExists() - if err != nil { - return nil, err - } - if !useNativeExec { - glog.V(2).Infof("Using nsinit to run the command %+v inside container %s", cmd, containerID) - return dm.runInContainerUsingNsinit(containerID, cmd) - } glog.V(2).Infof("Using docker native exec to run cmd %+v inside container %s", cmd, containerID) createOpts := docker.CreateExecOptions{ Container: containerID.ID,