Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid undesirable allocation when device is associated with multiple … #101893

Merged
merged 7 commits into from
May 21, 2021
50 changes: 39 additions & 11 deletions pkg/kubelet/cm/devicemanager/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/config"
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
"k8s.io/kubernetes/pkg/kubelet/pluginmanager"
"k8s.io/kubernetes/pkg/kubelet/util/format"
schedulerframework "k8s.io/kubernetes/pkg/scheduler/framework"
)

Expand Down Expand Up @@ -720,8 +721,13 @@ func TestFilterByAffinity(t *testing.T) {
},
}

fakeAffinity, _ := bitmask.NewBitMask(2)
fakeHint := topologymanager.TopologyHint{
NUMANodeAffinity: fakeAffinity,
Preferred: true,
}
testManager := ManagerImpl{
topologyAffinityStore: newFakeTopologyManager(),
topologyAffinityStore: NewFakeTopologyManagerWithHint(t, &fakeHint),
allDevices: allDevices,
}

Expand Down Expand Up @@ -753,23 +759,45 @@ func TestFilterByAffinity(t *testing.T) {
}
}

type fakeTopologyManager struct {
topologymanager.Manager
type fakeTopologyManagerWithHint struct {
t *testing.T
hint *topologymanager.TopologyHint
}

// NewFakeTopologyManagerWithHint returns an instance of fake topology manager with specified topology hints
func NewFakeTopologyManagerWithHint(t *testing.T, hint *topologymanager.TopologyHint) topologymanager.Manager {
return &fakeTopologyManagerWithHint{
t: t,
kikimo marked this conversation as resolved.
Show resolved Hide resolved
hint: hint,
}
}

func newFakeTopologyManager() topologymanager.Manager {
return &fakeTopologyManager{}
func (m *fakeTopologyManagerWithHint) AddHintProvider(h topologymanager.HintProvider) {
m.t.Logf("[fake topologymanager] AddHintProvider HintProvider: %v", h)
}

func (m *fakeTopologyManager) GetAffinity(podUID string, containerName string) topologymanager.TopologyHint {
// return hint with numa2 set
affinity, _ := bitmask.NewBitMask(2)
return topologymanager.TopologyHint{
NUMANodeAffinity: affinity,
Preferred: true,
func (m *fakeTopologyManagerWithHint) AddContainer(pod *v1.Pod, containerID string) error {
m.t.Logf("[fake topologymanager] AddContainer pod: %v container id: %v", format.Pod(pod), containerID)
return nil
}

func (m *fakeTopologyManagerWithHint) RemoveContainer(containerID string) error {
m.t.Logf("[fake topologymanager] RemoveContainer container id: %v", containerID)
return nil
}

func (m *fakeTopologyManagerWithHint) Admit(attrs *lifecycle.PodAdmitAttributes) lifecycle.PodAdmitResult {
m.t.Logf("[fake topologymanager] Topology Admit Handler")
return lifecycle.PodAdmitResult{
Admit: true,
}
}

func (m *fakeTopologyManagerWithHint) GetAffinity(podUID string, containerName string) topologymanager.TopologyHint {
m.t.Logf("[fake topologymanager] GetAffinity podUID: %v container name: %v", podUID, containerName)
return *m.hint
}

func TestPodContainerDeviceAllocation(t *testing.T) {
res1 := TestResource{
resourceName: "domain1.com/resource1",
Expand Down