Skip to content

Commit c38aa7d

Browse files
authored
Merge pull request #3 from sjenning/update-3.11-branch
UPSTREAM: google/cadvisor: 1963: container: fix concurrent map acccess
2 parents 49c4fae + 61bf777 commit c38aa7d

File tree

2 files changed

+8
-16
lines changed

2 files changed

+8
-16
lines changed

container/crio/handler.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,6 @@ type crioContainerHandler struct {
6565

6666
ignoreMetrics container.MetricSet
6767

68-
// container restart count
69-
restartCount int
70-
7168
reference info.ContainerReference
7269

7370
libcontainerHandler *containerlibcontainer.Handler
@@ -166,7 +163,10 @@ func newCrioContainerHandler(
166163
// ignore err and get zero as default, this happens with sandboxes, not sure why...
167164
// kube isn't sending restart count in labels for sandboxes.
168165
restartCount, _ := strconv.Atoi(cInfo.Annotations["io.kubernetes.container.restartCount"])
169-
handler.restartCount = restartCount
166+
// Only adds restartcount label if it's greater than 0
167+
if restartCount > 0 {
168+
handler.labels["restartcount"] = strconv.Itoa(restartCount)
169+
}
170170

171171
handler.ipAddress = cInfo.IP
172172

@@ -210,10 +210,6 @@ func (self *crioContainerHandler) GetSpec() (info.ContainerSpec, error) {
210210
spec, err := common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem)
211211

212212
spec.Labels = self.labels
213-
// Only adds restartcount label if it's greater than 0
214-
if self.restartCount > 0 {
215-
spec.Labels["restartcount"] = strconv.Itoa(self.restartCount)
216-
}
217213
spec.Envs = self.envs
218214
spec.Image = self.image
219215

container/docker/handler.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ type dockerContainerHandler struct {
9191
// zfsParent is the parent for docker zfs
9292
zfsParent string
9393

94-
// container restart count
95-
restartCount int
96-
9794
// Reference to the container
9895
reference info.ContainerReference
9996

@@ -226,7 +223,10 @@ func newDockerContainerHandler(
226223
}
227224
handler.image = ctnr.Config.Image
228225
handler.networkMode = ctnr.HostConfig.NetworkMode
229-
handler.restartCount = ctnr.RestartCount
226+
// Only adds restartcount label if it's greater than 0
227+
if ctnr.RestartCount > 0 {
228+
handler.labels["restartcount"] = strconv.Itoa(ctnr.RestartCount)
229+
}
230230

231231
// Obtain the IP address for the contianer.
232232
// If the NetworkMode starts with 'container:' then we need to use the IP address of the container specified.
@@ -356,10 +356,6 @@ func (self *dockerContainerHandler) GetSpec() (info.ContainerSpec, error) {
356356
spec, err := common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem)
357357

358358
spec.Labels = self.labels
359-
// Only adds restartcount label if it's greater than 0
360-
if self.restartCount > 0 {
361-
spec.Labels["restartcount"] = strconv.Itoa(self.restartCount)
362-
}
363359
spec.Envs = self.envs
364360
spec.Image = self.image
365361
spec.CreationTime = self.creationTime

0 commit comments

Comments
 (0)