mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Remove nsinit related code and bump up minimum docker apiversion
This commit is contained in:
parent
812b9a47d6
commit
1459a17dbe
@ -103,7 +103,7 @@ type ContainerAttacher interface {
|
|||||||
// CommandRunner encapsulates the command runner interfaces for testability.
|
// CommandRunner encapsulates the command runner interfaces for testability.
|
||||||
type ContainerCommandRunner interface {
|
type ContainerCommandRunner interface {
|
||||||
// TODO(vmarmol): Merge RunInContainer and ExecInContainer.
|
// 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)
|
RunInContainer(containerID ContainerID, cmd []string) ([]byte, error)
|
||||||
// Runs the command in the container of the specified pod using nsenter.
|
// Runs the command in the container of the specified pod using nsenter.
|
||||||
// Attaches the processes stdin, stdout, and stderr. Optionally uses a
|
// Attaches the processes stdin, stdout, and stderr. Optionally uses a
|
||||||
|
@ -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) {
|
func TestParseImageName(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
imageName string
|
imageName string
|
||||||
|
@ -60,7 +60,7 @@ import (
|
|||||||
const (
|
const (
|
||||||
DockerType = "docker"
|
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)
|
// 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.
|
// 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
|
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) {
|
func (dm *DockerManager) defaultSecurityOpt() ([]string, error) {
|
||||||
version, err := dm.APIVersion()
|
version, err := dm.APIVersion()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -995,32 +980,8 @@ func (dm *DockerManager) defaultSecurityOpt() ([]string, error) {
|
|||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (dm *DockerManager) getRunInContainerCommand(containerID kubecontainer.ContainerID, cmd []string) (*exec.Cmd, error) {
|
// RunInContainer run the command inside the container identified by containerID
|
||||||
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
|
|
||||||
func (dm *DockerManager) RunInContainer(containerID kubecontainer.ContainerID, cmd []string) ([]byte, error) {
|
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)
|
glog.V(2).Infof("Using docker native exec to run cmd %+v inside container %s", cmd, containerID)
|
||||||
createOpts := docker.CreateExecOptions{
|
createOpts := docker.CreateExecOptions{
|
||||||
Container: containerID.ID,
|
Container: containerID.ID,
|
||||||
|
Loading…
Reference in New Issue
Block a user