Skip to content

Commit

Permalink
Merge pull request #23613 from Random-Liu/remove-out-of-date-code
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue

Kubelet: Remove nsinit related code and bump up minimum docker apiversion

Docker has native exec support after 1.3.x. We never need this code now.

As for the apiversion, because Kubernetes supports 1.8.x - 1.10.x now, we should bump up the minimum docker apiversion.
@yujuhong I checked the [changes](https://github.com/docker/engine-api/blob/master/types/versions/v1p20/types.go), we are not relying on any of those changes. So #23506 should work with docker 1.8.x+
  • Loading branch information
k8s-merge-robot committed Apr 3, 2016
2 parents 5be819b + 1459a17 commit a2145d7
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 75 deletions.
2 changes: 1 addition & 1 deletion pkg/kubelet/container/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 0 additions & 33 deletions pkg/kubelet/dockertools/docker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 2 additions & 41 deletions pkg/kubelet/dockertools/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -966,21 +966,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 {
Expand All @@ -997,32 +982,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,
Expand Down

0 comments on commit a2145d7

Please sign in to comment.