Skip to content

Commit

Permalink
topology-aware: update docs, mock tests.
Browse files Browse the repository at this point in the history
Update docs with a brief mention of how to enable topology hints
based on Pod Resource API queries. Make mock tests compile again.

Signed-off-by: Krisztian Litkey <[email protected]>
  • Loading branch information
klihub committed Dec 2, 2024
1 parent fcaed53 commit 5fb185a
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
4 changes: 2 additions & 2 deletions cmd/plugins/topology-aware/policy/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ func TestAllocationMarshalling(t *testing.T) {
}{
{
name: "non-zero Exclusive",
data: []byte(`{"key1":{"Exclusive":"1","Part":1,"CPUType":0,"Container":"1","Pool":"testnode","MemoryPool":0,"MemType":"DRAM,PMEM,HBM","MemSize":0,"ColdStart":0}}`),
data: []byte(`{"key1":{"PrettyName":"","Exclusive":"1","Part":1,"CPUType":0,"Container":"1","Pool":"testnode","MemoryPool":0,"MemType":"DRAM,PMEM,HBM","MemSize":0,"ColdStart":0}}`),
},
{
name: "zero Exclusive",
data: []byte(`{"key1":{"Exclusive":"","Part":1,"CPUType":0,"Container":"1","Pool":"testnode","MemoryPool":0,"MemType":"DRAM,PMEM,HBM","MemSize":0,"ColdStart":0}}`),
data: []byte(`{"key1":{"PrettyName":"","Exclusive":"","Part":1,"CPUType":0,"Container":"1","Pool":"testnode","MemoryPool":0,"MemType":"DRAM,PMEM,HBM","MemSize":0,"ColdStart":0}}`),
},
}
for _, tc := range tcases {
Expand Down
14 changes: 12 additions & 2 deletions cmd/plugins/topology-aware/policy/mocks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

nri "github.com/containerd/nri/pkg/api"
"github.com/containers/nri-plugins/pkg/agent/podresapi"
resmgr "github.com/containers/nri-plugins/pkg/apis/resmgr/v1alpha1"
"github.com/containers/nri-plugins/pkg/cpuallocator"
"github.com/containers/nri-plugins/pkg/resmgr/cache"
Expand Down Expand Up @@ -324,6 +325,9 @@ func (fake *mockSystem) SetCpusOnline(online bool, cpus idset.IDSet) (idset.IDSe
func (fake *mockSystem) NodeDistance(idset.ID, idset.ID) int {
return 10
}
func (fake *mockSystem) NodeHintToCPUs(string) string {
return ""
}

type mockContainer struct {
name string
Expand Down Expand Up @@ -538,6 +542,9 @@ func (m *mockContainer) PreserveMemoryResources() bool {
func (m *mockContainer) MemoryTypes() (libmem.TypeMask, error) {
return libmem.TypeMaskDRAM, nil
}
func (m *mockContainer) GetPodResources() *podresapi.ContainerResources {
return nil
}

type mockPod struct {
name string
Expand Down Expand Up @@ -625,14 +632,17 @@ func (m *mockPod) GetTasks(bool) ([]string, error) {
func (m *mockPod) GetCtime() time.Time {
panic("unimplemented")
}
func (m *mockPod) GetPodResources() *podresapi.PodResources {
return nil
}

type mockCache struct {
returnValueForGetPolicyEntry bool
returnValue1ForLookupContainer cache.Container
returnValue2ForLookupContainer bool
}

func (m *mockCache) InsertPod(*nri.PodSandbox) (cache.Pod, error) {
func (m *mockCache) InsertPod(*nri.PodSandbox, <-chan *podresapi.PodResources) cache.Pod {
panic("unimplemented")
}
func (m *mockCache) DeletePod(string) cache.Pod {
Expand Down Expand Up @@ -695,7 +705,7 @@ func (m *mockCache) GetPolicyEntry(string, interface{}) bool {
func (m *mockCache) Save() error {
return nil
}
func (m *mockCache) RefreshPods([]*nri.PodSandbox) ([]cache.Pod, []cache.Pod, []cache.Container) {
func (m *mockCache) RefreshPods([]*nri.PodSandbox, <-chan podresapi.PodResourcesList) ([]cache.Pod, []cache.Pod, []cache.Container) {
panic("unimplemented")
}
func (m *mockCache) RefreshContainers([]*nri.Container) ([]cache.Container, []cache.Container) {
Expand Down
12 changes: 11 additions & 1 deletion docs/resource-policy/policy/topology-aware.md
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ metadata:
prefer-reserved-cpus.resource-policy.nri.io/container.special: "false"
```

## Allowing or denying mount/device paths via annotations
## Controlling Topology Hints Via Annotations

User is able mark certain pods and containers to have allowed or denied
paths for mounts or devices. What this means is that when the system
Expand Down Expand Up @@ -486,6 +486,16 @@ metadata:
- /xy-zy/another-blacklisted-path5
```

## Using Pod Resource API for Extra Topology Hints

If access to the `kubelet`'s `Pod Resource API` is enabled in the
[Node Agent's](../developers-guide/architecture.md#node-agent) configuration,
it is automatically used to generate per-container topology hints when a
device with locality to a NUMA node is advertised by the API. Annotated allow
and deny lists can be used to selective disable or enable per-resource hints,
using `podresapi:$RESOURCE_NAME` as the path.


## Container Affinity and Anti-Affinity

### Introduction
Expand Down

0 comments on commit 5fb185a

Please sign in to comment.