Commit ecfde2b8 authored by Kubernetes Submit Queue's avatar Kubernetes Submit Queue Committed by GitHub

Merge pull request #35998 from yujuhong/fix_enum

Automatic merge from submit-queue CRI: Rename container/sandbox states The enum constants are not namespaced. The shorter, unspecifc names are likely to cause naming conflicts in the future. Also replace "SandBox" with "Sandbox" in the API for consistency. /cc @kubernetes/sig-node
parents 3d33b45e 8a6285d8
...@@ -119,7 +119,7 @@ func (r *FakeRuntimeService) RunPodSandbox(config *runtimeApi.PodSandboxConfig) ...@@ -119,7 +119,7 @@ func (r *FakeRuntimeService) RunPodSandbox(config *runtimeApi.PodSandboxConfig)
// fixed name from BuildSandboxName() for easily making fake sandboxes. // fixed name from BuildSandboxName() for easily making fake sandboxes.
podSandboxID := BuildSandboxName(config.Metadata) podSandboxID := BuildSandboxName(config.Metadata)
createdAt := time.Now().Unix() createdAt := time.Now().Unix()
readyState := runtimeApi.PodSandBoxState_READY readyState := runtimeApi.PodSandboxState_SANDBOX_READY
r.Sandboxes[podSandboxID] = &FakePodSandbox{ r.Sandboxes[podSandboxID] = &FakePodSandbox{
PodSandboxStatus: runtimeApi.PodSandboxStatus{ PodSandboxStatus: runtimeApi.PodSandboxStatus{
Id: &podSandboxID, Id: &podSandboxID,
...@@ -143,7 +143,7 @@ func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error { ...@@ -143,7 +143,7 @@ func (r *FakeRuntimeService) StopPodSandbox(podSandboxID string) error {
r.Called = append(r.Called, "StopPodSandbox") r.Called = append(r.Called, "StopPodSandbox")
notReadyState := runtimeApi.PodSandBoxState_NOTREADY notReadyState := runtimeApi.PodSandboxState_SANDBOX_NOTREADY
if s, ok := r.Sandboxes[podSandboxID]; ok { if s, ok := r.Sandboxes[podSandboxID]; ok {
s.State = &notReadyState s.State = &notReadyState
} else { } else {
...@@ -231,7 +231,7 @@ func (r *FakeRuntimeService) CreateContainer(podSandboxID string, config *runtim ...@@ -231,7 +231,7 @@ func (r *FakeRuntimeService) CreateContainer(podSandboxID string, config *runtim
// fixed BuildContainerName() for easily making fake containers. // fixed BuildContainerName() for easily making fake containers.
containerID := BuildContainerName(config.Metadata, podSandboxID) containerID := BuildContainerName(config.Metadata, podSandboxID)
createdAt := time.Now().Unix() createdAt := time.Now().Unix()
createdState := runtimeApi.ContainerState_CREATED createdState := runtimeApi.ContainerState_CONTAINER_CREATED
imageRef := config.Image.GetImage() imageRef := config.Image.GetImage()
r.Containers[containerID] = &FakeContainer{ r.Containers[containerID] = &FakeContainer{
ContainerStatus: runtimeApi.ContainerStatus{ ContainerStatus: runtimeApi.ContainerStatus{
...@@ -263,7 +263,7 @@ func (r *FakeRuntimeService) StartContainer(containerID string) error { ...@@ -263,7 +263,7 @@ func (r *FakeRuntimeService) StartContainer(containerID string) error {
// Set container to running. // Set container to running.
startedAt := time.Now().Unix() startedAt := time.Now().Unix()
runningState := runtimeApi.ContainerState_RUNNING runningState := runtimeApi.ContainerState_CONTAINER_RUNNING
c.State = &runningState c.State = &runningState
c.StartedAt = &startedAt c.StartedAt = &startedAt
...@@ -283,7 +283,7 @@ func (r *FakeRuntimeService) StopContainer(containerID string, timeout int64) er ...@@ -283,7 +283,7 @@ func (r *FakeRuntimeService) StopContainer(containerID string, timeout int64) er
// Set container to exited state. // Set container to exited state.
finishedAt := time.Now().Unix() finishedAt := time.Now().Unix()
exitedState := runtimeApi.ContainerState_EXITED exitedState := runtimeApi.ContainerState_CONTAINER_EXITED
c.State = &exitedState c.State = &exitedState
c.FinishedAt = &finishedAt c.FinishedAt = &finishedAt
......
...@@ -20,7 +20,7 @@ service RuntimeService { ...@@ -20,7 +20,7 @@ service RuntimeService {
rpc RemovePodSandbox(RemovePodSandboxRequest) returns (RemovePodSandboxResponse) {} rpc RemovePodSandbox(RemovePodSandboxRequest) returns (RemovePodSandboxResponse) {}
// PodSandboxStatus returns the status of the PodSandbox. // PodSandboxStatus returns the status of the PodSandbox.
rpc PodSandboxStatus(PodSandboxStatusRequest) returns (PodSandboxStatusResponse) {} rpc PodSandboxStatus(PodSandboxStatusRequest) returns (PodSandboxStatusResponse) {}
// ListPodSandbox returns a list of SandBox. // ListPodSandbox returns a list of Sandbox.
rpc ListPodSandbox(ListPodSandboxRequest) returns (ListPodSandboxResponse) {} rpc ListPodSandbox(ListPodSandboxRequest) returns (ListPodSandboxResponse) {}
// CreateContainer creates a new container in specified PodSandbox // CreateContainer creates a new container in specified PodSandbox
...@@ -270,15 +270,15 @@ message Namespace { ...@@ -270,15 +270,15 @@ message Namespace {
optional NamespaceOption options = 2; optional NamespaceOption options = 2;
} }
// LinuxSandBoxStatus contains status specific to Linux sandboxes. // LinuxSandboxStatus contains status specific to Linux sandboxes.
message LinuxPodSandboxStatus { message LinuxPodSandboxStatus {
// Namespaces contains paths to the sandbox's namespaces. // Namespaces contains paths to the sandbox's namespaces.
optional Namespace namespaces = 1; optional Namespace namespaces = 1;
} }
enum PodSandBoxState { enum PodSandboxState {
READY = 0; SANDBOX_READY = 0;
NOTREADY = 1; SANDBOX_NOTREADY = 1;
} }
// PodSandboxStatus contains the status of the PodSandbox. // PodSandboxStatus contains the status of the PodSandbox.
...@@ -288,7 +288,7 @@ message PodSandboxStatus { ...@@ -288,7 +288,7 @@ message PodSandboxStatus {
// Metadata of the sandbox. // Metadata of the sandbox.
optional PodSandboxMetadata metadata = 2; optional PodSandboxMetadata metadata = 2;
// State of the sandbox. // State of the sandbox.
optional PodSandBoxState state = 3; optional PodSandboxState state = 3;
// Creation timestamp of the sandbox in nanoseconds. // Creation timestamp of the sandbox in nanoseconds.
optional int64 created_at = 4; optional int64 created_at = 4;
// Network contains network status if network is handled by the runtime. // Network contains network status if network is handled by the runtime.
...@@ -313,7 +313,7 @@ message PodSandboxFilter { ...@@ -313,7 +313,7 @@ message PodSandboxFilter {
// ID of the sandbox. // ID of the sandbox.
optional string id = 1; optional string id = 1;
// State of the sandbox. // State of the sandbox.
optional PodSandBoxState state = 2; optional PodSandboxState state = 2;
// LabelSelector to select matches. // LabelSelector to select matches.
// Only api.MatchLabels is supported for now and the requirements // Only api.MatchLabels is supported for now and the requirements
// are ANDed. MatchExpressions is not supported yet. // are ANDed. MatchExpressions is not supported yet.
...@@ -333,7 +333,7 @@ message PodSandbox { ...@@ -333,7 +333,7 @@ message PodSandbox {
// Metadata of the sandbox // Metadata of the sandbox
optional PodSandboxMetadata metadata = 2; optional PodSandboxMetadata metadata = 2;
// The state of the PodSandbox // The state of the PodSandbox
optional PodSandBoxState state = 3; optional PodSandboxState state = 3;
// Creation timestamps of the sandbox in nanoseconds // Creation timestamps of the sandbox in nanoseconds
optional int64 created_at = 4; optional int64 created_at = 4;
// The labels of the PodSandbox // The labels of the PodSandbox
...@@ -529,10 +529,10 @@ message RemoveContainerRequest { ...@@ -529,10 +529,10 @@ message RemoveContainerRequest {
message RemoveContainerResponse {} message RemoveContainerResponse {}
enum ContainerState { enum ContainerState {
CREATED = 0; CONTAINER_CREATED = 0;
RUNNING = 1; CONTAINER_RUNNING = 1;
EXITED = 2; CONTAINER_EXITED = 2;
UNKNOWN = 3; CONTAINER_UNKNOWN = 3;
} }
// ContainerFilter is used to filter containers. // ContainerFilter is used to filter containers.
......
...@@ -206,11 +206,11 @@ func ConvertPodStatusToRunningPod(runtimeName string, podStatus *PodStatus) Pod ...@@ -206,11 +206,11 @@ func ConvertPodStatusToRunningPod(runtimeName string, podStatus *PodStatus) Pod
// This is only needed because we need to return sandboxes as if they were // This is only needed because we need to return sandboxes as if they were
// kubecontainer.Containers to avoid substantial changes to PLEG. // kubecontainer.Containers to avoid substantial changes to PLEG.
// TODO: Remove this once it becomes obsolete. // TODO: Remove this once it becomes obsolete.
func SandboxToContainerState(state runtimeApi.PodSandBoxState) ContainerState { func SandboxToContainerState(state runtimeApi.PodSandboxState) ContainerState {
switch state { switch state {
case runtimeApi.PodSandBoxState_READY: case runtimeApi.PodSandboxState_SANDBOX_READY:
return ContainerStateRunning return ContainerStateRunning
case runtimeApi.PodSandBoxState_NOTREADY: case runtimeApi.PodSandboxState_SANDBOX_NOTREADY:
return ContainerStateExited return ContainerStateExited
} }
return ContainerStateUnknown return ContainerStateUnknown
......
...@@ -100,13 +100,13 @@ func toRuntimeAPIContainer(c *dockertypes.Container) (*runtimeApi.Container, err ...@@ -100,13 +100,13 @@ func toRuntimeAPIContainer(c *dockertypes.Container) (*runtimeApi.Container, err
func toDockerContainerStatus(state runtimeApi.ContainerState) string { func toDockerContainerStatus(state runtimeApi.ContainerState) string {
switch state { switch state {
case runtimeApi.ContainerState_CREATED: case runtimeApi.ContainerState_CONTAINER_CREATED:
return "created" return "created"
case runtimeApi.ContainerState_RUNNING: case runtimeApi.ContainerState_CONTAINER_RUNNING:
return "running" return "running"
case runtimeApi.ContainerState_EXITED: case runtimeApi.ContainerState_CONTAINER_EXITED:
return "exited" return "exited"
case runtimeApi.ContainerState_UNKNOWN: case runtimeApi.ContainerState_CONTAINER_UNKNOWN:
fallthrough fallthrough
default: default:
return "unknown" return "unknown"
...@@ -118,24 +118,24 @@ func toRuntimeAPIContainerState(state string) runtimeApi.ContainerState { ...@@ -118,24 +118,24 @@ func toRuntimeAPIContainerState(state string) runtimeApi.ContainerState {
// we upgrade docker. // we upgrade docker.
switch { switch {
case strings.HasPrefix(state, statusRunningPrefix): case strings.HasPrefix(state, statusRunningPrefix):
return runtimeApi.ContainerState_RUNNING return runtimeApi.ContainerState_CONTAINER_RUNNING
case strings.HasPrefix(state, statusExitedPrefix): case strings.HasPrefix(state, statusExitedPrefix):
return runtimeApi.ContainerState_EXITED return runtimeApi.ContainerState_CONTAINER_EXITED
case strings.HasPrefix(state, statusCreatedPrefix): case strings.HasPrefix(state, statusCreatedPrefix):
return runtimeApi.ContainerState_CREATED return runtimeApi.ContainerState_CONTAINER_CREATED
default: default:
return runtimeApi.ContainerState_UNKNOWN return runtimeApi.ContainerState_CONTAINER_UNKNOWN
} }
} }
func toRuntimeAPISandboxState(state string) runtimeApi.PodSandBoxState { func toRuntimeAPISandboxState(state string) runtimeApi.PodSandboxState {
// Parse the state string in dockertypes.Container. This could break when // Parse the state string in dockertypes.Container. This could break when
// we upgrade docker. // we upgrade docker.
switch { switch {
case strings.HasPrefix(state, statusRunningPrefix): case strings.HasPrefix(state, statusRunningPrefix):
return runtimeApi.PodSandBoxState_READY return runtimeApi.PodSandboxState_SANDBOX_READY
default: default:
return runtimeApi.PodSandBoxState_NOTREADY return runtimeApi.PodSandboxState_SANDBOX_NOTREADY
} }
} }
......
...@@ -30,10 +30,10 @@ func TestConvertDockerStatusToRuntimeAPIState(t *testing.T) { ...@@ -30,10 +30,10 @@ func TestConvertDockerStatusToRuntimeAPIState(t *testing.T) {
input string input string
expected runtimeApi.ContainerState expected runtimeApi.ContainerState
}{ }{
{input: "Up 5 hours", expected: runtimeApi.ContainerState_RUNNING}, {input: "Up 5 hours", expected: runtimeApi.ContainerState_CONTAINER_RUNNING},
{input: "Exited (0) 2 hours ago", expected: runtimeApi.ContainerState_EXITED}, {input: "Exited (0) 2 hours ago", expected: runtimeApi.ContainerState_CONTAINER_EXITED},
{input: "Created", expected: runtimeApi.ContainerState_CREATED}, {input: "Created", expected: runtimeApi.ContainerState_CONTAINER_CREATED},
{input: "Random string", expected: runtimeApi.ContainerState_UNKNOWN}, {input: "Random string", expected: runtimeApi.ContainerState_CONTAINER_UNKNOWN},
} }
for _, test := range testCases { for _, test := range testCases {
......
...@@ -327,7 +327,7 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai ...@@ -327,7 +327,7 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai
var reason, message string var reason, message string
if r.State.Running { if r.State.Running {
// Container is running. // Container is running.
state = runtimeApi.ContainerState_RUNNING state = runtimeApi.ContainerState_CONTAINER_RUNNING
} else { } else {
// Container is *not* running. We need to get more details. // Container is *not* running. We need to get more details.
// * Case 1: container has run and exited with non-zero finishedAt // * Case 1: container has run and exited with non-zero finishedAt
...@@ -336,7 +336,7 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai ...@@ -336,7 +336,7 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai
// time, but a non-zero exit code. // time, but a non-zero exit code.
// * Case 3: container has been created, but not started (yet). // * Case 3: container has been created, but not started (yet).
if !finishedAt.IsZero() { // Case 1 if !finishedAt.IsZero() { // Case 1
state = runtimeApi.ContainerState_EXITED state = runtimeApi.ContainerState_CONTAINER_EXITED
switch { switch {
case r.State.OOMKilled: case r.State.OOMKilled:
// TODO: consider exposing OOMKilled via the runtimeAPI. // TODO: consider exposing OOMKilled via the runtimeAPI.
...@@ -349,13 +349,13 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai ...@@ -349,13 +349,13 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai
reason = "Error" reason = "Error"
} }
} else if r.State.ExitCode != 0 { // Case 2 } else if r.State.ExitCode != 0 { // Case 2
state = runtimeApi.ContainerState_EXITED state = runtimeApi.ContainerState_CONTAINER_EXITED
// Adjust finshedAt and startedAt time to createdAt time to avoid // Adjust finshedAt and startedAt time to createdAt time to avoid
// the confusion. // the confusion.
finishedAt, startedAt = createdAt, createdAt finishedAt, startedAt = createdAt, createdAt
reason = "ContainerCannotRun" reason = "ContainerCannotRun"
} else { // Case 3 } else { // Case 3
state = runtimeApi.ContainerState_CREATED state = runtimeApi.ContainerState_CONTAINER_CREATED
} }
message = r.State.Error message = r.State.Error
} }
......
...@@ -62,7 +62,7 @@ func TestListContainers(t *testing.T) { ...@@ -62,7 +62,7 @@ func TestListContainers(t *testing.T) {
} }
expected := []*runtimeApi.Container{} expected := []*runtimeApi.Container{}
state := runtimeApi.ContainerState_RUNNING state := runtimeApi.ContainerState_CONTAINER_RUNNING
var createdAt int64 = 0 var createdAt int64 = 0
for i := range configs { for i := range configs {
// We don't care about the sandbox id; pass a bogus one. // We don't care about the sandbox id; pass a bogus one.
...@@ -105,7 +105,7 @@ func TestContainerStatus(t *testing.T) { ...@@ -105,7 +105,7 @@ func TestContainerStatus(t *testing.T) {
var defaultTime time.Time var defaultTime time.Time
dt := defaultTime.UnixNano() dt := defaultTime.UnixNano()
ct, st, ft := dt, dt, dt ct, st, ft := dt, dt, dt
state := runtimeApi.ContainerState_CREATED state := runtimeApi.ContainerState_CONTAINER_CREATED
// The following variables are not set in FakeDockerClient. // The following variables are not set in FakeDockerClient.
imageRef := DockerImageIDPrefix + "" imageRef := DockerImageIDPrefix + ""
exitCode := int32(0) exitCode := int32(0)
...@@ -149,7 +149,7 @@ func TestContainerStatus(t *testing.T) { ...@@ -149,7 +149,7 @@ func TestContainerStatus(t *testing.T) {
// Advance the clock and start the container. // Advance the clock and start the container.
fClock.SetTime(time.Now()) fClock.SetTime(time.Now())
*expected.StartedAt = fClock.Now().UnixNano() *expected.StartedAt = fClock.Now().UnixNano()
*expected.State = runtimeApi.ContainerState_RUNNING *expected.State = runtimeApi.ContainerState_CONTAINER_RUNNING
err = ds.StartContainer(id) err = ds.StartContainer(id)
assert.NoError(t, err) assert.NoError(t, err)
...@@ -159,7 +159,7 @@ func TestContainerStatus(t *testing.T) { ...@@ -159,7 +159,7 @@ func TestContainerStatus(t *testing.T) {
// Advance the clock and stop the container. // Advance the clock and stop the container.
fClock.SetTime(time.Now().Add(1 * time.Hour)) fClock.SetTime(time.Now().Add(1 * time.Hour))
*expected.FinishedAt = fClock.Now().UnixNano() *expected.FinishedAt = fClock.Now().UnixNano()
*expected.State = runtimeApi.ContainerState_EXITED *expected.State = runtimeApi.ContainerState_CONTAINER_EXITED
*expected.Reason = "Completed" *expected.Reason = "Completed"
err = ds.StopContainer(id, 0) err = ds.StopContainer(id, 0)
......
...@@ -192,9 +192,9 @@ func (ds *dockerService) PodSandboxStatus(podSandboxID string) (*runtimeApi.PodS ...@@ -192,9 +192,9 @@ func (ds *dockerService) PodSandboxStatus(podSandboxID string) (*runtimeApi.PodS
ct := createdAt.UnixNano() ct := createdAt.UnixNano()
// Translate container to sandbox state. // Translate container to sandbox state.
state := runtimeApi.PodSandBoxState_NOTREADY state := runtimeApi.PodSandboxState_SANDBOX_NOTREADY
if r.State.Running { if r.State.Running {
state = runtimeApi.PodSandBoxState_READY state = runtimeApi.PodSandboxState_SANDBOX_READY
} }
IP, err := ds.getIP(r) IP, err := ds.getIP(r)
if err != nil { if err != nil {
...@@ -244,11 +244,11 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([] ...@@ -244,11 +244,11 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]
f.Add("id", filter.GetId()) f.Add("id", filter.GetId())
} }
if filter.State != nil { if filter.State != nil {
if filter.GetState() == runtimeApi.PodSandBoxState_READY { if filter.GetState() == runtimeApi.PodSandboxState_SANDBOX_READY {
// Only list running containers. // Only list running containers.
opts.All = false opts.All = false
} else { } else {
// runtimeApi.PodSandBoxState_NOTREADY can mean the // runtimeApi.PodSandboxState_SANDBOX_NOTREADY can mean the
// container is in any of the non-running state (e.g., created, // container is in any of the non-running state (e.g., created,
// exited). We can't tell docker to filter out running // exited). We can't tell docker to filter out running
// containers directly, so we'll need to filter them out // containers directly, so we'll need to filter them out
...@@ -277,7 +277,7 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([] ...@@ -277,7 +277,7 @@ func (ds *dockerService) ListPodSandbox(filter *runtimeApi.PodSandboxFilter) ([]
glog.V(5).Infof("Unable to convert docker to runtime API sandbox: %v", err) glog.V(5).Infof("Unable to convert docker to runtime API sandbox: %v", err)
continue continue
} }
if filterOutReadySandboxes && converted.GetState() == runtimeApi.PodSandBoxState_READY { if filterOutReadySandboxes && converted.GetState() == runtimeApi.PodSandboxState_SANDBOX_READY {
continue continue
} }
......
...@@ -63,7 +63,7 @@ func TestListSandboxes(t *testing.T) { ...@@ -63,7 +63,7 @@ func TestListSandboxes(t *testing.T) {
} }
expected := []*runtimeApi.PodSandbox{} expected := []*runtimeApi.PodSandbox{}
state := runtimeApi.PodSandBoxState_READY state := runtimeApi.PodSandboxState_SANDBOX_READY
var createdAt int64 = 0 var createdAt int64 = 0
for i := range configs { for i := range configs {
id, err := ds.RunPodSandbox(configs[i]) id, err := ds.RunPodSandbox(configs[i])
...@@ -98,7 +98,7 @@ func TestSandboxStatus(t *testing.T) { ...@@ -98,7 +98,7 @@ func TestSandboxStatus(t *testing.T) {
fakeIP := "2.3.4.5" fakeIP := "2.3.4.5"
fakeNS := fmt.Sprintf("/proc/%d/ns/net", os.Getpid()) fakeNS := fmt.Sprintf("/proc/%d/ns/net", os.Getpid())
state := runtimeApi.PodSandBoxState_READY state := runtimeApi.PodSandboxState_SANDBOX_READY
ct := int64(0) ct := int64(0)
hostNetwork := false hostNetwork := false
expected := &runtimeApi.PodSandboxStatus{ expected := &runtimeApi.PodSandboxStatus{
...@@ -128,7 +128,7 @@ func TestSandboxStatus(t *testing.T) { ...@@ -128,7 +128,7 @@ func TestSandboxStatus(t *testing.T) {
assert.Equal(t, expected, status) assert.Equal(t, expected, status)
// Stop the sandbox. // Stop the sandbox.
*expected.State = runtimeApi.PodSandBoxState_NOTREADY *expected.State = runtimeApi.PodSandboxState_SANDBOX_NOTREADY
err = ds.StopPodSandbox(id) err = ds.StopPodSandbox(id)
assert.NoError(t, err) assert.NoError(t, err)
status, err = ds.PodSandboxStatus(id) status, err = ds.PodSandboxStatus(id)
......
...@@ -72,13 +72,13 @@ func (c containerStatusByCreated) Less(i, j int) bool { return c[i].CreatedAt.Af ...@@ -72,13 +72,13 @@ func (c containerStatusByCreated) Less(i, j int) bool { return c[i].CreatedAt.Af
// toKubeContainerState converts runtimeApi.ContainerState to kubecontainer.ContainerState. // toKubeContainerState converts runtimeApi.ContainerState to kubecontainer.ContainerState.
func toKubeContainerState(state runtimeApi.ContainerState) kubecontainer.ContainerState { func toKubeContainerState(state runtimeApi.ContainerState) kubecontainer.ContainerState {
switch state { switch state {
case runtimeApi.ContainerState_CREATED: case runtimeApi.ContainerState_CONTAINER_CREATED:
return kubecontainer.ContainerStateCreated return kubecontainer.ContainerStateCreated
case runtimeApi.ContainerState_RUNNING: case runtimeApi.ContainerState_CONTAINER_RUNNING:
return kubecontainer.ContainerStateRunning return kubecontainer.ContainerStateRunning
case runtimeApi.ContainerState_EXITED: case runtimeApi.ContainerState_CONTAINER_EXITED:
return kubecontainer.ContainerStateExited return kubecontainer.ContainerStateExited
case runtimeApi.ContainerState_UNKNOWN: case runtimeApi.ContainerState_CONTAINER_UNKNOWN:
return kubecontainer.ContainerStateUnknown return kubecontainer.ContainerStateUnknown
} }
......
...@@ -301,7 +301,7 @@ func (m *kubeGenericRuntimeManager) getKubeletContainers(allContainers bool) ([] ...@@ -301,7 +301,7 @@ func (m *kubeGenericRuntimeManager) getKubeletContainers(allContainers bool) ([]
LabelSelector: map[string]string{kubernetesManagedLabel: "true"}, LabelSelector: map[string]string{kubernetesManagedLabel: "true"},
} }
if !allContainers { if !allContainers {
runningState := runtimeApi.ContainerState_RUNNING runningState := runtimeApi.ContainerState_CONTAINER_RUNNING
filter.State = &runningState filter.State = &runningState
} }
...@@ -390,7 +390,7 @@ func (m *kubeGenericRuntimeManager) getPodContainerStatuses(uid kubetypes.UID, n ...@@ -390,7 +390,7 @@ func (m *kubeGenericRuntimeManager) getPodContainerStatuses(uid kubetypes.UID, n
CreatedAt: time.Unix(0, status.GetCreatedAt()), CreatedAt: time.Unix(0, status.GetCreatedAt()),
} }
if c.GetState() == runtimeApi.ContainerState_RUNNING { if c.GetState() == runtimeApi.ContainerState_CONTAINER_RUNNING {
cStatus.StartedAt = time.Unix(0, status.GetStartedAt()) cStatus.StartedAt = time.Unix(0, status.GetStartedAt())
} else { } else {
cStatus.Reason = status.GetReason() cStatus.Reason = status.GetReason()
......
...@@ -154,7 +154,7 @@ func (cgc *containerGC) evictableContainers(minAge time.Duration) (containersByE ...@@ -154,7 +154,7 @@ func (cgc *containerGC) evictableContainers(minAge time.Duration) (containersByE
newestGCTime := time.Now().Add(-minAge) newestGCTime := time.Now().Add(-minAge)
for _, container := range containers { for _, container := range containers {
// Prune out running containers. // Prune out running containers.
if container.GetState() == runtimeApi.ContainerState_RUNNING { if container.GetState() == runtimeApi.ContainerState_CONTAINER_RUNNING {
continue continue
} }
...@@ -249,7 +249,7 @@ func (cgc *containerGC) evictSandboxes(minAge time.Duration) error { ...@@ -249,7 +249,7 @@ func (cgc *containerGC) evictSandboxes(minAge time.Duration) error {
newestGCTime := time.Now().Add(-minAge) newestGCTime := time.Now().Add(-minAge)
for _, sandbox := range sandboxes { for _, sandbox := range sandboxes {
// Prune out ready sandboxes. // Prune out ready sandboxes.
if sandbox.GetState() == runtimeApi.PodSandBoxState_READY { if sandbox.GetState() == runtimeApi.PodSandboxState_SANDBOX_READY {
continue continue
} }
......
...@@ -393,14 +393,14 @@ func (m *kubeGenericRuntimeManager) podSandboxChanged(pod *api.Pod, podStatus *k ...@@ -393,14 +393,14 @@ func (m *kubeGenericRuntimeManager) podSandboxChanged(pod *api.Pod, podStatus *k
readySandboxCount := 0 readySandboxCount := 0
for _, s := range podStatus.SandboxStatuses { for _, s := range podStatus.SandboxStatuses {
if s.GetState() == runtimeApi.PodSandBoxState_READY { if s.GetState() == runtimeApi.PodSandboxState_SANDBOX_READY {
readySandboxCount++ readySandboxCount++
} }
} }
// Needs to create a new sandbox when readySandboxCount > 1 or the ready sandbox is not the latest one. // Needs to create a new sandbox when readySandboxCount > 1 or the ready sandbox is not the latest one.
sandboxStatus := podStatus.SandboxStatuses[0] sandboxStatus := podStatus.SandboxStatuses[0]
if readySandboxCount > 1 || sandboxStatus.GetState() != runtimeApi.PodSandBoxState_READY { if readySandboxCount > 1 || sandboxStatus.GetState() != runtimeApi.PodSandboxState_SANDBOX_READY {
glog.V(2).Infof("No ready sandbox for pod %q can be found. Need to start a new one", format.Pod(pod)) glog.V(2).Infof("No ready sandbox for pod %q can be found. Need to start a new one", format.Pod(pod))
return true, sandboxStatus.Metadata.GetAttempt() + 1, sandboxStatus.GetId() return true, sandboxStatus.Metadata.GetAttempt() + 1, sandboxStatus.GetId()
} }
...@@ -865,7 +865,7 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp ...@@ -865,7 +865,7 @@ func (m *kubeGenericRuntimeManager) GetPodStatus(uid kubetypes.UID, name, namesp
sandboxStatuses[idx] = podSandboxStatus sandboxStatuses[idx] = podSandboxStatus
// Only get pod IP from latest sandbox // Only get pod IP from latest sandbox
if idx == 0 && podSandboxStatus.GetState() == runtimeApi.PodSandBoxState_READY { if idx == 0 && podSandboxStatus.GetState() == runtimeApi.PodSandboxState_SANDBOX_READY {
podIP = m.determinePodSandboxIP(namespace, name, podSandboxStatus) podIP = m.determinePodSandboxIP(namespace, name, podSandboxStatus)
} }
} }
......
...@@ -66,7 +66,7 @@ type sandboxTemplate struct { ...@@ -66,7 +66,7 @@ type sandboxTemplate struct {
pod *api.Pod pod *api.Pod
attempt uint32 attempt uint32
createdAt int64 createdAt int64
state runtimeApi.PodSandBoxState state runtimeApi.PodSandboxState
} }
// containerTemplate is a container template to create fake container. // containerTemplate is a container template to create fake container.
...@@ -86,7 +86,7 @@ func makeAndSetFakePod(t *testing.T, m *kubeGenericRuntimeManager, fakeRuntime * ...@@ -86,7 +86,7 @@ func makeAndSetFakePod(t *testing.T, m *kubeGenericRuntimeManager, fakeRuntime *
sandbox := makeFakePodSandbox(t, m, sandboxTemplate{ sandbox := makeFakePodSandbox(t, m, sandboxTemplate{
pod: pod, pod: pod,
createdAt: fakeCreatedAt, createdAt: fakeCreatedAt,
state: runtimeApi.PodSandBoxState_READY, state: runtimeApi.PodSandboxState_SANDBOX_READY,
}) })
var containers []*apitest.FakeContainer var containers []*apitest.FakeContainer
...@@ -95,7 +95,7 @@ func makeAndSetFakePod(t *testing.T, m *kubeGenericRuntimeManager, fakeRuntime * ...@@ -95,7 +95,7 @@ func makeAndSetFakePod(t *testing.T, m *kubeGenericRuntimeManager, fakeRuntime *
pod: pod, pod: pod,
container: c, container: c,
createdAt: fakeCreatedAt, createdAt: fakeCreatedAt,
state: runtimeApi.ContainerState_RUNNING, state: runtimeApi.ContainerState_CONTAINER_RUNNING,
} }
} }
for i := range pod.Spec.Containers { for i := range pod.Spec.Containers {
...@@ -509,10 +509,10 @@ func TestKillPod(t *testing.T) { ...@@ -509,10 +509,10 @@ func TestKillPod(t *testing.T) {
assert.Equal(t, 2, len(fakeRuntime.Containers)) assert.Equal(t, 2, len(fakeRuntime.Containers))
assert.Equal(t, 1, len(fakeRuntime.Sandboxes)) assert.Equal(t, 1, len(fakeRuntime.Sandboxes))
for _, sandbox := range fakeRuntime.Sandboxes { for _, sandbox := range fakeRuntime.Sandboxes {
assert.Equal(t, runtimeApi.PodSandBoxState_NOTREADY, sandbox.GetState()) assert.Equal(t, runtimeApi.PodSandboxState_SANDBOX_NOTREADY, sandbox.GetState())
} }
for _, c := range fakeRuntime.Containers { for _, c := range fakeRuntime.Containers {
assert.Equal(t, runtimeApi.ContainerState_EXITED, c.GetState()) assert.Equal(t, runtimeApi.ContainerState_CONTAINER_EXITED, c.GetState())
} }
} }
...@@ -550,10 +550,10 @@ func TestSyncPod(t *testing.T) { ...@@ -550,10 +550,10 @@ func TestSyncPod(t *testing.T) {
assert.Equal(t, 2, len(fakeImage.Images)) assert.Equal(t, 2, len(fakeImage.Images))
assert.Equal(t, 1, len(fakeRuntime.Sandboxes)) assert.Equal(t, 1, len(fakeRuntime.Sandboxes))
for _, sandbox := range fakeRuntime.Sandboxes { for _, sandbox := range fakeRuntime.Sandboxes {
assert.Equal(t, runtimeApi.PodSandBoxState_READY, sandbox.GetState()) assert.Equal(t, runtimeApi.PodSandboxState_SANDBOX_READY, sandbox.GetState())
} }
for _, c := range fakeRuntime.Containers { for _, c := range fakeRuntime.Containers {
assert.Equal(t, runtimeApi.ContainerState_RUNNING, c.GetState()) assert.Equal(t, runtimeApi.ContainerState_CONTAINER_RUNNING, c.GetState())
} }
} }
...@@ -575,11 +575,11 @@ func TestPruneInitContainers(t *testing.T) { ...@@ -575,11 +575,11 @@ func TestPruneInitContainers(t *testing.T) {
} }
templates := []containerTemplate{ templates := []containerTemplate{
{pod: pod, container: &init1, attempt: 2, createdAt: 2, state: runtimeApi.ContainerState_EXITED}, {pod: pod, container: &init1, attempt: 2, createdAt: 2, state: runtimeApi.ContainerState_CONTAINER_EXITED},
{pod: pod, container: &init1, attempt: 1, createdAt: 1, state: runtimeApi.ContainerState_EXITED}, {pod: pod, container: &init1, attempt: 1, createdAt: 1, state: runtimeApi.ContainerState_CONTAINER_EXITED},
{pod: pod, container: &init2, attempt: 1, createdAt: 1, state: runtimeApi.ContainerState_EXITED}, {pod: pod, container: &init2, attempt: 1, createdAt: 1, state: runtimeApi.ContainerState_CONTAINER_EXITED},
{pod: pod, container: &init2, attempt: 0, createdAt: 0, state: runtimeApi.ContainerState_EXITED}, {pod: pod, container: &init2, attempt: 0, createdAt: 0, state: runtimeApi.ContainerState_CONTAINER_EXITED},
{pod: pod, container: &init1, attempt: 0, createdAt: 0, state: runtimeApi.ContainerState_EXITED}, {pod: pod, container: &init1, attempt: 0, createdAt: 0, state: runtimeApi.ContainerState_CONTAINER_EXITED},
} }
fakes := makeFakeContainers(t, m, templates) fakes := makeFakeContainers(t, m, templates)
fakeRuntime.SetFakeContainers(fakes) fakeRuntime.SetFakeContainers(fakes)
......
...@@ -153,7 +153,7 @@ func generatePodSandboxLinuxConfig(pod *api.Pod, cgroupParent string) *runtimeAp ...@@ -153,7 +153,7 @@ func generatePodSandboxLinuxConfig(pod *api.Pod, cgroupParent string) *runtimeAp
func (m *kubeGenericRuntimeManager) getKubeletSandboxes(all bool) ([]*runtimeApi.PodSandbox, error) { func (m *kubeGenericRuntimeManager) getKubeletSandboxes(all bool) ([]*runtimeApi.PodSandbox, error) {
var filter *runtimeApi.PodSandboxFilter var filter *runtimeApi.PodSandboxFilter
if !all { if !all {
readyState := runtimeApi.PodSandBoxState_READY readyState := runtimeApi.PodSandboxState_SANDBOX_READY
filter = &runtimeApi.PodSandboxFilter{ filter = &runtimeApi.PodSandboxFilter{
State: &readyState, State: &readyState,
} }
...@@ -195,7 +195,7 @@ func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName ...@@ -195,7 +195,7 @@ func (m *kubeGenericRuntimeManager) determinePodSandboxIP(podNamespace, podName
// getPodSandboxID gets the sandbox id by podUID and returns ([]sandboxID, error). // getPodSandboxID gets the sandbox id by podUID and returns ([]sandboxID, error).
// Param state could be nil in order to get all sandboxes belonging to same pod. // Param state could be nil in order to get all sandboxes belonging to same pod.
func (m *kubeGenericRuntimeManager) getSandboxIDByPodUID(podUID string, state *runtimeApi.PodSandBoxState) ([]string, error) { func (m *kubeGenericRuntimeManager) getSandboxIDByPodUID(podUID string, state *runtimeApi.PodSandboxState) ([]string, error) {
filter := &runtimeApi.PodSandboxFilter{ filter := &runtimeApi.PodSandboxFilter{
State: state, State: state,
LabelSelector: map[string]string{types.KubernetesPodUIDLabel: podUID}, LabelSelector: map[string]string{types.KubernetesPodUIDLabel: podUID},
......
...@@ -88,13 +88,13 @@ type fakeContainer struct { ...@@ -88,13 +88,13 @@ type fakeContainer struct {
} }
func (c *fakeContainer) Start() { func (c *fakeContainer) Start() {
c.State = runtimeApi.ContainerState_RUNNING c.State = runtimeApi.ContainerState_CONTAINER_RUNNING
c.Status.State = &c.State c.Status.State = &c.State
} }
func (c *fakeContainer) Stop() { func (c *fakeContainer) Stop() {
c.State = runtimeApi.ContainerState_EXITED c.State = runtimeApi.ContainerState_CONTAINER_EXITED
c.Status.State = &c.State c.Status.State = &c.State
...@@ -135,11 +135,11 @@ func (r *FakeRuntime) StartContainer(id string) error { ...@@ -135,11 +135,11 @@ func (r *FakeRuntime) StartContainer(id string) error {
return ErrContainerNotFound return ErrContainerNotFound
} }
switch c.State { switch c.State {
case runtimeApi.ContainerState_EXITED: case runtimeApi.ContainerState_CONTAINER_EXITED:
fallthrough fallthrough
case runtimeApi.ContainerState_CREATED: case runtimeApi.ContainerState_CONTAINER_CREATED:
c.Start() c.Start()
case runtimeApi.ContainerState_UNKNOWN: case runtimeApi.ContainerState_CONTAINER_UNKNOWN:
// TODO(tmrts): add timeout to Start API or generalize timeout somehow // TODO(tmrts): add timeout to Start API or generalize timeout somehow
//<-time.After(time.Duration(timeout) * time.Second) //<-time.After(time.Duration(timeout) * time.Second)
fallthrough fallthrough
...@@ -157,9 +157,9 @@ func (r *FakeRuntime) StopContainer(id string, timeout int64) error { ...@@ -157,9 +157,9 @@ func (r *FakeRuntime) StopContainer(id string, timeout int64) error {
} }
switch c.State { switch c.State {
case runtimeApi.ContainerState_RUNNING: case runtimeApi.ContainerState_CONTAINER_RUNNING:
c.State = runtimeApi.ContainerState_EXITED // This state might not be the best one c.State = runtimeApi.ContainerState_CONTAINER_EXITED // This state might not be the best one
case runtimeApi.ContainerState_UNKNOWN: case runtimeApi.ContainerState_CONTAINER_UNKNOWN:
<-time.After(time.Duration(timeout) * time.Second) <-time.After(time.Duration(timeout) * time.Second)
fallthrough fallthrough
default: default:
...@@ -214,7 +214,7 @@ func (r *FakeRuntime) ExecSync(containerID string, cmd []string, timeout time.Du ...@@ -214,7 +214,7 @@ func (r *FakeRuntime) ExecSync(containerID string, cmd []string, timeout time.Du
} }
// TODO(tmrts): Validate the assumption that container has to be running for exec to work. // TODO(tmrts): Validate the assumption that container has to be running for exec to work.
if c.State != runtimeApi.ContainerState_RUNNING { if c.State != runtimeApi.ContainerState_CONTAINER_RUNNING {
return nil, nil, ErrInvalidContainerStateTransition return nil, nil, ErrInvalidContainerStateTransition
} }
......
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