in agent/handlers/v2/response.go [219:300]
func NewContainerResponse(
dockerContainer *apicontainer.DockerContainer,
eni *apieni.ENI,
includeV4Metadata bool,
) ContainerResponse {
container := dockerContainer.Container
resp := ContainerResponse{
ID: dockerContainer.DockerID,
Name: container.Name,
DockerName: dockerContainer.DockerName,
Image: container.Image,
ImageID: container.ImageID,
DesiredStatus: container.GetDesiredStatus().String(),
KnownStatus: container.GetKnownStatus().String(),
Limits: LimitsResponse{
CPU: aws.Float64(float64(container.CPU)),
Memory: aws.Int64(int64(container.Memory)),
},
Type: container.Type.String(),
ExitCode: container.GetKnownExitCode(),
Labels: container.GetLabels(),
}
if container.CPU < minimumCPUUnit {
defaultCPU := func(val float64) *float64 { return &val }(minimumCPUUnit)
resp.Limits.CPU = defaultCPU
}
// V4 metadata endpoint calls this function for consistency across versions,
// but needs additional metadata only available at this scope.
if includeV4Metadata {
resp.LogDriver = container.GetLogDriver()
resp.LogOptions = container.GetLogOptions()
resp.ContainerARN = container.ContainerArn
}
// Write the container health status inside the container
if dockerContainer.Container.HealthStatusShouldBeReported() {
health := dockerContainer.Container.GetHealthStatus()
resp.Health = &health
}
if createdAt := container.GetCreatedAt(); !createdAt.IsZero() {
createdAt = createdAt.UTC()
resp.CreatedAt = &createdAt
}
if startedAt := container.GetStartedAt(); !startedAt.IsZero() {
startedAt = startedAt.UTC()
resp.StartedAt = &startedAt
}
if finishedAt := container.GetFinishedAt(); !finishedAt.IsZero() {
finishedAt = finishedAt.UTC()
resp.FinishedAt = &finishedAt
}
for _, binding := range container.GetKnownPortBindings() {
port := v1.PortResponse{
ContainerPort: binding.ContainerPort,
Protocol: binding.Protocol.String(),
}
if eni == nil {
port.HostPort = binding.HostPort
} else {
port.HostPort = port.ContainerPort
}
resp.Ports = append(resp.Ports, port)
}
if eni != nil {
resp.Networks = []containermetadata.Network{
{
NetworkMode: utils.NetworkModeAWSVPC,
IPv4Addresses: eni.GetIPV4Addresses(),
IPv6Addresses: eni.GetIPV6Addresses(),
},
}
}
resp.Volumes = v1.NewVolumesResponse(dockerContainer)
return resp
}