From 709989efa2a039007c78ae1754fa4eb4a5fb5d79 Mon Sep 17 00:00:00 2001 From: nolancon Date: Wed, 5 Feb 2020 09:48:27 +0000 Subject: [PATCH] CPU Manager - Rename policy.AddContainer() to policy.Allocate() --- pkg/kubelet/cm/cpumanager/cpu_manager.go | 2 +- pkg/kubelet/cm/cpumanager/cpu_manager_test.go | 2 +- pkg/kubelet/cm/cpumanager/policy.go | 4 ++-- pkg/kubelet/cm/cpumanager/policy_none.go | 2 +- pkg/kubelet/cm/cpumanager/policy_none_test.go | 6 ++--- pkg/kubelet/cm/cpumanager/policy_static.go | 4 ++-- .../cm/cpumanager/policy_static_test.go | 24 +++++++++---------- 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/pkg/kubelet/cm/cpumanager/cpu_manager.go b/pkg/kubelet/cm/cpumanager/cpu_manager.go index 5c54897a25f..ab19c2fa80d 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_manager.go +++ b/pkg/kubelet/cm/cpumanager/cpu_manager.go @@ -232,7 +232,7 @@ func (m *manager) Allocate(p *v1.Pod, c *v1.Container) error { //} // Call down into the policy to assign this container CPUs if required. - err := m.policy.AddContainer(m.state, p, c) + err := m.policy.Allocate(m.state, p, c) if err != nil { klog.Errorf("[cpumanager] Allocate error: %v", err) return err diff --git a/pkg/kubelet/cm/cpumanager/cpu_manager_test.go b/pkg/kubelet/cm/cpumanager/cpu_manager_test.go index 451943e6d4b..ba74ab4c840 100644 --- a/pkg/kubelet/cm/cpumanager/cpu_manager_test.go +++ b/pkg/kubelet/cm/cpumanager/cpu_manager_test.go @@ -104,7 +104,7 @@ func (p *mockPolicy) Start(s state.State) error { return p.err } -func (p *mockPolicy) AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error { +func (p *mockPolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Container) error { return p.err } diff --git a/pkg/kubelet/cm/cpumanager/policy.go b/pkg/kubelet/cm/cpumanager/policy.go index 2031612be91..958dac0c2af 100644 --- a/pkg/kubelet/cm/cpumanager/policy.go +++ b/pkg/kubelet/cm/cpumanager/policy.go @@ -26,8 +26,8 @@ import ( type Policy interface { Name() string Start(s state.State) error - // AddContainer call is idempotent - AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error + // Allocate call is idempotent + Allocate(s state.State, pod *v1.Pod, container *v1.Container) error // RemoveContainer call is idempotent RemoveContainer(s state.State, podUID string, containerName string) error // GetTopologyHints implements the topologymanager.HintProvider Interface diff --git a/pkg/kubelet/cm/cpumanager/policy_none.go b/pkg/kubelet/cm/cpumanager/policy_none.go index 77cd367b642..bc71fe8f29d 100644 --- a/pkg/kubelet/cm/cpumanager/policy_none.go +++ b/pkg/kubelet/cm/cpumanager/policy_none.go @@ -44,7 +44,7 @@ func (p *nonePolicy) Start(s state.State) error { return nil } -func (p *nonePolicy) AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error { +func (p *nonePolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Container) error { return nil } diff --git a/pkg/kubelet/cm/cpumanager/policy_none_test.go b/pkg/kubelet/cm/cpumanager/policy_none_test.go index a28dfa6a0e9..d2dcbecdd2e 100644 --- a/pkg/kubelet/cm/cpumanager/policy_none_test.go +++ b/pkg/kubelet/cm/cpumanager/policy_none_test.go @@ -33,7 +33,7 @@ func TestNonePolicyName(t *testing.T) { } } -func TestNonePolicyAdd(t *testing.T) { +func TestNonePolicyAllocate(t *testing.T) { policy := &nonePolicy{} st := &mockState{ @@ -44,9 +44,9 @@ func TestNonePolicyAdd(t *testing.T) { testPod := makePod("fakePod", "fakeContainer", "1000m", "1000m") container := &testPod.Spec.Containers[0] - err := policy.AddContainer(st, testPod, container) + err := policy.Allocate(st, testPod, container) if err != nil { - t.Errorf("NonePolicy AddContainer() error. expected no error but got: %v", err) + t.Errorf("NonePolicy Allocate() error. expected no error but got: %v", err) } } diff --git a/pkg/kubelet/cm/cpumanager/policy_static.go b/pkg/kubelet/cm/cpumanager/policy_static.go index c088df866eb..ba80c0145bd 100644 --- a/pkg/kubelet/cm/cpumanager/policy_static.go +++ b/pkg/kubelet/cm/cpumanager/policy_static.go @@ -188,9 +188,9 @@ func (p *staticPolicy) assignableCPUs(s state.State) cpuset.CPUSet { return s.GetDefaultCPUSet().Difference(p.reserved) } -func (p *staticPolicy) AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error { +func (p *staticPolicy) Allocate(s state.State, pod *v1.Pod, container *v1.Container) error { if numCPUs := p.guaranteedCPUs(pod, container); numCPUs != 0 { - klog.Infof("[cpumanager] static policy: AddContainer (pod: %s, container: %s)", pod.Name, container.Name) + klog.Infof("[cpumanager] static policy: Allocate (pod: %s, container: %s)", pod.Name, container.Name) // container belongs in an exclusively allocated pool if _, ok := s.GetCPUSet(string(pod.UID), container.Name); ok { diff --git a/pkg/kubelet/cm/cpumanager/policy_static_test.go b/pkg/kubelet/cm/cpumanager/policy_static_test.go index 9e67692b459..ea2bcf11333 100644 --- a/pkg/kubelet/cm/cpumanager/policy_static_test.go +++ b/pkg/kubelet/cm/cpumanager/policy_static_test.go @@ -444,26 +444,26 @@ func TestStaticPolicyAdd(t *testing.T) { } container := &testCase.pod.Spec.Containers[0] - err := policy.AddContainer(st, testCase.pod, container) + err := policy.Allocate(st, testCase.pod, container) if !reflect.DeepEqual(err, testCase.expErr) { - t.Errorf("StaticPolicy AddContainer() error (%v). expected add error: %v but got: %v", + t.Errorf("StaticPolicy Allocate() error (%v). expected add error: %v but got: %v", testCase.description, testCase.expErr, err) } if testCase.expCPUAlloc { cset, found := st.assignments[string(testCase.pod.UID)][container.Name] if !found { - t.Errorf("StaticPolicy AddContainer() error (%v). expected container %v to be present in assignments %v", + t.Errorf("StaticPolicy Allocate() error (%v). expected container %v to be present in assignments %v", testCase.description, container.Name, st.assignments) } if !reflect.DeepEqual(cset, testCase.expCSet) { - t.Errorf("StaticPolicy AddContainer() error (%v). expected cpuset %v but got %v", + t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v but got %v", testCase.description, testCase.expCSet, cset) } if !cset.Intersection(st.defaultCPUSet).IsEmpty() { - t.Errorf("StaticPolicy AddContainer() error (%v). expected cpuset %v to be disoint from the shared cpuset %v", + t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v to be disoint from the shared cpuset %v", testCase.description, cset, st.defaultCPUSet) } } @@ -471,7 +471,7 @@ func TestStaticPolicyAdd(t *testing.T) { if !testCase.expCPUAlloc { _, found := st.assignments[string(testCase.pod.UID)][container.Name] if found { - t.Errorf("StaticPolicy AddContainer() error (%v). Did not expect container %v to be present in assignments %v", + t.Errorf("StaticPolicy Allocate() error (%v). Did not expect container %v to be present in assignments %v", testCase.description, container.Name, st.assignments) } } @@ -786,26 +786,26 @@ func TestStaticPolicyAddWithResvList(t *testing.T) { } container := &testCase.pod.Spec.Containers[0] - err := policy.AddContainer(st, testCase.pod, container) + err := policy.Allocate(st, testCase.pod, container) if !reflect.DeepEqual(err, testCase.expErr) { - t.Errorf("StaticPolicy AddContainer() error (%v). expected add error: %v but got: %v", + t.Errorf("StaticPolicy Allocate() error (%v). expected add error: %v but got: %v", testCase.description, testCase.expErr, err) } if testCase.expCPUAlloc { cset, found := st.assignments[string(testCase.pod.UID)][container.Name] if !found { - t.Errorf("StaticPolicy AddContainer() error (%v). expected container %v to be present in assignments %v", + t.Errorf("StaticPolicy Allocate() error (%v). expected container %v to be present in assignments %v", testCase.description, container.Name, st.assignments) } if !reflect.DeepEqual(cset, testCase.expCSet) { - t.Errorf("StaticPolicy AddContainer() error (%v). expected cpuset %v but got %v", + t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v but got %v", testCase.description, testCase.expCSet, cset) } if !cset.Intersection(st.defaultCPUSet).IsEmpty() { - t.Errorf("StaticPolicy AddContainer() error (%v). expected cpuset %v to be disoint from the shared cpuset %v", + t.Errorf("StaticPolicy Allocate() error (%v). expected cpuset %v to be disoint from the shared cpuset %v", testCase.description, cset, st.defaultCPUSet) } } @@ -813,7 +813,7 @@ func TestStaticPolicyAddWithResvList(t *testing.T) { if !testCase.expCPUAlloc { _, found := st.assignments[string(testCase.pod.UID)][container.Name] if found { - t.Errorf("StaticPolicy AddContainer() error (%v). Did not expect container %v to be present in assignments %v", + t.Errorf("StaticPolicy Allocate() error (%v). Did not expect container %v to be present in assignments %v", testCase.description, container.Name, st.assignments) } }