mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-10 13:42:02 +00:00
Merge pull request #1335 from dchen1107/exit1
Convert existing kubernetes system to use ContainerStatus, instead of
This commit is contained in:
@@ -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)
|
||||
}
|
||||
@@ -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++
|
||||
|
@@ -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{},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
@@ -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,
|
||||
},
|
||||
@@ -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,
|
||||
},
|
||||
@@ -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,
|
||||
},
|
||||
@@ -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,
|
||||
},
|
||||
@@ -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,
|
||||
},
|
||||
@@ -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",
|
||||
@@ -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,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -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",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
Reference in New Issue
Block a user