Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert existing kubernetes system to use ContainerStatus, instead of #1335

Merged
merged 3 commits into from
Sep 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/e2e-suite/basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ while [ $ALL_RUNNING -ne 1 ]; do
ALL_RUNNING=1
for id in $POD_ID_LIST; do
CURRENT_STATUS=$($KUBECFG -template '{{and .CurrentState.Info.mynginx.State.Running .CurrentState.Info.net.State.Running}}' get pods/$id)
if [ "$CURRENT_STATUS" != "true" ]; then
if [ "$CURRENT_STATUS" != "{}" ]; then
ALL_RUNNING=0
fi
done
Expand Down
4 changes: 2 additions & 2 deletions hack/e2e-suite/update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ function validate() {
for id in $POD_ID_LIST; do
TEMPLATE_STRING="{{and ((index .CurrentState.Info \"${CONTROLLER_NAME}\").State.Running) .CurrentState.Info.net.State.Running}}"
CURRENT_STATUS=$($KUBECFG -template "${TEMPLATE_STRING}" get pods/$id)
if [ "$CURRENT_STATUS" != "true" ]; then
if [ "$CURRENT_STATUS" != "{}" ]; then
ALL_RUNNING=0
else
CURRENT_IMAGE=$($KUBECFG -template "{{(index .CurrentState.Info \"${CONTROLLER_NAME}\").Config.Image}}" get pods/$id)
CURRENT_IMAGE=$($KUBECFG -template "{{(index .CurrentState.Info \"${CONTROLLER_NAME}\").DetailInfo.Config.Image}}" get pods/$id)
if [ "$CURRENT_IMAGE" != "${DOCKER_HUB_USER}/update-demo:${CONTAINER_IMAGE_VERSION}" ]; then
ALL_RUNNING=0
fi
Expand Down
3 changes: 1 addition & 2 deletions pkg/api/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,7 @@ type ContainerStatus struct {
}

// PodInfo contains one entry for every container with available info.
// TODO(dchen1107): Replace docker.Container below with ContainerStatus defined above.
type PodInfo map[string]docker.Container
type PodInfo map[string]ContainerStatus

type RestartPolicyAlways struct{}

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ type ContainerStatus struct {
}

// PodInfo contains one entry for every container with available info.
type PodInfo map[string]docker.Container
type PodInfo map[string]ContainerStatus

type RestartPolicyAlways struct{}

Expand Down
2 changes: 1 addition & 1 deletion pkg/api/v1beta2/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ type ContainerStatus struct {

// PodInfo contains one entry for every container with available info.
// TODO(dchen1107): Replace docker.Container below with ContainerStatus defined above.
type PodInfo map[string]docker.Container
type PodInfo map[string]ContainerStatus

type RestartPolicyAlways struct{}

Expand Down
11 changes: 8 additions & 3 deletions pkg/client/podinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ import (

func TestHTTPPodInfoGetter(t *testing.T) {
expectObj := api.PodInfo{
"myID": docker.Container{ID: "myID"},
"myID": api.ContainerStatus{
DetailInfo: docker.Container{ID: "myID"},
},
}
body, err := json.Marshal(expectObj)
if err != nil {
Expand Down Expand Up @@ -67,14 +69,17 @@ func TestHTTPPodInfoGetter(t *testing.T) {
}

// reflect.DeepEqual(expectObj, gotObj) doesn't handle blank times well
if len(gotObj) != len(expectObj) || expectObj["myID"].ID != gotObj["myID"].ID {
if len(gotObj) != len(expectObj) ||
expectObj["myID"].DetailInfo.ID != gotObj["myID"].DetailInfo.ID {
t.Errorf("Unexpected response. Expected: %#v, received %#v", expectObj, gotObj)
}
}

func TestHTTPPodInfoGetterNotFound(t *testing.T) {
expectObj := api.PodInfo{
"myID": docker.Container{ID: "myID"},
"myID": api.ContainerStatus{
DetailInfo: docker.Container{ID: "myID"},
},
}
_, err := json.Marshal(expectObj)
if err != nil {
Expand Down
30 changes: 23 additions & 7 deletions pkg/kubelet/dockertools/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,25 @@ func GetKubeletDockerContainerLogs(client DockerInterface, containerID, tail str
return
}

func generateContainerStatus(inspectResult *docker.Container) api.ContainerStatus {
if inspectResult == nil {
// Why did we not get an error?
return api.ContainerStatus{}
}

var containerStatus api.ContainerStatus

if inspectResult.State.Running {
containerStatus.State.Running = &api.ContainerStateRunning{}
} else {
containerStatus.State.Termination = &api.ContainerStateTerminated{
ExitCode: inspectResult.State.ExitCode,
}
}
containerStatus.DetailInfo = *inspectResult
return containerStatus
}

// ErrNoContainersInPod is returned when there are no containers for a given pod
var ErrNoContainersInPod = errors.New("no containers exist for this pod")

Expand All @@ -249,20 +268,17 @@ func GetDockerPodInfo(client DockerInterface, podFullName, uuid string) (api.Pod
continue
}
// We assume docker return us a list of containers in time order
if _, ok := info[dockerContainerName]; ok {
if containerStatus, found := info[dockerContainerName]; found {
containerStatus.RestartCount += 1
info[dockerContainerName] = containerStatus
continue
}

inspectResult, err := client.InspectContainer(value.ID)
if err != nil {
return nil, err
}
if inspectResult == nil {
// Why did we not get an error?
info[dockerContainerName] = docker.Container{}
} else {
info[dockerContainerName] = *inspectResult
}
info[dockerContainerName] = generateContainerStatus(inspectResult)
}
if len(info) == 0 {
return nil, ErrNoContainersInPod
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ func (h *httpActionHandler) Run(podFullName, uuid string, container *api.Contain
return err
}
netInfo, found := info[networkContainerName]
if found && netInfo.NetworkSettings != nil {
host = netInfo.NetworkSettings.IPAddress
if found && netInfo.DetailInfo.NetworkSettings != nil {
host = netInfo.DetailInfo.NetworkSettings.IPAddress
} else {
return fmt.Errorf("failed to find networking container: %v", info)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/kubelet/kubelet.go
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,8 @@ func (kl *Kubelet) syncPod(pod *Pod, dockerContainers dockertools.DockerContaine
podFullName, uuid)
}
netInfo, found := info[networkContainerName]
if found && netInfo.NetworkSettings != nil {
podState.PodIP = netInfo.NetworkSettings.IPAddress
if found && netInfo.DetailInfo.NetworkSettings != nil {
podState.PodIP = netInfo.DetailInfo.NetworkSettings.IPAddress
}

for _, container := range pod.Manifest.Containers {
Expand Down
6 changes: 5 additions & 1 deletion pkg/kubelet/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,11 @@ func TestContainers(t *testing.T) {

func TestPodInfo(t *testing.T) {
fw := newServerTest()
expected := api.PodInfo{"goodpod": docker.Container{ID: "myContainerID"}}
expected := api.PodInfo{
"goodpod": api.ContainerStatus{
DetailInfo: docker.Container{ID: "myContainerID"},
},
}
fw.fakeKubelet.infoFunc = func(name string) (api.PodInfo, error) {
if name == "goodpod.etcd" {
return expected, nil
Expand Down
18 changes: 15 additions & 3 deletions pkg/master/pod_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@ func (f *FakePodInfoGetter) GetPodInfo(host, id string) (api.PodInfo, error) {
func TestPodCacheGet(t *testing.T) {
cache := NewPodCache(nil, nil)

expected := api.PodInfo{"foo": docker.Container{ID: "foo"}}
expected := api.PodInfo{
"foo": api.ContainerStatus{
DetailInfo: docker.Container{ID: "foo"},
},
}
cache.podInfo["foo"] = expected

info, err := cache.GetPodInfo("host", "foo")
Expand All @@ -66,7 +70,11 @@ func TestPodCacheGetMissing(t *testing.T) {
}

func TestPodGetPodInfoGetter(t *testing.T) {
expected := api.PodInfo{"foo": docker.Container{ID: "foo"}}
expected := api.PodInfo{
"foo": api.ContainerStatus{
DetailInfo: docker.Container{ID: "foo"},
},
}
fake := FakePodInfoGetter{
data: expected,
}
Expand Down Expand Up @@ -98,7 +106,11 @@ func TestPodUpdateAllContainers(t *testing.T) {
pods := []api.Pod{pod}
mockRegistry := registrytest.NewPodRegistry(&api.PodList{Items: pods})

expected := api.PodInfo{"foo": docker.Container{ID: "foo"}}
expected := api.PodInfo{
"foo": api.ContainerStatus{
DetailInfo: docker.Container{ID: "foo"},
},
}
fake := FakePodInfoGetter{
data: expected,
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/registry/pod/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ func (rs *REST) fillPodInfo(pod *api.Pod) {
pod.CurrentState.Info = info
netContainerInfo, ok := info["net"]
if ok {
if netContainerInfo.NetworkSettings != nil {
pod.CurrentState.PodIP = netContainerInfo.NetworkSettings.IPAddress
if netContainerInfo.DetailInfo.NetworkSettings != nil {
pod.CurrentState.PodIP = netContainerInfo.DetailInfo.NetworkSettings.IPAddress
} else {
glog.Warningf("No network settings: %#v", netContainerInfo)
}
Expand Down Expand Up @@ -253,11 +253,13 @@ func getPodStatus(pod *api.Pod, minions client.MinionInterface) (api.PodStatus,
stopped := 0
unknown := 0
for _, container := range pod.DesiredState.Manifest.Containers {
if info, ok := pod.CurrentState.Info[container.Name]; ok {
if info.State.Running {
if containerStatus, ok := pod.CurrentState.Info[container.Name]; ok {
if containerStatus.State.Running != nil {
running++
} else {
} else if containerStatus.State.Termination != nil {
stopped++
} else {
unknown++
}
} else {
unknown++
Expand Down
53 changes: 25 additions & 28 deletions pkg/registry/pod/rest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,14 +360,14 @@ func TestMakePodStatus(t *testing.T) {
currentState := api.PodState{
Host: "machine",
}
runningState := docker.Container{
State: docker.State{
Running: true,
runningState := api.ContainerStatus{
State: api.ContainerState{
Running: &api.ContainerStateRunning{},
},
}
stoppedState := docker.Container{
State: docker.State{
Running: false,
stoppedState := api.ContainerStatus{
State: api.ContainerState{
Termination: &api.ContainerStateTerminated{},
},
}

Expand All @@ -376,14 +376,7 @@ func TestMakePodStatus(t *testing.T) {
status api.PodStatus
test string
}{
{
&api.Pod{
DesiredState: desiredState,
CurrentState: currentState,
},
api.PodWaiting,
"waiting",
},
{&api.Pod{DesiredState: desiredState, CurrentState: currentState}, api.PodWaiting, "waiting"},
{
&api.Pod{
DesiredState: desiredState,
Expand All @@ -398,7 +391,7 @@ func TestMakePodStatus(t *testing.T) {
&api.Pod{
DesiredState: desiredState,
CurrentState: api.PodState{
Info: map[string]docker.Container{
Info: map[string]api.ContainerStatus{
"containerA": runningState,
"containerB": runningState,
},
Expand All @@ -412,7 +405,7 @@ func TestMakePodStatus(t *testing.T) {
&api.Pod{
DesiredState: desiredState,
CurrentState: api.PodState{
Info: map[string]docker.Container{
Info: map[string]api.ContainerStatus{
"containerA": runningState,
"containerB": runningState,
},
Expand All @@ -426,7 +419,7 @@ func TestMakePodStatus(t *testing.T) {
&api.Pod{
DesiredState: desiredState,
CurrentState: api.PodState{
Info: map[string]docker.Container{
Info: map[string]api.ContainerStatus{
"containerA": stoppedState,
"containerB": stoppedState,
},
Expand All @@ -440,7 +433,7 @@ func TestMakePodStatus(t *testing.T) {
&api.Pod{
DesiredState: desiredState,
CurrentState: api.PodState{
Info: map[string]docker.Container{
Info: map[string]api.ContainerStatus{
"containerA": stoppedState,
"containerB": stoppedState,
},
Expand All @@ -454,7 +447,7 @@ func TestMakePodStatus(t *testing.T) {
&api.Pod{
DesiredState: desiredState,
CurrentState: api.PodState{
Info: map[string]docker.Container{
Info: map[string]api.ContainerStatus{
"containerA": runningState,
"containerB": stoppedState,
},
Expand All @@ -468,7 +461,7 @@ func TestMakePodStatus(t *testing.T) {
&api.Pod{
DesiredState: desiredState,
CurrentState: api.PodState{
Info: map[string]docker.Container{
Info: map[string]api.ContainerStatus{
"containerA": runningState,
},
Host: "machine",
Expand Down Expand Up @@ -566,12 +559,14 @@ func (f *FakePodInfoGetter) GetPodInfo(host, podID string) (api.PodInfo, error)
func TestFillPodInfo(t *testing.T) {
expectedIP := "1.2.3.4"
fakeGetter := FakePodInfoGetter{
info: map[string]docker.Container{
info: map[string]api.ContainerStatus{
"net": {
ID: "foobar",
Path: "bin/run.sh",
NetworkSettings: &docker.NetworkSettings{
IPAddress: expectedIP,
DetailInfo: docker.Container{
ID: "foobar",
Path: "bin/run.sh",
NetworkSettings: &docker.NetworkSettings{
IPAddress: expectedIP,
},
},
},
},
Expand All @@ -592,10 +587,12 @@ func TestFillPodInfo(t *testing.T) {
func TestFillPodInfoNoData(t *testing.T) {
expectedIP := ""
fakeGetter := FakePodInfoGetter{
info: map[string]docker.Container{
info: map[string]api.ContainerStatus{
"net": {
ID: "foobar",
Path: "bin/run.sh",
DetailInfo: docker.Container{
ID: "foobar",
Path: "bin/run.sh",
},
},
},
}
Expand Down