Skip to content

Commit 709989e

Browse files
author
nolancon
committed
CPU Manager - Rename policy.AddContainer() to policy.Allocate()
1 parent 0d68bff commit 709989e

File tree

7 files changed

+22
-22
lines changed

7 files changed

+22
-22
lines changed

pkg/kubelet/cm/cpumanager/cpu_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ func (m *manager) Allocate(p *v1.Pod, c *v1.Container) error {
232232
//}
233233

234234
// Call down into the policy to assign this container CPUs if required.
235-
err := m.policy.AddContainer(m.state, p, c)
235+
err := m.policy.Allocate(m.state, p, c)
236236
if err != nil {
237237
klog.Errorf("[cpumanager] Allocate error: %v", err)
238238
return err

pkg/kubelet/cm/cpumanager/cpu_manager_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (p *mockPolicy) Start(s state.State) error {
104104
return p.err
105105
}
106106

107-
func (p *mockPolicy) AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error {
107+
func (p *mockPolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Container) error {
108108
return p.err
109109
}
110110

pkg/kubelet/cm/cpumanager/policy.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ import (
2626
type Policy interface {
2727
Name() string
2828
Start(s state.State) error
29-
// AddContainer call is idempotent
30-
AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error
29+
// Allocate call is idempotent
30+
Allocate(s state.State, pod *v1.Pod, container *v1.Container) error
3131
// RemoveContainer call is idempotent
3232
RemoveContainer(s state.State, podUID string, containerName string) error
3333
// GetTopologyHints implements the topologymanager.HintProvider Interface

pkg/kubelet/cm/cpumanager/policy_none.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func (p *nonePolicy) Start(s state.State) error {
4444
return nil
4545
}
4646

47-
func (p *nonePolicy) AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error {
47+
func (p *nonePolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Container) error {
4848
return nil
4949
}
5050

pkg/kubelet/cm/cpumanager/policy_none_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func TestNonePolicyName(t *testing.T) {
3333
}
3434
}
3535

36-
func TestNonePolicyAdd(t *testing.T) {
36+
func TestNonePolicyAllocate(t *testing.T) {
3737
policy := &nonePolicy{}
3838

3939
st := &mockState{
@@ -44,9 +44,9 @@ func TestNonePolicyAdd(t *testing.T) {
4444
testPod := makePod("fakePod", "fakeContainer", "1000m", "1000m")
4545

4646
container := &testPod.Spec.Containers[0]
47-
err := policy.AddContainer(st, testPod, container)
47+
err := policy.Allocate(st, testPod, container)
4848
if err != nil {
49-
t.Errorf("NonePolicy AddContainer() error. expected no error but got: %v", err)
49+
t.Errorf("NonePolicy Allocate() error. expected no error but got: %v", err)
5050
}
5151
}
5252

pkg/kubelet/cm/cpumanager/policy_static.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,9 @@ func (p *staticPolicy) assignableCPUs(s state.State) cpuset.CPUSet {
188188
return s.GetDefaultCPUSet().Difference(p.reserved)
189189
}
190190

191-
func (p *staticPolicy) AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error {
191+
func (p *staticPolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Container) error {
192192
if numCPUs := p.guaranteedCPUs(pod, container); numCPUs != 0 {
193-
klog.Infof("[cpumanager] static policy: AddContainer (pod: %s, container: %s)", pod.Name, container.Name)
193+
klog.Infof("[cpumanager] static policy: Allocate (pod: %s, container: %s)", pod.Name, container.Name)
194194
// container belongs in an exclusively allocated pool
195195

196196
if _, ok := s.GetCPUSet(string(pod.UID), container.Name); ok {

pkg/kubelet/cm/cpumanager/policy_static_test.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -444,34 +444,34 @@ func TestStaticPolicyAdd(t *testing.T) {
444444
}
445445

446446
container := &testCase.pod.Spec.Containers[0]
447-
err := policy.AddContainer(st, testCase.pod, container)
447+
err := policy.Allocate(st, testCase.pod, container)
448448
if !reflect.DeepEqual(err, testCase.expErr) {
449-
t.Errorf("StaticPolicy AddContainer() error (%v). expected add error: %v but got: %v",
449+
t.Errorf("StaticPolicy Allocate() error (%v). expected add error: %v but got: %v",
450450
testCase.description, testCase.expErr, err)
451451
}
452452

453453
if testCase.expCPUAlloc {
454454
cset, found := st.assignments[string(testCase.pod.UID)][container.Name]
455455
if !found {
456-
t.Errorf("StaticPolicy AddContainer() error (%v). expected container %v to be present in assignments %v",
456+
t.Errorf("StaticPolicy Allocate() error (%v). expected container %v to be present in assignments %v",
457457
testCase.description, container.Name, st.assignments)
458458
}
459459

460460
if !reflect.DeepEqual(cset, testCase.expCSet) {
461-
t.Errorf("StaticPolicy AddContainer() error (%v). expected cpuset %v but got %v",
461+
t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v but got %v",
462462
testCase.description, testCase.expCSet, cset)
463463
}
464464

465465
if !cset.Intersection(st.defaultCPUSet).IsEmpty() {
466-
t.Errorf("StaticPolicy AddContainer() error (%v). expected cpuset %v to be disoint from the shared cpuset %v",
466+
t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v to be disoint from the shared cpuset %v",
467467
testCase.description, cset, st.defaultCPUSet)
468468
}
469469
}
470470

471471
if !testCase.expCPUAlloc {
472472
_, found := st.assignments[string(testCase.pod.UID)][container.Name]
473473
if found {
474-
t.Errorf("StaticPolicy AddContainer() error (%v). Did not expect container %v to be present in assignments %v",
474+
t.Errorf("StaticPolicy Allocate() error (%v). Did not expect container %v to be present in assignments %v",
475475
testCase.description, container.Name, st.assignments)
476476
}
477477
}
@@ -786,34 +786,34 @@ func TestStaticPolicyAddWithResvList(t *testing.T) {
786786
}
787787

788788
container := &testCase.pod.Spec.Containers[0]
789-
err := policy.AddContainer(st, testCase.pod, container)
789+
err := policy.Allocate(st, testCase.pod, container)
790790
if !reflect.DeepEqual(err, testCase.expErr) {
791-
t.Errorf("StaticPolicy AddContainer() error (%v). expected add error: %v but got: %v",
791+
t.Errorf("StaticPolicy Allocate() error (%v). expected add error: %v but got: %v",
792792
testCase.description, testCase.expErr, err)
793793
}
794794

795795
if testCase.expCPUAlloc {
796796
cset, found := st.assignments[string(testCase.pod.UID)][container.Name]
797797
if !found {
798-
t.Errorf("StaticPolicy AddContainer() error (%v). expected container %v to be present in assignments %v",
798+
t.Errorf("StaticPolicy Allocate() error (%v). expected container %v to be present in assignments %v",
799799
testCase.description, container.Name, st.assignments)
800800
}
801801

802802
if !reflect.DeepEqual(cset, testCase.expCSet) {
803-
t.Errorf("StaticPolicy AddContainer() error (%v). expected cpuset %v but got %v",
803+
t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v but got %v",
804804
testCase.description, testCase.expCSet, cset)
805805
}
806806

807807
if !cset.Intersection(st.defaultCPUSet).IsEmpty() {
808-
t.Errorf("StaticPolicy AddContainer() error (%v). expected cpuset %v to be disoint from the shared cpuset %v",
808+
t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v to be disoint from the shared cpuset %v",
809809
testCase.description, cset, st.defaultCPUSet)
810810
}
811811
}
812812

813813
if !testCase.expCPUAlloc {
814814
_, found := st.assignments[string(testCase.pod.UID)][container.Name]
815815
if found {
816-
t.Errorf("StaticPolicy AddContainer() error (%v). Did not expect container %v to be present in assignments %v",
816+
t.Errorf("StaticPolicy Allocate() error (%v). Did not expect container %v to be present in assignments %v",
817817
testCase.description, container.Name, st.assignments)
818818
}
819819
}

0 commit comments

Comments
 (0)