From 6f34682355f8a95071ac6291b050ee904d432a80 Mon Sep 17 00:00:00 2001 From: Francesco Romani Date: Wed, 23 Aug 2023 10:09:37 +0200 Subject: [PATCH] noderesourcetopology: move TM config utils in subpkg A upcoming change in the overreserve cache wants to consume nodeconfig utilities, so in order to enable both packages to consume this code, we move it in its own package. Trivial code movement and only necessary interface changes (renames/public <-> private symbols). Signed-off-by: Francesco Romani --- pkg/noderesourcetopology/filter.go | 5 +- .../topologymanager.go} | 37 +++- .../topologymanager_test.go} | 160 ++++++++++++--- pkg/noderesourcetopology/score.go | 5 +- .../noderesourcetopology_cache_test.go | 49 ++--- test/integration/noderesourcetopology_test.go | 185 +++++++++--------- 6 files changed, 281 insertions(+), 160 deletions(-) rename pkg/noderesourcetopology/{config.go => nodeconfig/topologymanager.go} (79%) rename pkg/noderesourcetopology/{config_test.go => nodeconfig/topologymanager_test.go} (74%) diff --git a/pkg/noderesourcetopology/filter.go b/pkg/noderesourcetopology/filter.go index 61cde522e..0502911bc 100644 --- a/pkg/noderesourcetopology/filter.go +++ b/pkg/noderesourcetopology/filter.go @@ -30,6 +30,7 @@ import ( "k8s.io/kubernetes/pkg/scheduler/framework" topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2" + "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/nodeconfig" "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/resourcerequests" "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/stringify" "sigs.k8s.io/scheduler-plugins/pkg/util" @@ -215,7 +216,7 @@ func (tm *TopologyMatch) Filter(ctx context.Context, cycleState *framework.Cycle klog.V(5).InfoS("Found NodeResourceTopology", "nodeTopology", klog.KObj(nodeTopology)) - handler := filterHandlerFromTopologyManagerConfig(topologyManagerConfigFromNodeResourceTopology(nodeTopology)) + handler := filterHandlerFromTopologyManager(nodeconfig.TopologyManagerFromNodeResourceTopology(nodeTopology)) if handler == nil { return nil } @@ -248,7 +249,7 @@ func subtractFromNUMA(nodes NUMANodeList, numaID int, container v1.Container) { } } -func filterHandlerFromTopologyManagerConfig(conf TopologyManagerConfig) filterFn { +func filterHandlerFromTopologyManager(conf nodeconfig.TopologyManager) filterFn { if conf.Policy != kubeletconfig.SingleNumaNodeTopologyManagerPolicy { return nil } diff --git a/pkg/noderesourcetopology/config.go b/pkg/noderesourcetopology/nodeconfig/topologymanager.go similarity index 79% rename from pkg/noderesourcetopology/config.go rename to pkg/noderesourcetopology/nodeconfig/topologymanager.go index 9b58d34bf..1ee7bf0b2 100644 --- a/pkg/noderesourcetopology/config.go +++ b/pkg/noderesourcetopology/nodeconfig/topologymanager.go @@ -14,9 +14,11 @@ See the License for the specific language governing permissions and limitations under the License. */ -package noderesourcetopology +package nodeconfig import ( + "fmt" + "k8s.io/klog/v2" kubeletconfig "k8s.io/kubernetes/pkg/kubelet/apis/config" @@ -45,28 +47,43 @@ func IsValidPolicy(policy string) bool { return false } -type TopologyManagerConfig struct { +type TopologyManager struct { Scope string Policy string } -func makeTopologyManagerConfigDefaults() TopologyManagerConfig { - return TopologyManagerConfig{ +func TopologyManagerDefaults() TopologyManager { + return TopologyManager{ Scope: kubeletconfig.ContainerTopologyManagerScope, Policy: kubeletconfig.NoneTopologyManagerPolicy, } } -func topologyManagerConfigFromNodeResourceTopology(nodeTopology *topologyv1alpha2.NodeResourceTopology) TopologyManagerConfig { - conf := makeTopologyManagerConfigDefaults() +func TopologyManagerFromNodeResourceTopology(nodeTopology *topologyv1alpha2.NodeResourceTopology) TopologyManager { + conf := TopologyManagerDefaults() + cfg := &conf // shortcut // Backward compatibility (v1alpha2 and previous). Deprecated, will be removed when the NRT API moves to v1beta1. - updateTopologyManagerConfigFromTopologyPolicies(&conf, nodeTopology.Name, nodeTopology.TopologyPolicies) + cfg.updateFromPolicies(nodeTopology.Name, nodeTopology.TopologyPolicies) // preferred new configuration source (v1alpha2 and onwards) - updateTopologyManagerConfigFromAttributes(&conf, nodeTopology.Attributes) + cfg.updateFromAttributes(nodeTopology.Attributes) return conf } -func updateTopologyManagerConfigFromAttributes(conf *TopologyManagerConfig, attrs topologyv1alpha2.AttributeList) { +func (conf TopologyManager) String() string { + return fmt.Sprintf("policy=%q scope=%q", conf.Policy, conf.Scope) +} + +func (conf TopologyManager) Equal(other TopologyManager) bool { + if conf.Scope != other.Scope { + return false + } + if conf.Policy != other.Policy { + return false + } + return true +} + +func (conf *TopologyManager) updateFromAttributes(attrs topologyv1alpha2.AttributeList) { for _, attr := range attrs { if attr.Name == AttributeScope && IsValidScope(attr.Value) { conf.Scope = attr.Value @@ -80,7 +97,7 @@ func updateTopologyManagerConfigFromAttributes(conf *TopologyManagerConfig, attr } } -func updateTopologyManagerConfigFromTopologyPolicies(conf *TopologyManagerConfig, nodeName string, topologyPolicies []string) { +func (conf *TopologyManager) updateFromPolicies(nodeName string, topologyPolicies []string) { if len(topologyPolicies) == 0 { klog.V(3).InfoS("Cannot determine policy", "node", nodeName) return diff --git a/pkg/noderesourcetopology/config_test.go b/pkg/noderesourcetopology/nodeconfig/topologymanager_test.go similarity index 74% rename from pkg/noderesourcetopology/config_test.go rename to pkg/noderesourcetopology/nodeconfig/topologymanager_test.go index a84ae7027..55fdd9374 100644 --- a/pkg/noderesourcetopology/config_test.go +++ b/pkg/noderesourcetopology/nodeconfig/topologymanager_test.go @@ -14,7 +14,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package noderesourcetopology +package nodeconfig import ( "reflect" @@ -119,21 +119,119 @@ func TestIsValidPolicy(t *testing.T) { } } +func TestTopologyManagerEqual(t *testing.T) { + tests := []struct { + name string + tmA TopologyManager + tmB TopologyManager + expected bool + }{ + { + name: "empty", + tmA: TopologyManager{}, + tmB: TopologyManager{}, + expected: true, + }, + { + name: "matching", + tmA: TopologyManager{ + Scope: "container", + Policy: "single-numa-node", + }, + tmB: TopologyManager{ + Scope: "container", + Policy: "single-numa-node", + }, + expected: true, + }, + { + name: "policy diff vs nil", + tmA: TopologyManager{ + Policy: "restricted", + }, + tmB: TopologyManager{}, + expected: false, + }, + { + name: "policy diff", + tmA: TopologyManager{ + Policy: "restricted", + }, + tmB: TopologyManager{ + Policy: "best-effort", + }, + expected: false, + }, + { + name: "scope diff vs nil", + tmA: TopologyManager{ + Scope: "container", + }, + tmB: TopologyManager{}, + expected: false, + }, + { + name: "scope diff", + tmA: TopologyManager{ + Scope: "container", + }, + tmB: TopologyManager{ + Scope: "pod", + }, + expected: false, + }, + { + name: "scope diff, policy matching", + tmA: TopologyManager{ + Scope: "container", + Policy: "single-numa-node", + }, + tmB: TopologyManager{ + Scope: "pod", + Policy: "single-numa-node", + }, + expected: false, + }, + { + name: "scope matching, policy diff", + tmA: TopologyManager{ + Scope: "container", + Policy: "single-numa-node", + }, + tmB: TopologyManager{ + Scope: "container", + Policy: "best-effort", + }, + expected: false, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + got := tt.tmA.Equal(tt.tmB) + if got != tt.expected { + t.Errorf("<%s> vs <%s> got=%v expected=%v", tt.tmA.String(), tt.tmB.String(), got, tt.expected) + } + }) + } + +} + func TestConfigFromAttributes(t *testing.T) { tests := []struct { name string attrs topologyv1alpha2.AttributeList - expected TopologyManagerConfig + expected TopologyManager }{ { name: "nil", attrs: nil, - expected: TopologyManagerConfig{}, + expected: TopologyManager{}, }, { name: "empty", attrs: topologyv1alpha2.AttributeList{}, - expected: TopologyManagerConfig{}, + expected: TopologyManager{}, }, { name: "no-policy", @@ -143,7 +241,7 @@ func TestConfigFromAttributes(t *testing.T) { Value: "pod", }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Scope: kubeletconfig.PodTopologyManagerScope, }, }, @@ -155,7 +253,7 @@ func TestConfigFromAttributes(t *testing.T) { Value: "restricted", }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.RestrictedTopologyManagerPolicy, }, }, @@ -171,7 +269,7 @@ func TestConfigFromAttributes(t *testing.T) { Value: "container", }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.RestrictedTopologyManagerPolicy, Scope: kubeletconfig.ContainerTopologyManagerScope, }, @@ -188,7 +286,7 @@ func TestConfigFromAttributes(t *testing.T) { Value: "single-numa-node", }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.SingleNumaNodeTopologyManagerPolicy, Scope: kubeletconfig.PodTopologyManagerScope, }, @@ -205,7 +303,7 @@ func TestConfigFromAttributes(t *testing.T) { Value: "single-numa-node", }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.SingleNumaNodeTopologyManagerPolicy, }, }, @@ -221,7 +319,7 @@ func TestConfigFromAttributes(t *testing.T) { Value: "restricted", }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.RestrictedTopologyManagerPolicy, }, }, @@ -229,8 +327,9 @@ func TestConfigFromAttributes(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := TopologyManagerConfig{} - updateTopologyManagerConfigFromAttributes(&got, tt.attrs) + got := TopologyManager{} + cfg := &got // shortcut + cfg.updateFromAttributes(tt.attrs) if !reflect.DeepEqual(got, tt.expected) { t.Errorf("conf got=%+#v expected=%+#v", got, tt.expected) } @@ -242,22 +341,22 @@ func TestConfigFromPolicies(t *testing.T) { tests := []struct { name string policies []string - expected TopologyManagerConfig + expected TopologyManager }{ { name: "nil", policies: nil, - expected: TopologyManagerConfig{}, + expected: TopologyManager{}, }, { name: "empty", policies: []string{}, - expected: TopologyManagerConfig{}, + expected: TopologyManager{}, }, { name: "single-numa-pod", policies: []string{string(topologyv1alpha2.SingleNUMANodePodLevel)}, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.SingleNumaNodeTopologyManagerPolicy, Scope: kubeletconfig.PodTopologyManagerScope, }, @@ -265,7 +364,7 @@ func TestConfigFromPolicies(t *testing.T) { { name: "single-numa-container", policies: []string{string(topologyv1alpha2.SingleNUMANodeContainerLevel)}, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.SingleNumaNodeTopologyManagerPolicy, Scope: kubeletconfig.ContainerTopologyManagerScope, }, @@ -273,7 +372,7 @@ func TestConfigFromPolicies(t *testing.T) { { name: "restricted-container", policies: []string{string(topologyv1alpha2.RestrictedContainerLevel)}, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.RestrictedTopologyManagerPolicy, Scope: kubeletconfig.ContainerTopologyManagerScope, }, @@ -284,7 +383,7 @@ func TestConfigFromPolicies(t *testing.T) { string(topologyv1alpha2.RestrictedContainerLevel), string(topologyv1alpha2.SingleNUMANodePodLevel), }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.RestrictedTopologyManagerPolicy, Scope: kubeletconfig.ContainerTopologyManagerScope, }, @@ -292,14 +391,15 @@ func TestConfigFromPolicies(t *testing.T) { { name: "error-unknown-policy", policies: []string{"foobar"}, - expected: TopologyManagerConfig{}, + expected: TopologyManager{}, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := TopologyManagerConfig{} - updateTopologyManagerConfigFromTopologyPolicies(&got, "", tt.policies) + got := TopologyManager{} + cfg := &got // shortcut\ + cfg.updateFromPolicies("", tt.policies) if !reflect.DeepEqual(got, tt.expected) { t.Errorf("conf got=%+#v expected=%+#v", got, tt.expected) } @@ -311,12 +411,12 @@ func TestConfigFromNRT(t *testing.T) { tests := []struct { name string nrt topologyv1alpha2.NodeResourceTopology - expected TopologyManagerConfig + expected TopologyManager }{ { name: "nil", nrt: topologyv1alpha2.NodeResourceTopology{}, - expected: makeTopologyManagerConfigDefaults(), + expected: TopologyManagerDefaults(), }, { name: "policies-single", @@ -325,7 +425,7 @@ func TestConfigFromNRT(t *testing.T) { string(topologyv1alpha2.BestEffortPodLevel), }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.BestEffortTopologyManagerPolicy, Scope: kubeletconfig.PodTopologyManagerScope, }, @@ -338,7 +438,7 @@ func TestConfigFromNRT(t *testing.T) { string(topologyv1alpha2.BestEffortPodLevel), }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.RestrictedTopologyManagerPolicy, Scope: kubeletconfig.ContainerTopologyManagerScope, }, @@ -353,7 +453,7 @@ func TestConfigFromNRT(t *testing.T) { }, }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.RestrictedTopologyManagerPolicy, Scope: kubeletconfig.ContainerTopologyManagerScope, }, @@ -371,7 +471,7 @@ func TestConfigFromNRT(t *testing.T) { }, }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.BestEffortTopologyManagerPolicy, Scope: kubeletconfig.ContainerTopologyManagerScope, }, @@ -393,7 +493,7 @@ func TestConfigFromNRT(t *testing.T) { }, }, }, - expected: TopologyManagerConfig{ + expected: TopologyManager{ Policy: kubeletconfig.RestrictedTopologyManagerPolicy, Scope: kubeletconfig.ContainerTopologyManagerScope, }, @@ -402,7 +502,7 @@ func TestConfigFromNRT(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := topologyManagerConfigFromNodeResourceTopology(&tt.nrt) + got := TopologyManagerFromNodeResourceTopology(&tt.nrt) if !reflect.DeepEqual(got, tt.expected) { t.Errorf("conf got=%+#v expected=%+#v", got, tt.expected) } diff --git a/pkg/noderesourcetopology/score.go b/pkg/noderesourcetopology/score.go index 1e88deafd..e0e68c303 100644 --- a/pkg/noderesourcetopology/score.go +++ b/pkg/noderesourcetopology/score.go @@ -30,6 +30,7 @@ import ( apiconfig "sigs.k8s.io/scheduler-plugins/apis/config" topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2" + "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/nodeconfig" "sigs.k8s.io/scheduler-plugins/pkg/util" ) @@ -76,7 +77,7 @@ func (tm *TopologyMatch) Score(ctx context.Context, state *framework.CycleState, logNRT("noderesourcetopology found", nodeTopology) - handler := tm.scoringHandlerFromTopologyManagerConfig(topologyManagerConfigFromNodeResourceTopology(nodeTopology)) + handler := tm.scoringHandlerFromTopologyManagerConfig(nodeconfig.TopologyManagerFromNodeResourceTopology(nodeTopology)) if handler == nil { return 0, nil } @@ -150,7 +151,7 @@ func containerScopeScore(pod *v1.Pod, zones topologyv1alpha2.ZoneList, scorerFn return finalScore, nil } -func (tm *TopologyMatch) scoringHandlerFromTopologyManagerConfig(conf TopologyManagerConfig) scoringFn { +func (tm *TopologyMatch) scoringHandlerFromTopologyManagerConfig(conf nodeconfig.TopologyManager) scoringFn { if tm.scoreStrategyType == apiconfig.LeastNUMANodes { if conf.Scope == kubeletconfig.PodTopologyManagerScope { return leastNUMAPodScopeScore diff --git a/test/integration/noderesourcetopology_cache_test.go b/test/integration/noderesourcetopology_cache_test.go index 91f6c8b75..89ef96761 100644 --- a/test/integration/noderesourcetopology_cache_test.go +++ b/test/integration/noderesourcetopology_cache_test.go @@ -49,6 +49,7 @@ import ( schedconfig "sigs.k8s.io/scheduler-plugins/apis/config" "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology" + "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/nodeconfig" "sigs.k8s.io/scheduler-plugins/test/util" ) @@ -130,11 +131,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -151,11 +152,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -219,11 +220,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -240,11 +241,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -290,11 +291,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -311,11 +312,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -359,11 +360,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -380,11 +381,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -433,11 +434,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -454,11 +455,11 @@ func TestTopologyCachePluginWithoutUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -777,11 +778,11 @@ func TestTopologyCachePluginWithUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, { @@ -823,11 +824,11 @@ func TestTopologyCachePluginWithUpdates(t *testing.T) { MakeNRT().Name("fake-node-cache-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). diff --git a/test/integration/noderesourcetopology_test.go b/test/integration/noderesourcetopology_test.go index 8da80d97c..48bf43fef 100644 --- a/test/integration/noderesourcetopology_test.go +++ b/test/integration/noderesourcetopology_test.go @@ -49,6 +49,7 @@ import ( scheconfig "sigs.k8s.io/scheduler-plugins/apis/config" "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology" + "sigs.k8s.io/scheduler-plugins/pkg/noderesourcetopology/nodeconfig" "sigs.k8s.io/scheduler-plugins/test/util" topologyv1alpha2 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha2" @@ -244,11 +245,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -265,11 +266,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -295,11 +296,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -315,11 +316,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -343,11 +344,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -362,11 +363,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "none", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -391,11 +392,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -412,11 +413,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -443,11 +444,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -464,11 +465,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -495,11 +496,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -516,11 +517,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -576,11 +577,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -597,11 +598,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -634,11 +635,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -655,11 +656,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -689,11 +690,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -710,11 +711,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -744,11 +745,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -765,11 +766,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -799,11 +800,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -820,11 +821,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -854,11 +855,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -875,11 +876,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -909,11 +910,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -930,11 +931,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -961,11 +962,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -982,11 +983,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1076,11 +1077,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1097,11 +1098,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1131,11 +1132,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1152,11 +1153,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1187,11 +1188,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1208,11 +1209,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1243,11 +1244,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -1264,11 +1265,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -1299,11 +1300,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -1320,11 +1321,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -1354,11 +1355,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1375,11 +1376,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1409,11 +1410,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -1430,11 +1431,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -1464,11 +1465,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -1485,11 +1486,11 @@ func TestTopologyMatchPlugin(t *testing.T) { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "best-effort", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "pod", }, }). @@ -2096,11 +2097,11 @@ func parseTestUserEntry(entries []nrtTestUserEntry, ns string) []nrtTestEntry { MakeNRT().Name("fake-node-1"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }). @@ -2122,11 +2123,11 @@ func parseTestUserEntry(entries []nrtTestUserEntry, ns string) []nrtTestEntry { MakeNRT().Name("fake-node-2"). Attributes(topologyv1alpha2.AttributeList{ { - Name: noderesourcetopology.AttributePolicy, + Name: nodeconfig.AttributePolicy, Value: "single-numa-node", }, { - Name: noderesourcetopology.AttributeScope, + Name: nodeconfig.AttributeScope, Value: "container", }, }).