mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 18:02:01 +00:00
Merge pull request #95111 from choury/patch-2
make podTopologyHints protected by lock
This commit is contained in:
commit
889cf714c1
@ -68,10 +68,26 @@ func (s *scope) Name() string {
|
||||
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]
|
||||
}
|
||||
|
||||
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) {
|
||||
s.hintProviders = append(s.hintProviders, h)
|
||||
}
|
||||
|
@ -55,13 +55,9 @@ func (s *containerScope) Admit(pod *v1.Pod) lifecycle.PodAdmitResult {
|
||||
if !admit {
|
||||
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)
|
||||
(s.podTopologyHints)[string(pod.UID)][container.Name] = bestHint
|
||||
s.setTopologyHints(string(pod.UID), container.Name, bestHint)
|
||||
|
||||
err := s.allocateAlignedResources(pod, &container)
|
||||
if err != nil {
|
||||
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...) {
|
||||
klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), 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
|
||||
s.setTopologyHints(string(pod.UID), container.Name, bestHint)
|
||||
|
||||
err := s.allocateAlignedResources(pod, &container)
|
||||
if err != nil {
|
||||
|
Loading…
Reference in New Issue
Block a user