@@ -18,6 +18,7 @@ package rkt
18
18
19
19
import (
20
20
"fmt"
21
+ "reflect"
21
22
"strconv"
22
23
"strings"
23
24
@@ -43,6 +44,21 @@ const (
43
44
exitCodePrefix = "app-"
44
45
)
45
46
47
+ // rktInfo represents the information of the rkt pod that stored in the
48
+ // systemd service file.
49
+ type rktInfo struct {
50
+ uuid string
51
+ restartCount int
52
+ }
53
+
54
+ func emptyRktInfo () * rktInfo {
55
+ return & rktInfo {restartCount : - 1 }
56
+ }
57
+
58
+ func (r * rktInfo ) isEmpty () bool {
59
+ return reflect .DeepEqual (r , emptyRktInfo ())
60
+ }
61
+
46
62
// podInfo is the internal type that represents the state of
47
63
// the rkt pod.
48
64
type podInfo struct {
@@ -122,15 +138,15 @@ func getIPFromNetworkInfo(networkInfo string) string {
122
138
return ""
123
139
}
124
140
125
- // getContainerStatus creates the api.containerStatus of a container from the podInfo.
126
- func ( p * podInfo ) getContainerStatus ( container * kubecontainer.Container ) api.ContainerStatus {
141
+ // makeContainerStatus creates the api.containerStatus of a container from the podInfo.
142
+ func makeContainerStatus ( container * kubecontainer.Container , podInfo * podInfo ) api.ContainerStatus {
127
143
var status api.ContainerStatus
128
144
status .Name = container .Name
129
145
status .Image = container .Image
130
146
status .ContainerID = string (container .ID )
131
147
// TODO(yifan): Add image ID info.
132
148
133
- switch p .state {
149
+ switch podInfo .state {
134
150
case Running :
135
151
// TODO(yifan): Get StartedAt.
136
152
status .State = api.ContainerState {
@@ -141,7 +157,7 @@ func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.Con
141
157
case Embryo , Preparing , Prepared :
142
158
status .State = api.ContainerState {Waiting : & api.ContainerStateWaiting {}}
143
159
case AbortedPrepare , Deleting , Exited , Garbage :
144
- exitCode , ok := p .exitCodes [status .Name ]
160
+ exitCode , ok := podInfo .exitCodes [status .Name ]
145
161
if ! ok {
146
162
glog .Warningf ("rkt: Cannot get exit code for container %v" , container )
147
163
exitCode = - 1
@@ -154,18 +170,20 @@ func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.Con
154
170
},
155
171
}
156
172
default :
157
- glog .Warningf ("rkt: Unknown pod state: %q" , p .state )
173
+ glog .Warningf ("rkt: Unknown pod state: %q" , podInfo .state )
158
174
}
159
175
return status
160
176
}
161
177
162
- // toPodStatus converts a podInfo type into an api.PodStatus type .
163
- func ( p * podInfo ) toPodStatus ( pod * kubecontainer.Pod ) api.PodStatus {
178
+ // makePodStatus constructs the pod status from the pod info and rkt info .
179
+ func makePodStatus ( pod * kubecontainer.Pod , podInfo * podInfo , rktInfo * rktInfo ) api.PodStatus {
164
180
var status api.PodStatus
165
- status .PodIP = p .ip
181
+ status .PodIP = podInfo .ip
166
182
// For now just make every container's state the same as the pod.
167
183
for _ , container := range pod .Containers {
168
- status .ContainerStatuses = append (status .ContainerStatuses , p .getContainerStatus (container ))
184
+ containerStatus := makeContainerStatus (container , podInfo )
185
+ containerStatus .RestartCount = rktInfo .restartCount
186
+ status .ContainerStatuses = append (status .ContainerStatuses , containerStatus )
169
187
}
170
188
return status
171
189
}
0 commit comments