Пример #1
0
func (r *runtime) getContainerStatus(container ContainerStatus, image, imageID string) api.ContainerStatus {
	var status api.ContainerStatus

	_, _, _, containerName, _, err := r.parseHyperContainerFullName(container.Name)
	if err != nil {
		return status
	}

	status.Name = strings.Split(containerName, ".")[0]
	status.ContainerID = r.buildContainerID(container.ContainerID)
	status.Image = image
	status.ImageID = imageID

	switch container.Phase {
	case StatusRunning:
		runningStartedAt, err := parseTimeString(container.Running.StartedAt)
		if err != nil {
			glog.Errorf("Hyper: can't parse runningStartedAt %s", container.Running.StartedAt)
			return status
		}

		status.State = api.ContainerState{
			Running: &api.ContainerStateRunning{
				StartedAt: unversioned.NewTime(runningStartedAt),
			},
		}
	case StatusPending:
		status.State = api.ContainerState{
			Waiting: &api.ContainerStateWaiting{
				Reason: container.Waiting.Reason,
			},
		}
	case StatusFailed, StatusSuccess:
		terminatedStartedAt, err := parseTimeString(container.Terminated.StartedAt)
		if err != nil {
			glog.Errorf("Hyper: can't parse terminatedStartedAt %s", container.Terminated.StartedAt)
			return status
		}

		terminatedFinishedAt, err := parseTimeString(container.Terminated.FinishedAt)
		if err != nil {
			glog.Errorf("Hyper: can't parse terminatedFinishedAt %s", container.Terminated.FinishedAt)
			return status
		}

		status.State = api.ContainerState{
			Terminated: &api.ContainerStateTerminated{
				ExitCode:   container.Terminated.ExitCode,
				Reason:     container.Terminated.Reason,
				Message:    container.Terminated.Message,
				StartedAt:  unversioned.NewTime(terminatedStartedAt),
				FinishedAt: unversioned.NewTime(terminatedFinishedAt),
			},
		}
	default:
		glog.Warningf("Hyper: Unknown pod state: %q", container.Phase)
	}

	return status
}
Пример #2
0
// getContainerStatus creates the api.containerStatus of a container from the podInfo.
// TODO(yifan): Get more detailed info such as Image, ImageID, etc.
func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.ContainerStatus {
	var status api.ContainerStatus
	status.Name = container.Name
	status.Image = container.Image
	containerID, _ := parseContainerID(string(container.ID))
	status.ImageID = containerID.imageID

	switch p.state {
	case Running:
		// TODO(yifan): Get StartedAt.
		status.State = api.ContainerState{
			Running: &api.ContainerStateRunning{
				StartedAt: util.Unix(container.Created, 0),
			},
		}
	case Embryo, Preparing, Prepared:
		status.State = api.ContainerState{Waiting: &api.ContainerStateWaiting{}}
	case AbortedPrepare, Deleting, Exited, Garbage:
		exitCode, ok := p.exitCodes[status.ImageID]
		if !ok {
			glog.Warningf("rkt: Cannot get exit code for container %v", container)
		}
		exitCode = -1
		status.State = api.ContainerState{
			Terminated: &api.ContainerStateTerminated{
				ExitCode:  exitCode,
				StartedAt: util.Unix(container.Created, 0),
			},
		}
	default:
		glog.Warningf("rkt: Unknown pod state: %q", p.state)
	}
	return status
}
Пример #3
0
// makeContainerStatus creates the api.containerStatus of a container from the podInfo.
func makeContainerStatus(container *kubecontainer.Container, podInfo *podInfo) api.ContainerStatus {
	var status api.ContainerStatus
	status.Name = container.Name
	status.Image = container.Image
	status.ContainerID = string(container.ID)
	// TODO(yifan): Add image ID info.

	switch podInfo.state {
	case Running:
		// TODO(yifan): Get StartedAt.
		status.State = api.ContainerState{
			Running: &api.ContainerStateRunning{
				StartedAt: unversioned.Unix(container.Created, 0),
			},
		}
	case Embryo, Preparing, Prepared:
		status.State = api.ContainerState{Waiting: &api.ContainerStateWaiting{}}
	case AbortedPrepare, Deleting, Exited, Garbage:
		exitCode, ok := podInfo.exitCodes[status.Name]
		if !ok {
			glog.Warningf("rkt: Cannot get exit code for container %v", container)
			exitCode = -1

		}
		status.State = api.ContainerState{
			Terminated: &api.ContainerStateTerminated{
				ExitCode:  exitCode,
				StartedAt: unversioned.Unix(container.Created, 0),
			},
		}
	default:
		glog.Warningf("rkt: Unknown pod state: %q", podInfo.state)
	}
	return status
}