Skip to content

Commit 655645e

Browse files
committed
Merge pull request kubernetes#13041 from yifan-gu/rkt_patch_fix
kubelet/rkt: merge environments instead of overriding.
2 parents f1e8cb1 + 7767daf commit 655645e

File tree

2 files changed

+150
-214
lines changed

2 files changed

+150
-214
lines changed

pkg/kubelet/rkt/pod_info.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package rkt
1818

1919
import (
2020
"fmt"
21+
"reflect"
2122
"strconv"
2223
"strings"
2324

@@ -43,6 +44,21 @@ const (
4344
exitCodePrefix = "app-"
4445
)
4546

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+
4662
// podInfo is the internal type that represents the state of
4763
// the rkt pod.
4864
type podInfo struct {
@@ -122,15 +138,15 @@ func getIPFromNetworkInfo(networkInfo string) string {
122138
return ""
123139
}
124140

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 {
127143
var status api.ContainerStatus
128144
status.Name = container.Name
129145
status.Image = container.Image
130146
status.ContainerID = string(container.ID)
131147
// TODO(yifan): Add image ID info.
132148

133-
switch p.state {
149+
switch podInfo.state {
134150
case Running:
135151
// TODO(yifan): Get StartedAt.
136152
status.State = api.ContainerState{
@@ -141,7 +157,7 @@ func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.Con
141157
case Embryo, Preparing, Prepared:
142158
status.State = api.ContainerState{Waiting: &api.ContainerStateWaiting{}}
143159
case AbortedPrepare, Deleting, Exited, Garbage:
144-
exitCode, ok := p.exitCodes[status.Name]
160+
exitCode, ok := podInfo.exitCodes[status.Name]
145161
if !ok {
146162
glog.Warningf("rkt: Cannot get exit code for container %v", container)
147163
exitCode = -1
@@ -154,18 +170,20 @@ func (p *podInfo) getContainerStatus(container *kubecontainer.Container) api.Con
154170
},
155171
}
156172
default:
157-
glog.Warningf("rkt: Unknown pod state: %q", p.state)
173+
glog.Warningf("rkt: Unknown pod state: %q", podInfo.state)
158174
}
159175
return status
160176
}
161177

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 {
164180
var status api.PodStatus
165-
status.PodIP = p.ip
181+
status.PodIP = podInfo.ip
166182
// For now just make every container's state the same as the pod.
167183
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)
169187
}
170188
return status
171189
}

0 commit comments

Comments
 (0)