Commit 7767dafb authored by Yifan Gu's avatar Yifan Gu

kubelet/rkt: include the pod restart count in service file.

Also remove the service file when the pod is killed.
parent 763ffdb1
...@@ -18,6 +18,7 @@ package rkt ...@@ -18,6 +18,7 @@ package rkt
import ( import (
"fmt" "fmt"
"reflect"
"strconv" "strconv"
"strings" "strings"
...@@ -43,6 +44,21 @@ const ( ...@@ -43,6 +44,21 @@ const (
exitCodePrefix = "app-" exitCodePrefix = "app-"
) )
// rktInfo represents the information of the rkt pod that stored in the
// systemd service file.
type rktInfo struct {
uuid string
restartCount int
}
func emptyRktInfo() *rktInfo {
return &rktInfo{restartCount: -1}
}
func (r *rktInfo) isEmpty() bool {
return reflect.DeepEqual(r, emptyRktInfo())
}
// podInfo is the internal type that represents the state of // podInfo is the internal type that represents the state of
// the rkt pod. // the rkt pod.
type podInfo struct { type podInfo struct {
...@@ -122,15 +138,15 @@ func getIPFromNetworkInfo(networkInfo string) string { ...@@ -122,15 +138,15 @@ func getIPFromNetworkInfo(networkInfo string) string {
return "" return ""
} }
// getContainerStatus creates the api.containerStatus of a container from the podInfo. // makeContainerStatus creates the api.containerStatus of a container from the podInfo.
func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.ContainerStatus { func makeContainerStatus(container *kubecontainer.Container, podInfo *podInfo) api.ContainerStatus {
var status api.ContainerStatus var status api.ContainerStatus
status.Name = container.Name status.Name = container.Name
status.Image = container.Image status.Image = container.Image
status.ContainerID = string(container.ID) status.ContainerID = string(container.ID)
// TODO(yifan): Add image ID info. // TODO(yifan): Add image ID info.
switch p.state { switch podInfo.state {
case Running: case Running:
// TODO(yifan): Get StartedAt. // TODO(yifan): Get StartedAt.
status.State = api.ContainerState{ status.State = api.ContainerState{
...@@ -141,7 +157,7 @@ func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.Con ...@@ -141,7 +157,7 @@ func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.Con
case Embryo, Preparing, Prepared: case Embryo, Preparing, Prepared:
status.State = api.ContainerState{Waiting: &api.ContainerStateWaiting{}} status.State = api.ContainerState{Waiting: &api.ContainerStateWaiting{}}
case AbortedPrepare, Deleting, Exited, Garbage: case AbortedPrepare, Deleting, Exited, Garbage:
exitCode, ok := p.exitCodes[status.Name] exitCode, ok := podInfo.exitCodes[status.Name]
if !ok { if !ok {
glog.Warningf("rkt: Cannot get exit code for container %v", container) glog.Warningf("rkt: Cannot get exit code for container %v", container)
exitCode = -1 exitCode = -1
...@@ -154,18 +170,20 @@ func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.Con ...@@ -154,18 +170,20 @@ func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.Con
}, },
} }
default: default:
glog.Warningf("rkt: Unknown pod state: %q", p.state) glog.Warningf("rkt: Unknown pod state: %q", podInfo.state)
} }
return status return status
} }
// toPodStatus converts a podInfo type into an api.PodStatus type. // makePodStatus constructs the pod status from the pod info and rkt info.
func (p *podInfo) toPodStatus(pod *kubecontainer.Pod) api.PodStatus { func makePodStatus(pod *kubecontainer.Pod, podInfo *podInfo, rktInfo *rktInfo) api.PodStatus {
var status api.PodStatus var status api.PodStatus
status.PodIP = p.ip status.PodIP = podInfo.ip
// For now just make every container's state the same as the pod. // For now just make every container's state the same as the pod.
for _, container := range pod.Containers { for _, container := range pod.Containers {
status.ContainerStatuses = append(status.ContainerStatuses, p.getContainerStatus(container)) containerStatus := makeContainerStatus(container, podInfo)
containerStatus.RestartCount = rktInfo.restartCount
status.ContainerStatuses = append(status.ContainerStatuses, containerStatus)
} }
return status return status
} }
......
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