Skip to content

Commit bc01306

Browse files
authored
Merge pull request kubernetes#116738 from AxeZhan/TopologyManagerPolicy
When TopologyManagerPolicy is None, skip checks in NewManager.
2 parents 50782ce + 4e928c9 commit bc01306

File tree

6 files changed

+61
-16
lines changed

6 files changed

+61
-16
lines changed

pkg/kubelet/cm/topologymanager/scope.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ const (
3131
containerTopologyScope = "container"
3232
// podTopologyScope specifies the TopologyManagerScope per pod.
3333
podTopologyScope = "pod"
34+
// noneTopologyScope specifies the TopologyManagerScope when topologyPolicyName is none.
35+
noneTopologyScope = "none"
3436
)
3537

3638
type podTopologyHints map[string]map[string]TopologyHint

pkg/kubelet/cm/topologymanager/scope_container.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ func NewContainerScope(policy Policy) Scope {
4545
}
4646

4747
func (s *containerScope) Admit(pod *v1.Pod) lifecycle.PodAdmitResult {
48-
// Exception - Policy : none
49-
if s.policy.Name() == PolicyNone {
50-
return s.admitPolicyNone(pod)
51-
}
52-
5348
for _, container := range append(pod.Spec.InitContainers, pod.Spec.Containers...) {
5449
bestHint, admit := s.calculateAffinity(pod, &container)
5550
klog.InfoS("Best TopologyHint", "bestHint", bestHint, "pod", klog.KObj(pod), "containerName", container.Name)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
Copyright 2023 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package topologymanager
18+
19+
import (
20+
"k8s.io/api/core/v1"
21+
"k8s.io/kubernetes/pkg/kubelet/cm/containermap"
22+
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
23+
)
24+
25+
type noneScope struct {
26+
scope
27+
}
28+
29+
// Ensure noneScope implements Scope interface
30+
var _ Scope = &noneScope{}
31+
32+
// NewNoneScope returns a none scope.
33+
func NewNoneScope() Scope {
34+
return &noneScope{
35+
scope{
36+
name: noneTopologyScope,
37+
podTopologyHints: podTopologyHints{},
38+
policy: NewNonePolicy(),
39+
podMap: containermap.NewContainerMap(),
40+
},
41+
}
42+
}
43+
44+
func (s *noneScope) Admit(pod *v1.Pod) lifecycle.PodAdmitResult {
45+
return s.admitPolicyNone(pod)
46+
}

pkg/kubelet/cm/topologymanager/scope_pod.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ func NewPodScope(policy Policy) Scope {
4545
}
4646

4747
func (s *podScope) Admit(pod *v1.Pod) lifecycle.PodAdmitResult {
48-
// Exception - Policy : none
49-
if s.policy.Name() == PolicyNone {
50-
return s.admitPolicyNone(pod)
51-
}
52-
5348
bestHint, admit := s.calculateAffinity(pod)
5449
klog.InfoS("Best TopologyHint", "bestHint", bestHint, "pod", klog.KObj(pod))
5550
if !admit {

pkg/kubelet/cm/topologymanager/topology_manager.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ var _ Manager = &manager{}
135135
func NewManager(topology []cadvisorapi.Node, topologyPolicyName string, topologyScopeName string, topologyPolicyOptions map[string]string) (Manager, error) {
136136
klog.InfoS("Creating topology manager with policy per scope", "topologyPolicyName", topologyPolicyName, "topologyScopeName", topologyScopeName)
137137

138+
// When policy is none, the scope is not relevant, so we can short circuit here.
139+
if topologyPolicyName == PolicyNone {
140+
return &manager{scope: NewNoneScope()}, nil
141+
}
142+
138143
opts, err := NewPolicyOptions(topologyPolicyOptions)
139144
if err != nil {
140145
return nil, err
@@ -152,9 +157,6 @@ func NewManager(topology []cadvisorapi.Node, topologyPolicyName string, topology
152157
var policy Policy
153158
switch topologyPolicyName {
154159

155-
case PolicyNone:
156-
policy = NewNonePolicy()
157-
158160
case PolicyBestEffort:
159161
policy = NewBestEffortPolicy(numaInfo, opts)
160162

pkg/kubelet/cm/topologymanager/topology_manager_test.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,14 @@ func TestNewManager(t *testing.T) {
9898
}
9999
} else {
100100
rawMgr := mngr.(*manager)
101-
rawScope := rawMgr.scope.(*containerScope)
102-
if rawScope.policy.Name() != tc.expectedPolicy {
103-
t.Errorf("Unexpected policy name. Have: %q wants %q", rawScope.policy.Name(), tc.expectedPolicy)
101+
var policyName string
102+
if rawScope, ok := rawMgr.scope.(*containerScope); ok {
103+
policyName = rawScope.policy.Name()
104+
} else if rawScope, ok := rawMgr.scope.(*noneScope); ok {
105+
policyName = rawScope.policy.Name()
106+
}
107+
if policyName != tc.expectedPolicy {
108+
t.Errorf("Unexpected policy name. Have: %q wants %q", policyName, tc.expectedPolicy)
104109
}
105110
}
106111
}

0 commit comments

Comments
 (0)