From 89feb6fc531c0ee24a560ac95a4541247fc4db23 Mon Sep 17 00:00:00 2001 From: Yifan Gu Date: Fri, 18 Mar 2016 11:43:20 -0700 Subject: [PATCH] rkt: Append tag to the returned image name. --- pkg/kubelet/container/runtime.go | 6 ++++-- pkg/kubelet/rkt/rkt.go | 15 ++++++++------- pkg/kubelet/rkt/rkt_test.go | 33 ++++++++++++++++---------------- 3 files changed, 29 insertions(+), 25 deletions(-) diff --git a/pkg/kubelet/container/runtime.go b/pkg/kubelet/container/runtime.go index 6cdfa3290ef..9bb5b940b23 100644 --- a/pkg/kubelet/container/runtime.go +++ b/pkg/kubelet/container/runtime.go @@ -218,7 +218,8 @@ type Container struct { // The name of the container, which should be the same as specified by // api.Container. Name string - // The image name of the container. + // The image name of the container, this also includes the tag of the image, + // the expected form is "NAME:TAG". Image string // Hash of the container, used for comparison. Optional for containers // not managed by kubelet. @@ -261,7 +262,8 @@ type ContainerStatus struct { FinishedAt time.Time // Exit code of the container. ExitCode int - // Name of the image. + // Name of the image, this also includes the tag of the image, + // the expected form is "NAME:TAG". Image string // ID of the image. ImageID string diff --git a/pkg/kubelet/rkt/rkt.go b/pkg/kubelet/rkt/rkt.go index ce8dea71dec..5268c9f40f9 100644 --- a/pkg/kubelet/rkt/rkt.go +++ b/pkg/kubelet/rkt/rkt.go @@ -85,7 +85,6 @@ const ( authDir = "auth.d" dockerAuthTemplate = `{"rktKind":"dockerAuth","rktVersion":"v1","registries":[%q],"credentials":{"user":%q,"password":%q}}` - defaultImageTag = "latest" defaultRktAPIServiceAddr = "localhost:15441" defaultNetworkName = "rkt.kubernetes.io" @@ -982,9 +981,10 @@ func (r *Runtime) convertRktPod(rktpod *rktapi.Pod) (*kubecontainer.Pod, error) } kubepod.Containers = append(kubepod.Containers, &kubecontainer.Container{ - ID: buildContainerID(&containerID{rktpod.Id, app.Name}), - Name: app.Name, - Image: app.Image.Name, + ID: buildContainerID(&containerID{rktpod.Id, app.Name}), + Name: app.Name, + // By default, the version returned by rkt API service will be "latest" if not specified. + Image: fmt.Sprintf("%s:%s", app.Image.Name, app.Image.Version), Hash: containerHash, Created: podCreated, State: appStateToContainerState(app.State), @@ -1459,9 +1459,10 @@ func populateContainerStatus(pod rktapi.Pod, app rktapi.App, runtimeApp appcsche CreatedAt: creationTime, StartedAt: creationTime, ExitCode: int(app.ExitCode), - Image: app.Image.Name, - ImageID: "rkt://" + app.Image.Id, // TODO(yifan): Add the prefix only in api.PodStatus. - Hash: hashNum, + // By default, the version returned by rkt API service will be "latest" if not specified. + Image: fmt.Sprintf("%s:%s", app.Image.Name, app.Image.Version), + ImageID: "rkt://" + app.Image.Id, // TODO(yifan): Add the prefix only in api.PodStatus. + Hash: hashNum, // TODO(yifan): Note that now all apps share the same restart count, this might // change once apps don't share the same lifecycle. // See https://github.com/appc/spec/pull/547. diff --git a/pkg/kubelet/rkt/rkt_test.go b/pkg/kubelet/rkt/rkt_test.go index 0aaf22084df..006c07a33b4 100644 --- a/pkg/kubelet/rkt/rkt_test.go +++ b/pkg/kubelet/rkt/rkt_test.go @@ -109,8 +109,9 @@ func makeRktPod(rktPodState rktapi.PodState, Name: appNames[i], State: appStates[i], Image: &rktapi.Image{ - Id: imgIDs[i], - Name: imgNames[i], + Id: imgIDs[i], + Name: imgNames[i], + Version: "latest", Manifest: mustMarshalImageManifest( &appcschema.ImageManifest{ ACKind: appcschema.ImageManifestKind, @@ -372,7 +373,7 @@ func TestGetPods(t *testing.T) { { ID: kubecontainer.BuildContainerID("rkt", "uuid-4002:app-1"), Name: "app-1", - Image: "img-name-1", + Image: "img-name-1:latest", Hash: 1001, Created: 100000, State: "running", @@ -380,7 +381,7 @@ func TestGetPods(t *testing.T) { { ID: kubecontainer.BuildContainerID("rkt", "uuid-4002:app-2"), Name: "app-2", - Image: "img-name-2", + Image: "img-name-2:latest", Hash: 1002, Created: 100000, State: "exited", @@ -432,7 +433,7 @@ func TestGetPods(t *testing.T) { { ID: kubecontainer.BuildContainerID("rkt", "uuid-4002:app-1"), Name: "app-1", - Image: "img-name-1", + Image: "img-name-1:latest", Hash: 1001, Created: 100000, State: "running", @@ -440,7 +441,7 @@ func TestGetPods(t *testing.T) { { ID: kubecontainer.BuildContainerID("rkt", "uuid-4002:app-2"), Name: "app-2", - Image: "img-name-2", + Image: "img-name-2:latest", Hash: 1002, Created: 100000, State: "exited", @@ -455,7 +456,7 @@ func TestGetPods(t *testing.T) { { ID: kubecontainer.BuildContainerID("rkt", "uuid-4003:app-11"), Name: "app-11", - Image: "img-name-11", + Image: "img-name-11:latest", Hash: 10011, Created: 90000, State: "exited", @@ -463,7 +464,7 @@ func TestGetPods(t *testing.T) { { ID: kubecontainer.BuildContainerID("rkt", "uuid-4003:app-22"), Name: "app-22", - Image: "img-name-22", + Image: "img-name-22:latest", Hash: 10022, Created: 90000, State: "exited", @@ -471,7 +472,7 @@ func TestGetPods(t *testing.T) { { ID: kubecontainer.BuildContainerID("rkt", "uuid-4004:app-11"), Name: "app-11", - Image: "img-name-11", + Image: "img-name-11:latest", Hash: 10011, Created: 100000, State: "running", @@ -479,7 +480,7 @@ func TestGetPods(t *testing.T) { { ID: kubecontainer.BuildContainerID("rkt", "uuid-4004:app-22"), Name: "app-22", - Image: "img-name-22", + Image: "img-name-22:latest", Hash: 10022, Created: 100000, State: "running", @@ -591,7 +592,7 @@ func TestGetPodStatus(t *testing.T) { State: kubecontainer.ContainerStateRunning, CreatedAt: time.Unix(100000, 0), StartedAt: time.Unix(100000, 0), - Image: "img-name-1", + Image: "img-name-1:latest", ImageID: "rkt://img-id-1", Hash: 1001, RestartCount: 7, @@ -602,7 +603,7 @@ func TestGetPodStatus(t *testing.T) { State: kubecontainer.ContainerStateExited, CreatedAt: time.Unix(100000, 0), StartedAt: time.Unix(100000, 0), - Image: "img-name-2", + Image: "img-name-2:latest", ImageID: "rkt://img-id-2", Hash: 1002, RestartCount: 7, @@ -648,7 +649,7 @@ func TestGetPodStatus(t *testing.T) { State: kubecontainer.ContainerStateRunning, CreatedAt: time.Unix(90000, 0), StartedAt: time.Unix(90000, 0), - Image: "img-name-1", + Image: "img-name-1:latest", ImageID: "rkt://img-id-1", Hash: 1001, RestartCount: 7, @@ -659,7 +660,7 @@ func TestGetPodStatus(t *testing.T) { State: kubecontainer.ContainerStateExited, CreatedAt: time.Unix(90000, 0), StartedAt: time.Unix(90000, 0), - Image: "img-name-2", + Image: "img-name-2:latest", ImageID: "rkt://img-id-2", Hash: 1002, RestartCount: 7, @@ -671,7 +672,7 @@ func TestGetPodStatus(t *testing.T) { State: kubecontainer.ContainerStateRunning, CreatedAt: time.Unix(100000, 0), StartedAt: time.Unix(100000, 0), - Image: "img-name-1", + Image: "img-name-1:latest", ImageID: "rkt://img-id-1", Hash: 1001, RestartCount: 10, @@ -682,7 +683,7 @@ func TestGetPodStatus(t *testing.T) { State: kubecontainer.ContainerStateExited, CreatedAt: time.Unix(100000, 0), StartedAt: time.Unix(100000, 0), - Image: "img-name-2", + Image: "img-name-2:latest", ImageID: "rkt://img-id-2", Hash: 1002, RestartCount: 10,