container: fix concurrent map acccess
GetSpec() can be called concurrently in manager/container.go.updateSpec() results into a concurrent map access on the labels map because we're directly updating the map inside GetSpec(). The labels map from the container handler is not a copy of the map itself, just a reference, that's why we're getting the concurrent map access. Fix this by moving the label update with restartcount to the handler's initialization method which is not called concurrently. Signed-off-by: Antonio Murdaca <runcom@redhat.com>
This commit is contained in:
parent
e10baf0057
commit
42eeba5783
@ -65,9 +65,6 @@ type crioContainerHandler struct {
|
|||||||
|
|
||||||
ignoreMetrics container.MetricSet
|
ignoreMetrics container.MetricSet
|
||||||
|
|
||||||
// container restart count
|
|
||||||
restartCount int
|
|
||||||
|
|
||||||
reference info.ContainerReference
|
reference info.ContainerReference
|
||||||
|
|
||||||
libcontainerHandler *containerlibcontainer.Handler
|
libcontainerHandler *containerlibcontainer.Handler
|
||||||
@ -166,7 +163,10 @@ func newCrioContainerHandler(
|
|||||||
// ignore err and get zero as default, this happens with sandboxes, not sure why...
|
// ignore err and get zero as default, this happens with sandboxes, not sure why...
|
||||||
// kube isn't sending restart count in labels for sandboxes.
|
// kube isn't sending restart count in labels for sandboxes.
|
||||||
restartCount, _ := strconv.Atoi(cInfo.Annotations["io.kubernetes.container.restartCount"])
|
restartCount, _ := strconv.Atoi(cInfo.Annotations["io.kubernetes.container.restartCount"])
|
||||||
handler.restartCount = restartCount
|
// Only adds restartcount label if it's greater than 0
|
||||||
|
if restartCount > 0 {
|
||||||
|
handler.labels["restartcount"] = strconv.Itoa(restartCount)
|
||||||
|
}
|
||||||
|
|
||||||
handler.ipAddress = cInfo.IP
|
handler.ipAddress = cInfo.IP
|
||||||
|
|
||||||
@ -210,10 +210,6 @@ func (self *crioContainerHandler) GetSpec() (info.ContainerSpec, error) {
|
|||||||
spec, err := common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem)
|
spec, err := common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem)
|
||||||
|
|
||||||
spec.Labels = self.labels
|
spec.Labels = self.labels
|
||||||
// Only adds restartcount label if it's greater than 0
|
|
||||||
if self.restartCount > 0 {
|
|
||||||
spec.Labels["restartcount"] = strconv.Itoa(self.restartCount)
|
|
||||||
}
|
|
||||||
spec.Envs = self.envs
|
spec.Envs = self.envs
|
||||||
spec.Image = self.image
|
spec.Image = self.image
|
||||||
|
|
||||||
|
@ -91,9 +91,6 @@ type dockerContainerHandler struct {
|
|||||||
// zfsParent is the parent for docker zfs
|
// zfsParent is the parent for docker zfs
|
||||||
zfsParent string
|
zfsParent string
|
||||||
|
|
||||||
// container restart count
|
|
||||||
restartCount int
|
|
||||||
|
|
||||||
// Reference to the container
|
// Reference to the container
|
||||||
reference info.ContainerReference
|
reference info.ContainerReference
|
||||||
|
|
||||||
@ -226,7 +223,10 @@ func newDockerContainerHandler(
|
|||||||
}
|
}
|
||||||
handler.image = ctnr.Config.Image
|
handler.image = ctnr.Config.Image
|
||||||
handler.networkMode = ctnr.HostConfig.NetworkMode
|
handler.networkMode = ctnr.HostConfig.NetworkMode
|
||||||
handler.restartCount = ctnr.RestartCount
|
// Only adds restartcount label if it's greater than 0
|
||||||
|
if ctnr.RestartCount > 0 {
|
||||||
|
handler.labels["restartcount"] = strconv.Itoa(ctnr.RestartCount)
|
||||||
|
}
|
||||||
|
|
||||||
// Obtain the IP address for the contianer.
|
// Obtain the IP address for the contianer.
|
||||||
// If the NetworkMode starts with 'container:' then we need to use the IP address of the container specified.
|
// 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) {
|
|||||||
spec, err := common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem)
|
spec, err := common.GetSpec(self.cgroupPaths, self.machineInfoFactory, self.needNet(), hasFilesystem)
|
||||||
|
|
||||||
spec.Labels = self.labels
|
spec.Labels = self.labels
|
||||||
// Only adds restartcount label if it's greater than 0
|
|
||||||
if self.restartCount > 0 {
|
|
||||||
spec.Labels["restartcount"] = strconv.Itoa(self.restartCount)
|
|
||||||
}
|
|
||||||
spec.Envs = self.envs
|
spec.Envs = self.envs
|
||||||
spec.Image = self.image
|
spec.Image = self.image
|
||||||
spec.CreationTime = self.creationTime
|
spec.CreationTime = self.creationTime
|
||||||
|
Loading…
Reference in New Issue
Block a user