Commit a7b07c01 authored by Ken Robertson's avatar Ken Robertson

Update container runtime to properly report the engine and version

This address a TODO when collecting the node version information so it will properly report the configured runtime and its version. Previously, this was hardcoded to "docker://" and the docker version, and would show "docker://1.9.1" even when the kubelet was configured to use rkt. With this change, it will use the runtime's Type() and Version() data. This also changes the container.Runtime interface to add an APIVersion() method. This can be used when the runtime has separate versions for the engine and the API, such as with Docker. The Docker minimum version validation has been updated to use APIVersion(), and DockerManager.Version() now returns the engine version.
parent 6504b748
...@@ -43,6 +43,7 @@ type FakeRuntime struct { ...@@ -43,6 +43,7 @@ type FakeRuntime struct {
StartedContainers []string StartedContainers []string
KilledContainers []string KilledContainers []string
VersionInfo string VersionInfo string
APIVersionInfo string
RuntimeType string RuntimeType string
Err error Err error
InspectErr error InspectErr error
...@@ -154,6 +155,14 @@ func (f *FakeRuntime) Version() (Version, error) { ...@@ -154,6 +155,14 @@ func (f *FakeRuntime) Version() (Version, error) {
return &FakeVersion{Version: f.VersionInfo}, f.Err return &FakeVersion{Version: f.VersionInfo}, f.Err
} }
func (f *FakeRuntime) APIVersion() (Version, error) {
f.Lock()
defer f.Unlock()
f.CalledFunctions = append(f.CalledFunctions, "APIVersion")
return &FakeVersion{Version: f.APIVersionInfo}, f.Err
}
func (f *FakeRuntime) GetPods(all bool) ([]*Pod, error) { func (f *FakeRuntime) GetPods(all bool) ([]*Pod, error) {
f.Lock() f.Lock()
defer f.Unlock() defer f.Unlock()
......
...@@ -82,6 +82,9 @@ type Runtime interface { ...@@ -82,6 +82,9 @@ type Runtime interface {
// Version returns the version information of the container runtime. // Version returns the version information of the container runtime.
Version() (Version, error) Version() (Version, error)
// APIVersion returns the API version information of the container
// runtime. This may be different from the runtime engine's version.
APIVersion() (Version, error)
// GetPods returns a list containers group by pods. The boolean parameter // GetPods returns a list containers group by pods. The boolean parameter
// specifies whether the runtime returns all containers including those already // specifies whether the runtime returns all containers including those already
// exited and dead containers (used for garbage collection). // exited and dead containers (used for garbage collection).
......
...@@ -47,6 +47,11 @@ func (r *Mock) Version() (Version, error) { ...@@ -47,6 +47,11 @@ func (r *Mock) Version() (Version, error) {
return args.Get(0).(Version), args.Error(1) return args.Get(0).(Version), args.Error(1)
} }
func (r *Mock) APIVersion() (Version, error) {
args := r.Called()
return args.Get(0).(Version), args.Error(1)
}
func (r *Mock) GetPods(all bool) ([]*Pod, error) { func (r *Mock) GetPods(all bool) ([]*Pod, error) {
args := r.Called(all) args := r.Called(all)
return args.Get(0).([]*Pod), args.Error(1) return args.Get(0).([]*Pod), args.Error(1)
......
...@@ -160,7 +160,16 @@ func TestVersion(t *testing.T) { ...@@ -160,7 +160,16 @@ func TestVersion(t *testing.T) {
if err != nil { if err != nil {
t.Errorf("got error while getting docker server version - %s", err) t.Errorf("got error while getting docker server version - %s", err)
} }
expectedVersion, _ := docker.NewAPIVersion("1.15") expectedVersion, _ := docker.NewAPIVersion("1.1.3")
if e, a := expectedVersion.String(), version.String(); e != a {
t.Errorf("invalid docker server version. expected: %v, got: %v", e, a)
}
version, err = manager.APIVersion()
if err != nil {
t.Errorf("got error while getting docker server version - %s", err)
}
expectedVersion, _ = docker.NewAPIVersion("1.15")
if e, a := expectedVersion.String(), version.String(); e != a { if e, a := expectedVersion.String(), version.String(); e != a {
t.Errorf("invalid docker server version. expected: %v, got: %v", e, a) t.Errorf("invalid docker server version. expected: %v, got: %v", e, a)
} }
......
...@@ -980,11 +980,26 @@ func (dm *DockerManager) Version() (kubecontainer.Version, error) { ...@@ -980,11 +980,26 @@ func (dm *DockerManager) Version() (kubecontainer.Version, error) {
return nil, fmt.Errorf("docker: failed to get docker version: %v", err) return nil, fmt.Errorf("docker: failed to get docker version: %v", err)
} }
engineVersion := env.Get("Version")
version, err := docker.NewAPIVersion(engineVersion)
if err != nil {
glog.Errorf("docker: failed to parse docker server version %q: %v", engineVersion, err)
return nil, fmt.Errorf("docker: failed to parse docker server version %q: %v", engineVersion, err)
}
return dockerVersion(version), nil
}
func (dm *DockerManager) APIVersion() (kubecontainer.Version, error) {
env, err := dm.client.Version()
if err != nil {
return nil, fmt.Errorf("docker: failed to get docker version: %v", err)
}
apiVersion := env.Get("ApiVersion") apiVersion := env.Get("ApiVersion")
version, err := docker.NewAPIVersion(apiVersion) version, err := docker.NewAPIVersion(apiVersion)
if err != nil { if err != nil {
glog.Errorf("docker: failed to parse docker server version %q: %v", apiVersion, err) glog.Errorf("docker: failed to parse docker api version %q: %v", apiVersion, err)
return nil, fmt.Errorf("docker: failed to parse docker server version %q: %v", apiVersion, err) return nil, fmt.Errorf("docker: failed to parse docker api version %q: %v", apiVersion, err)
} }
return dockerVersion(version), nil return dockerVersion(version), nil
} }
...@@ -993,7 +1008,7 @@ func (dm *DockerManager) Version() (kubecontainer.Version, error) { ...@@ -993,7 +1008,7 @@ func (dm *DockerManager) Version() (kubecontainer.Version, error) {
var dockerAPIVersionWithExec = "1.15" var dockerAPIVersionWithExec = "1.15"
func (dm *DockerManager) nativeExecSupportExists() (bool, error) { func (dm *DockerManager) nativeExecSupportExists() (bool, error) {
version, err := dm.Version() version, err := dm.APIVersion()
if err != nil { if err != nil {
return false, err return false, err
} }
......
...@@ -2438,14 +2438,6 @@ func (kl *Kubelet) LatestLoopEntryTime() time.Time { ...@@ -2438,14 +2438,6 @@ func (kl *Kubelet) LatestLoopEntryTime() time.Time {
return val.(time.Time) return val.(time.Time)
} }
// Returns the container runtime version for this Kubelet.
func (kl *Kubelet) GetContainerRuntimeVersion() (kubecontainer.Version, error) {
if kl.containerRuntime == nil {
return nil, fmt.Errorf("no container runtime")
}
return kl.containerRuntime.Version()
}
func (kl *Kubelet) validatePodPhase(podStatus *api.PodStatus) error { func (kl *Kubelet) validatePodPhase(podStatus *api.PodStatus) error {
switch podStatus.Phase { switch podStatus.Phase {
case api.PodRunning, api.PodSucceeded, api.PodFailed: case api.PodRunning, api.PodSucceeded, api.PodFailed:
...@@ -2768,8 +2760,13 @@ func (kl *Kubelet) setNodeStatusVersionInfo(node *api.Node) { ...@@ -2768,8 +2760,13 @@ func (kl *Kubelet) setNodeStatusVersionInfo(node *api.Node) {
} else { } else {
node.Status.NodeInfo.KernelVersion = verinfo.KernelVersion node.Status.NodeInfo.KernelVersion = verinfo.KernelVersion
node.Status.NodeInfo.OSImage = verinfo.ContainerOsVersion node.Status.NodeInfo.OSImage = verinfo.ContainerOsVersion
// TODO: Determine the runtime is docker or rocket
node.Status.NodeInfo.ContainerRuntimeVersion = "docker://" + verinfo.DockerVersion runtimeVersion := "Unknown"
if runtimeVer, err := kl.containerRuntime.Version(); err == nil {
runtimeVersion = runtimeVer.String()
}
node.Status.NodeInfo.ContainerRuntimeVersion = fmt.Sprintf("%s://%s", kl.containerRuntime.Type(), runtimeVersion)
node.Status.NodeInfo.KubeletVersion = version.Get().String() node.Status.NodeInfo.KubeletVersion = version.Get().String()
// TODO: kube-proxy might be different version from kubelet in the future // TODO: kube-proxy might be different version from kubelet in the future
node.Status.NodeInfo.KubeProxyVersion = version.Get().String() node.Status.NodeInfo.KubeProxyVersion = version.Get().String()
...@@ -2959,7 +2956,7 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error { ...@@ -2959,7 +2956,7 @@ func (kl *Kubelet) setNodeStatus(node *api.Node) error {
func (kl *Kubelet) isContainerRuntimeVersionCompatible() error { func (kl *Kubelet) isContainerRuntimeVersionCompatible() error {
switch kl.GetRuntime().Type() { switch kl.GetRuntime().Type() {
case "docker": case "docker":
version, err := kl.GetContainerRuntimeVersion() version, err := kl.GetRuntime().APIVersion()
if err != nil { if err != nil {
return nil return nil
} }
......
...@@ -2521,6 +2521,9 @@ func updateDiskSpacePolicy(kubelet *Kubelet, mockCadvisor *cadvisor.Mock, rootCa ...@@ -2521,6 +2521,9 @@ func updateDiskSpacePolicy(kubelet *Kubelet, mockCadvisor *cadvisor.Mock, rootCa
func TestUpdateNewNodeStatus(t *testing.T) { func TestUpdateNewNodeStatus(t *testing.T) {
testKubelet := newTestKubelet(t) testKubelet := newTestKubelet(t)
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
fakeRuntime := testKubelet.fakeRuntime
fakeRuntime.RuntimeType = "docker"
fakeRuntime.VersionInfo = "1.5.0"
kubeClient := testKubelet.fakeKubeClient kubeClient := testKubelet.fakeKubeClient
kubeClient.ReactionChain = testclient.NewSimpleFake(&api.NodeList{Items: []api.Node{ kubeClient.ReactionChain = testclient.NewSimpleFake(&api.NodeList{Items: []api.Node{
{ObjectMeta: api.ObjectMeta{Name: testKubeletHostname}}, {ObjectMeta: api.ObjectMeta{Name: testKubeletHostname}},
...@@ -2538,7 +2541,6 @@ func TestUpdateNewNodeStatus(t *testing.T) { ...@@ -2538,7 +2541,6 @@ func TestUpdateNewNodeStatus(t *testing.T) {
versionInfo := &cadvisorapi.VersionInfo{ versionInfo := &cadvisorapi.VersionInfo{
KernelVersion: "3.16.0-0.bpo.4-amd64", KernelVersion: "3.16.0-0.bpo.4-amd64",
ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)", ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)",
DockerVersion: "1.5.0",
} }
mockCadvisor.On("VersionInfo").Return(versionInfo, nil) mockCadvisor.On("VersionInfo").Return(versionInfo, nil)
...@@ -2662,7 +2664,6 @@ func TestUpdateNewNodeOutOfDiskStatusWithTransitionFrequency(t *testing.T) { ...@@ -2662,7 +2664,6 @@ func TestUpdateNewNodeOutOfDiskStatusWithTransitionFrequency(t *testing.T) {
versionInfo := &cadvisorapi.VersionInfo{ versionInfo := &cadvisorapi.VersionInfo{
KernelVersion: "3.16.0-0.bpo.4-amd64", KernelVersion: "3.16.0-0.bpo.4-amd64",
ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)", ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)",
DockerVersion: "1.5.0",
} }
mockCadvisor.On("VersionInfo").Return(versionInfo, nil) mockCadvisor.On("VersionInfo").Return(versionInfo, nil)
...@@ -2724,7 +2725,8 @@ func testDockerRuntimeVersion(t *testing.T) { ...@@ -2724,7 +2725,8 @@ func testDockerRuntimeVersion(t *testing.T) {
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
fakeRuntime := testKubelet.fakeRuntime fakeRuntime := testKubelet.fakeRuntime
fakeRuntime.RuntimeType = "docker" fakeRuntime.RuntimeType = "docker"
fakeRuntime.VersionInfo = "1.18" fakeRuntime.VersionInfo = "1.5.0"
fakeRuntime.APIVersionInfo = "1.18"
kubeClient := testKubelet.fakeKubeClient kubeClient := testKubelet.fakeKubeClient
kubeClient.ReactionChain = testclient.NewSimpleFake(&api.NodeList{Items: []api.Node{ kubeClient.ReactionChain = testclient.NewSimpleFake(&api.NodeList{Items: []api.Node{
{ObjectMeta: api.ObjectMeta{Name: testKubeletHostname}}, {ObjectMeta: api.ObjectMeta{Name: testKubeletHostname}},
...@@ -2741,7 +2743,6 @@ func testDockerRuntimeVersion(t *testing.T) { ...@@ -2741,7 +2743,6 @@ func testDockerRuntimeVersion(t *testing.T) {
versionInfo := &cadvisorapi.VersionInfo{ versionInfo := &cadvisorapi.VersionInfo{
KernelVersion: "3.16.0-0.bpo.4-amd64", KernelVersion: "3.16.0-0.bpo.4-amd64",
ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)", ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)",
DockerVersion: "1.5.0",
} }
mockCadvisor.On("VersionInfo").Return(versionInfo, nil) mockCadvisor.On("VersionInfo").Return(versionInfo, nil)
...@@ -2866,6 +2867,9 @@ func testDockerRuntimeVersion(t *testing.T) { ...@@ -2866,6 +2867,9 @@ func testDockerRuntimeVersion(t *testing.T) {
func TestUpdateExistingNodeStatus(t *testing.T) { func TestUpdateExistingNodeStatus(t *testing.T) {
testKubelet := newTestKubelet(t) testKubelet := newTestKubelet(t)
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
fakeRuntime := testKubelet.fakeRuntime
fakeRuntime.RuntimeType = "docker"
fakeRuntime.VersionInfo = "1.5.0"
kubeClient := testKubelet.fakeKubeClient kubeClient := testKubelet.fakeKubeClient
kubeClient.ReactionChain = testclient.NewSimpleFake(&api.NodeList{Items: []api.Node{ kubeClient.ReactionChain = testclient.NewSimpleFake(&api.NodeList{Items: []api.Node{
{ {
...@@ -2916,7 +2920,6 @@ func TestUpdateExistingNodeStatus(t *testing.T) { ...@@ -2916,7 +2920,6 @@ func TestUpdateExistingNodeStatus(t *testing.T) {
versionInfo := &cadvisorapi.VersionInfo{ versionInfo := &cadvisorapi.VersionInfo{
KernelVersion: "3.16.0-0.bpo.4-amd64", KernelVersion: "3.16.0-0.bpo.4-amd64",
ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)", ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)",
DockerVersion: "1.5.0",
} }
mockCadvisor.On("VersionInfo").Return(versionInfo, nil) mockCadvisor.On("VersionInfo").Return(versionInfo, nil)
...@@ -3179,10 +3182,8 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) { ...@@ -3179,10 +3182,8 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) {
kubelet := testKubelet.kubelet kubelet := testKubelet.kubelet
kubeClient := testKubelet.fakeKubeClient kubeClient := testKubelet.fakeKubeClient
fakeRuntime := testKubelet.fakeRuntime fakeRuntime := testKubelet.fakeRuntime
// This causes returning an error from GetContainerRuntimeVersion() which fakeRuntime.RuntimeType = "docker"
// simulates that container runtime is down. fakeRuntime.VersionInfo = "1.5.0"
fakeRuntime.VersionInfo = ""
kubeClient.ReactionChain = testclient.NewSimpleFake(&api.NodeList{Items: []api.Node{ kubeClient.ReactionChain = testclient.NewSimpleFake(&api.NodeList{Items: []api.Node{
{ObjectMeta: api.ObjectMeta{Name: testKubeletHostname}}, {ObjectMeta: api.ObjectMeta{Name: testKubeletHostname}},
}}).ReactionChain }}).ReactionChain
...@@ -3199,7 +3200,6 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) { ...@@ -3199,7 +3200,6 @@ func TestUpdateNodeStatusWithoutContainerRuntime(t *testing.T) {
versionInfo := &cadvisorapi.VersionInfo{ versionInfo := &cadvisorapi.VersionInfo{
KernelVersion: "3.16.0-0.bpo.4-amd64", KernelVersion: "3.16.0-0.bpo.4-amd64",
ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)", ContainerOsVersion: "Debian GNU/Linux 7 (wheezy)",
DockerVersion: "1.5.0",
} }
mockCadvisor.On("VersionInfo").Return(versionInfo, nil) mockCadvisor.On("VersionInfo").Return(versionInfo, nil)
......
...@@ -971,6 +971,10 @@ func (r *Runtime) Version() (kubecontainer.Version, error) { ...@@ -971,6 +971,10 @@ func (r *Runtime) Version() (kubecontainer.Version, error) {
return r.binVersion, nil return r.binVersion, nil
} }
func (r *Runtime) APIVersion() (kubecontainer.Version, error) {
return r.binVersion, nil
}
// SyncPod syncs the running pod to match the specified desired pod. // SyncPod syncs the running pod to match the specified desired pod.
func (r *Runtime) SyncPod(pod *api.Pod, podStatus api.PodStatus, internalPodStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) error { func (r *Runtime) SyncPod(pod *api.Pod, podStatus api.PodStatus, internalPodStatus *kubecontainer.PodStatus, pullSecrets []api.Secret, backOff *util.Backoff) error {
// TODO: (random-liu) Stop using running pod in SyncPod() // TODO: (random-liu) Stop using running pod in SyncPod()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment