Merge pull request #99969 from knabben/sl-topologymanager

Migrate pkg/kubelet/cm/topologymanager to structure logging
This commit is contained in:
Kubernetes Prow Robot 2021-03-16 14:49:39 -07:00 committed by GitHub
commit 81a1a793a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 20 additions and 23 deletions

View File

@ -20,38 +20,37 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/klog/v2" "k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/kubelet/lifecycle" "k8s.io/kubernetes/pkg/kubelet/lifecycle"
"k8s.io/kubernetes/pkg/kubelet/util/format"
) )
type fakeManager struct{} type fakeManager struct{}
//NewFakeManager returns an instance of FakeManager //NewFakeManager returns an instance of FakeManager
func NewFakeManager() Manager { func NewFakeManager() Manager {
klog.Infof("[fake topologymanager] NewFakeManager") klog.InfoS("NewFakeManager")
return &fakeManager{} return &fakeManager{}
} }
func (m *fakeManager) GetAffinity(podUID string, containerName string) TopologyHint { func (m *fakeManager) GetAffinity(podUID string, containerName string) TopologyHint {
klog.Infof("[fake topologymanager] GetAffinity pod: %v container name: %v", podUID, containerName) klog.InfoS("GetAffinity", "podUID", podUID, "containerName", containerName)
return TopologyHint{} return TopologyHint{}
} }
func (m *fakeManager) AddHintProvider(h HintProvider) { func (m *fakeManager) AddHintProvider(h HintProvider) {
klog.Infof("[fake topologymanager] AddHintProvider HintProvider: %v", h) klog.InfoS("AddHintProvider", "hintProvider", h)
} }
func (m *fakeManager) AddContainer(pod *v1.Pod, containerID string) error { func (m *fakeManager) AddContainer(pod *v1.Pod, containerID string) error {
klog.Infof("[fake topologymanager] AddContainer pod: %v container id: %v", format.Pod(pod), containerID) klog.InfoS("AddContainer", "pod", klog.KObj(pod), "containerID", containerID)
return nil return nil
} }
func (m *fakeManager) RemoveContainer(containerID string) error { func (m *fakeManager) RemoveContainer(containerID string) error {
klog.Infof("[fake topologymanager] RemoveContainer container id: %v", containerID) klog.InfoS("RemoveContainer", "containerID", containerID)
return nil return nil
} }
func (m *fakeManager) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult { func (m *fakeManager) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult {
klog.Infof("[fake topologymanager] Topology Admit Handler") klog.InfoS("Topology Admit Handler")
return lifecycle.PodAdmitResult{ return lifecycle.PodAdmitResult{
Admit: true, Admit: true,
} }

View File

@ -67,7 +67,7 @@ func filterProvidersHints(providersHints []map[string][]TopologyHint) [][]Topolo
for _, hints := range providersHints { for _, hints := range providersHints {
// If hints is nil, insert a single, preferred any-numa hint into allProviderHints. // If hints is nil, insert a single, preferred any-numa hint into allProviderHints.
if len(hints) == 0 { if len(hints) == 0 {
klog.Infof("[topologymanager] Hint Provider has no preference for NUMA affinity with any resource") klog.InfoS("Hint Provider has no preference for NUMA affinity with any resource")
allProviderHints = append(allProviderHints, []TopologyHint{{nil, true}}) allProviderHints = append(allProviderHints, []TopologyHint{{nil, true}})
continue continue
} }
@ -75,13 +75,13 @@ func filterProvidersHints(providersHints []map[string][]TopologyHint) [][]Topolo
// Otherwise, accumulate the hints for each resource type into allProviderHints. // Otherwise, accumulate the hints for each resource type into allProviderHints.
for resource := range hints { for resource := range hints {
if hints[resource] == nil { if hints[resource] == nil {
klog.Infof("[topologymanager] Hint Provider has no preference for NUMA affinity with resource '%s'", resource) klog.InfoS("Hint Provider has no preference for NUMA affinity with resource", "resource", resource)
allProviderHints = append(allProviderHints, []TopologyHint{{nil, true}}) allProviderHints = append(allProviderHints, []TopologyHint{{nil, true}})
continue continue
} }
if len(hints[resource]) == 0 { if len(hints[resource]) == 0 {
klog.Infof("[topologymanager] Hint Provider has no possible NUMA affinities for resource '%s'", resource) klog.InfoS("Hint Provider has no possible NUMA affinities for resource", "resource", resource)
allProviderHints = append(allProviderHints, []TopologyHint{{nil, false}}) allProviderHints = append(allProviderHints, []TopologyHint{{nil, false}})
continue continue
} }

View File

@ -108,7 +108,7 @@ func (s *scope) RemoveContainer(containerID string) error {
s.mutex.Lock() s.mutex.Lock()
defer s.mutex.Unlock() defer s.mutex.Unlock()
klog.Infof("[topologymanager] RemoveContainer - Container ID: %v", containerID) klog.InfoS("RemoveContainer", "containerID", containerID)
podUIDString := s.podMap[containerID] podUIDString := s.podMap[containerID]
delete(s.podMap, containerID) delete(s.podMap, containerID)
if _, exists := s.podTopologyHints[podUIDString]; exists { if _, exists := s.podTopologyHints[podUIDString]; exists {

View File

@ -20,7 +20,6 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/klog/v2" "k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/kubelet/lifecycle" "k8s.io/kubernetes/pkg/kubelet/lifecycle"
"k8s.io/kubernetes/pkg/kubelet/util/format"
) )
type containerScope struct { type containerScope struct {
@ -50,12 +49,12 @@ func (s *containerScope) 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...) {
bestHint, admit := s.calculateAffinity(pod, &container) bestHint, admit := s.calculateAffinity(pod, &container)
klog.Infof("[topologymanager] Best TopologyHint for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint) klog.InfoS("Best TopologyHint", "bestHint", bestHint, "pod", klog.KObj(pod), "containerName", container.Name)
if !admit { if !admit {
return topologyAffinityError() return topologyAffinityError()
} }
klog.Infof("[topologymanager] Topology Affinity for (pod: %v container: %v): %v", format.Pod(pod), container.Name, bestHint) klog.InfoS("Topology Affinity", "bestHint", bestHint, "pod", klog.KObj(pod), "containerName", container.Name)
s.setTopologyHints(string(pod.UID), container.Name, bestHint) s.setTopologyHints(string(pod.UID), container.Name, bestHint)
err := s.allocateAlignedResources(pod, &container) err := s.allocateAlignedResources(pod, &container)
@ -73,7 +72,7 @@ func (s *containerScope) accumulateProvidersHints(pod *v1.Pod, container *v1.Con
// Get the TopologyHints for a Container from a provider. // Get the TopologyHints for a Container from a provider.
hints := provider.GetTopologyHints(pod, container) hints := provider.GetTopologyHints(pod, container)
providersHints = append(providersHints, hints) providersHints = append(providersHints, hints)
klog.Infof("[topologymanager] TopologyHints for pod '%v', container '%v': %v", format.Pod(pod), container.Name, hints) klog.InfoS("TopologyHints", "hints", hints, "pod", klog.KObj(pod), "containerName", container.Name)
} }
return providersHints return providersHints
} }
@ -81,6 +80,6 @@ func (s *containerScope) accumulateProvidersHints(pod *v1.Pod, container *v1.Con
func (s *containerScope) calculateAffinity(pod *v1.Pod, container *v1.Container) (TopologyHint, bool) { func (s *containerScope) calculateAffinity(pod *v1.Pod, container *v1.Container) (TopologyHint, bool) {
providersHints := s.accumulateProvidersHints(pod, container) providersHints := s.accumulateProvidersHints(pod, container)
bestHint, admit := s.policy.Merge(providersHints) bestHint, admit := s.policy.Merge(providersHints)
klog.Infof("[topologymanager] ContainerTopologyHint: %v", bestHint) klog.InfoS("ContainerTopologyHint", "bestHint", bestHint)
return bestHint, admit return bestHint, admit
} }

View File

@ -20,7 +20,6 @@ import (
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/klog/v2" "k8s.io/klog/v2"
"k8s.io/kubernetes/pkg/kubelet/lifecycle" "k8s.io/kubernetes/pkg/kubelet/lifecycle"
"k8s.io/kubernetes/pkg/kubelet/util/format"
) )
type podScope struct { type podScope struct {
@ -49,13 +48,13 @@ func (s *podScope) Admit(pod *v1.Pod) lifecycle.PodAdmitResult {
} }
bestHint, admit := s.calculateAffinity(pod) bestHint, admit := s.calculateAffinity(pod)
klog.Infof("[topologymanager] Best TopologyHint for (pod: %v): %v", format.Pod(pod), bestHint) klog.InfoS("Best TopologyHint", "bestHint", bestHint, "pod", klog.KObj(pod))
if !admit { if !admit {
return topologyAffinityError() return topologyAffinityError()
} }
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.InfoS("Topology Affinity", "bestHint", bestHint, "pod", klog.KObj(pod), "containerName", container.Name)
s.setTopologyHints(string(pod.UID), container.Name, bestHint) s.setTopologyHints(string(pod.UID), container.Name, bestHint)
err := s.allocateAlignedResources(pod, &container) err := s.allocateAlignedResources(pod, &container)
@ -73,7 +72,7 @@ func (s *podScope) accumulateProvidersHints(pod *v1.Pod) []map[string][]Topology
// Get the TopologyHints for a Pod from a provider. // Get the TopologyHints for a Pod from a provider.
hints := provider.GetPodTopologyHints(pod) hints := provider.GetPodTopologyHints(pod)
providersHints = append(providersHints, hints) providersHints = append(providersHints, hints)
klog.Infof("[topologymanager] TopologyHints for pod '%v': %v", format.Pod(pod), hints) klog.InfoS("TopologyHints", "hints", hints, "pod", klog.KObj(pod))
} }
return providersHints return providersHints
} }
@ -81,6 +80,6 @@ func (s *podScope) accumulateProvidersHints(pod *v1.Pod) []map[string][]Topology
func (s *podScope) calculateAffinity(pod *v1.Pod) (TopologyHint, bool) { func (s *podScope) calculateAffinity(pod *v1.Pod) (TopologyHint, bool) {
providersHints := s.accumulateProvidersHints(pod) providersHints := s.accumulateProvidersHints(pod)
bestHint, admit := s.policy.Merge(providersHints) bestHint, admit := s.policy.Merge(providersHints)
klog.Infof("[topologymanager] PodTopologyHint: %v", bestHint) klog.InfoS("PodTopologyHint", "bestHint", bestHint)
return bestHint, admit return bestHint, admit
} }

View File

@ -117,7 +117,7 @@ var _ Manager = &manager{}
// NewManager creates a new TopologyManager based on provided policy and scope // NewManager creates a new TopologyManager based on provided policy and scope
func NewManager(topology []cadvisorapi.Node, topologyPolicyName string, topologyScopeName string) (Manager, error) { func NewManager(topology []cadvisorapi.Node, topologyPolicyName string, topologyScopeName string) (Manager, error) {
klog.Infof("[topologymanager] Creating topology manager with %s policy per %s scope", topologyPolicyName, topologyScopeName) klog.InfoS("Creating topology manager with policy per scope", "topologyPolicyName", topologyPolicyName, "topologyScopeName", topologyScopeName)
var numaNodes []int var numaNodes []int
for _, node := range topology { for _, node := range topology {
@ -184,7 +184,7 @@ func (m *manager) RemoveContainer(containerID string) error {
} }
func (m *manager) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult { func (m *manager) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult {
klog.Infof("[topologymanager] Topology Admit Handler") klog.InfoS("Topology Admit Handler")
pod := attrs.Pod pod := attrs.Pod
return m.scope.Admit(pod) return m.scope.Admit(pod)