Commit 73776995 authored by Yu-Ju Hong's avatar Yu-Ju Hong

CRI: add Message in ContainerStatus

Kubernetes expects a brief CamelCase string as "Reason" and a human-readable string as "Message" in the conatiner status. It is difficult for kubelet to derive the other one if the runtime only provides one of the two fields. Augment the API by adding the "Message" field.
parent 501f2647
......@@ -571,14 +571,17 @@ message ContainerStatus {
// Reference to the image in use. For most runtimes, this should be an
// image ID
optional string image_ref = 9;
// A string explains why container is in such a status.
// A brief CamelCase string explains why container is in such a status.
optional string reason = 10;
// A human-readable message indication details about why container is in
// this state.
optional string message = 11;
// Labels are key value pairs that may be used to scope and select individual resources.
map<string,string> labels = 11;
map<string,string> labels = 12;
// Annotations is an unstructured key value map.
map<string,string> annotations = 12;
map<string,string> annotations = 13;
// Mounts specifies mounts for the container
repeated Mount mounts = 13;
repeated Mount mounts = 14;
}
message ContainerStatusResponse {
......
......@@ -239,7 +239,7 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai
}
// Interpret container states.
var state runtimeApi.ContainerState
var reason string
var reason, message string
if r.State.Running {
// Container is running.
state = runtimeApi.ContainerState_RUNNING
......@@ -261,9 +261,9 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai
case r.State.ExitCode == 0:
reason = "Completed"
default:
reason = fmt.Sprintf("Error: %s", r.State.Error)
reason = "Error"
}
} else if !finishedAt.IsZero() && r.State.ExitCode != 0 { // Case 2
} else if r.State.ExitCode != 0 { // Case 2
state = runtimeApi.ContainerState_EXITED
// Adjust finshedAt and startedAt time to createdAt time to avoid
// the confusion.
......@@ -272,6 +272,7 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai
} else { // Case 3
state = runtimeApi.ContainerState_CREATED
}
message = r.State.Error
}
// Convert to unix timestamps.
......@@ -296,6 +297,7 @@ func (ds *dockerService) ContainerStatus(containerID string) (*runtimeApi.Contai
StartedAt: &st,
FinishedAt: &ft,
Reason: &reason,
Message: &message,
Labels: labels,
Annotations: annotations,
}, nil
......
......@@ -104,7 +104,7 @@ func TestContainerStatus(t *testing.T) {
// The following variables are not set in FakeDockerClient.
imageRef := ""
exitCode := int32(0)
reason := ""
var reason, message string
expected := &runtimeApi.ContainerStatus{
State: &state,
......@@ -116,6 +116,7 @@ func TestContainerStatus(t *testing.T) {
ImageRef: &imageRef,
ExitCode: &exitCode,
Reason: &reason,
Message: &message,
Mounts: []*runtimeApi.Mount{},
Labels: config.Labels,
Annotations: config.Annotations,
......
......@@ -377,11 +377,16 @@ func (m *kubeGenericRuntimeManager) getKubeletContainerStatuses(podSandboxID str
cStatus.StartedAt = time.Unix(status.GetStartedAt(), 0)
} else {
cStatus.Reason = status.GetReason()
cStatus.Message = status.GetMessage()
cStatus.ExitCode = int(status.GetExitCode())
cStatus.FinishedAt = time.Unix(status.GetFinishedAt(), 0)
}
cStatus.Message = getTerminationMessage(status, cStatus, annotatedInfo.TerminationMessagePath)
tMessage := getTerminationMessage(status, cStatus, annotatedInfo.TerminationMessagePath)
// Use the termination message written by the application is not empty
if len(tMessage) != 0 {
cStatus.Message = tMessage
}
statuses[i] = cStatus
}
......
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