mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-21 02:41:25 +00:00
make podTopologyHints protected by lock
It crashed kubelet by "concurrent map read and map write"
This commit is contained in:
parent
68108c70e2
commit
fe089a2d12
@ -68,10 +68,26 @@ func (s *scope) Name() string {
|
|||||||
return s.name
|
return s.name
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *scope) GetAffinity(podUID string, containerName string) TopologyHint {
|
func (s *scope) getTopologyHints(podUID string, containerName string) TopologyHint {
|
||||||
|
s.mutex.Lock()
|
||||||
|
defer s.mutex.Unlock()
|
||||||
return s.podTopologyHints[podUID][containerName]
|
return s.podTopologyHints[podUID][containerName]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *scope) setTopologyHints(podUID string, containerName string, th TopologyHint) {
|
||||||
|
s.mutex.Lock()
|
||||||
|
defer s.mutex.Unlock()
|
||||||
|
|
||||||
|
if s.podTopologyHints[podUID] == nil {
|
||||||
|
s.podTopologyHints[podUID] = make(map[string]TopologyHint)
|
||||||
|
}
|
||||||
|
s.podTopologyHints[podUID][containerName] = th
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *scope) GetAffinity(podUID string, containerName string) TopologyHint {
|
||||||
|
return s.getTopologyHints(podUID, containerName)
|
||||||
|
}
|
||||||
|
|
||||||
func (s *scope) AddHintProvider(h HintProvider) {
|
func (s *scope) AddHintProvider(h HintProvider) {
|
||||||
s.hintProviders = append(s.hintProviders, h)
|
s.hintProviders = append(s.hintProviders, h)
|
||||||
}
|
}
|
||||||
|
@ -55,13 +55,9 @@ func (s *containerScope) Admit(pod *v1.Pod) lifecycle.PodAdmitResult {
|
|||||||
if !admit {
|
if !admit {
|
||||||
return topologyAffinityError()
|
return topologyAffinityError()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s.podTopologyHints)[string(pod.UID)] == nil {
|
|
||||||
(s.podTopologyHints)[string(pod.UID)] = make(map[string]TopologyHint)
|
|
||||||
}
|
|
||||||
|
|
||||||
klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint)
|
klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint)
|
||||||
(s.podTopologyHints)[string(pod.UID)][container.Name] = bestHint
|
s.setTopologyHints(string(pod.UID), container.Name, bestHint)
|
||||||
|
|
||||||
err := s.allocateAlignedResources(pod, &container)
|
err := s.allocateAlignedResources(pod, &container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return unexpectedAdmissionError(err)
|
return unexpectedAdmissionError(err)
|
||||||
|
@ -56,12 +56,7 @@ func (s *podScope) Admit(pod *v1.Pod) lifecycle.PodAdmitResult {
|
|||||||
|
|
||||||
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
|
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
|
||||||
klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint)
|
klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint)
|
||||||
|
s.setTopologyHints(string(pod.UID), container.Name, bestHint)
|
||||||
if (s.podTopologyHints)[string(pod.UID)] == nil {
|
|
||||||
(s.podTopologyHints)[string(pod.UID)] = make(map[string]TopologyHint)
|
|
||||||
}
|
|
||||||
|
|
||||||
(s.podTopologyHints)[string(pod.UID)][container.Name] = bestHint
|
|
||||||
|
|
||||||
err := s.allocateAlignedResources(pod, &container)
|
err := s.allocateAlignedResources(pod, &container)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user