CPU Manager - Rename policy.AddContainer() to policy.Allocate()

This commit is contained in:
nolancon 2020-02-05 09:48:27 +00:00
parent 0d68bffd03
commit 709989efa2
7 changed files with 22 additions and 22 deletions

View File

@ -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. // 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 { if err != nil {
klog.Errorf("[cpumanager] Allocate error: %v", err) klog.Errorf("[cpumanager] Allocate error: %v", err)
return err return err

View File

@ -104,7 +104,7 @@ func (p *mockPolicy) Start(s state.State) error {
return p.err 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 return p.err
} }

View File

@ -26,8 +26,8 @@ import (
type Policy interface { type Policy interface {
Name() string Name() string
Start(s state.State) error Start(s state.State) error
// AddContainer call is idempotent // Allocate call is idempotent
AddContainer(s state.State, pod *v1.Pod, container *v1.Container) error Allocate(s state.State, pod *v1.Pod, container *v1.Container) error
// RemoveContainer call is idempotent // RemoveContainer call is idempotent
RemoveContainer(s state.State, podUID string, containerName string) error RemoveContainer(s state.State, podUID string, containerName string) error
// GetTopologyHints implements the topologymanager.HintProvider Interface // GetTopologyHints implements the topologymanager.HintProvider Interface

View File

@ -44,7 +44,7 @@ func (p *nonePolicy) Start(s state.State) error {
return nil 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 return nil
} }

View File

@ -33,7 +33,7 @@ func TestNonePolicyName(t *testing.T) {
} }
} }
func TestNonePolicyAdd(t *testing.T) { func TestNonePolicyAllocate(t *testing.T) {
policy := &nonePolicy{} policy := &nonePolicy{}
st := &mockState{ st := &mockState{
@ -44,9 +44,9 @@ func TestNonePolicyAdd(t *testing.T) {
testPod := makePod("fakePod", "fakeContainer", "1000m", "1000m") testPod := makePod("fakePod", "fakeContainer", "1000m", "1000m")
container := &testPod.Spec.Containers[0] container := &testPod.Spec.Containers[0]
err := policy.AddContainer(st, testPod, container) err := policy.Allocate(st, testPod, container)
if err != nil { 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)
} }
} }

View File

@ -188,9 +188,9 @@ func (p *staticPolicy) assignableCPUs(s state.State) cpuset.CPUSet {
return s.GetDefaultCPUSet().Difference(p.reserved) 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 { 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 // container belongs in an exclusively allocated pool
if _, ok := s.GetCPUSet(string(pod.UID), container.Name); ok { if _, ok := s.GetCPUSet(string(pod.UID), container.Name); ok {

View File

@ -444,26 +444,26 @@ func TestStaticPolicyAdd(t *testing.T) {
} }
container := &testCase.pod.Spec.Containers[0] 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) { 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) testCase.description, testCase.expErr, err)
} }
if testCase.expCPUAlloc { if testCase.expCPUAlloc {
cset, found := st.assignments[string(testCase.pod.UID)][container.Name] cset, found := st.assignments[string(testCase.pod.UID)][container.Name]
if !found { 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) testCase.description, container.Name, st.assignments)
} }
if !reflect.DeepEqual(cset, testCase.expCSet) { 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) testCase.description, testCase.expCSet, cset)
} }
if !cset.Intersection(st.defaultCPUSet).IsEmpty() { 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) testCase.description, cset, st.defaultCPUSet)
} }
} }
@ -471,7 +471,7 @@ func TestStaticPolicyAdd(t *testing.T) {
if !testCase.expCPUAlloc { if !testCase.expCPUAlloc {
_, found := st.assignments[string(testCase.pod.UID)][container.Name] _, found := st.assignments[string(testCase.pod.UID)][container.Name]
if found { 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) testCase.description, container.Name, st.assignments)
} }
} }
@ -786,26 +786,26 @@ func TestStaticPolicyAddWithResvList(t *testing.T) {
} }
container := &testCase.pod.Spec.Containers[0] 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) { 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) testCase.description, testCase.expErr, err)
} }
if testCase.expCPUAlloc { if testCase.expCPUAlloc {
cset, found := st.assignments[string(testCase.pod.UID)][container.Name] cset, found := st.assignments[string(testCase.pod.UID)][container.Name]
if !found { 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) testCase.description, container.Name, st.assignments)
} }
if !reflect.DeepEqual(cset, testCase.expCSet) { 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) testCase.description, testCase.expCSet, cset)
} }
if !cset.Intersection(st.defaultCPUSet).IsEmpty() { 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) testCase.description, cset, st.defaultCPUSet)
} }
} }
@ -813,7 +813,7 @@ func TestStaticPolicyAddWithResvList(t *testing.T) {
if !testCase.expCPUAlloc { if !testCase.expCPUAlloc {
_, found := st.assignments[string(testCase.pod.UID)][container.Name] _, found := st.assignments[string(testCase.pod.UID)][container.Name]
if found { 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) testCase.description, container.Name, st.assignments)
} }
} }