mirror of
https://github.com/kubernetes-sigs/node-feature-discovery.git
synced 2025-03-30 19:54:46 +00:00
Release v0.0.13
of NodeResourceTopology API added missing TopologyManagerPolicy.
Expose new policies: * RestrictedContainerLevel * RestrictedPodLevel * BestEffortContainerLevel * BestEffortPodLevel Signed-off-by: PiotrProkop <pprokop@nvidia.com>
This commit is contained in:
parent
9356efe811
commit
1bae2867e2
2 changed files with 128 additions and 10 deletions
|
@ -24,20 +24,39 @@ import (
|
||||||
// DetectTopologyPolicy returns string type which present
|
// DetectTopologyPolicy returns string type which present
|
||||||
// both Topology manager policy and scope
|
// both Topology manager policy and scope
|
||||||
func DetectTopologyPolicy(policy string, scope string) v1alpha1.TopologyManagerPolicy {
|
func DetectTopologyPolicy(policy string, scope string) v1alpha1.TopologyManagerPolicy {
|
||||||
|
switch scope {
|
||||||
|
case config.PodTopologyManagerScope:
|
||||||
|
return detectPolicyPodScope(policy)
|
||||||
|
case config.ContainerTopologyManagerScope:
|
||||||
|
return detectPolicyContainerScope(policy)
|
||||||
|
default:
|
||||||
|
return v1alpha1.None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func detectPolicyPodScope(policy string) v1alpha1.TopologyManagerPolicy {
|
||||||
switch policy {
|
switch policy {
|
||||||
case config.SingleNumaNodeTopologyManagerPolicy:
|
case config.SingleNumaNodeTopologyManagerPolicy:
|
||||||
if scope == config.PodTopologyManagerScope {
|
return v1alpha1.SingleNUMANodePodLevel
|
||||||
return v1alpha1.SingleNUMANodePodLevel
|
|
||||||
} else if scope == config.ContainerTopologyManagerScope {
|
|
||||||
return v1alpha1.SingleNUMANodeContainerLevel
|
|
||||||
} else {
|
|
||||||
// default scope for single-numa-node
|
|
||||||
return v1alpha1.SingleNUMANodeContainerLevel
|
|
||||||
}
|
|
||||||
case config.RestrictedTopologyManagerPolicy:
|
case config.RestrictedTopologyManagerPolicy:
|
||||||
return v1alpha1.Restricted
|
return v1alpha1.RestrictedPodLevel
|
||||||
case config.BestEffortTopologyManagerPolicy:
|
case config.BestEffortTopologyManagerPolicy:
|
||||||
return v1alpha1.BestEffort
|
return v1alpha1.BestEffortPodLevel
|
||||||
|
case config.NoneTopologyManagerPolicy:
|
||||||
|
return v1alpha1.None
|
||||||
|
default:
|
||||||
|
return v1alpha1.None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func detectPolicyContainerScope(policy string) v1alpha1.TopologyManagerPolicy {
|
||||||
|
switch policy {
|
||||||
|
case config.SingleNumaNodeTopologyManagerPolicy:
|
||||||
|
return v1alpha1.SingleNUMANodeContainerLevel
|
||||||
|
case config.RestrictedTopologyManagerPolicy:
|
||||||
|
return v1alpha1.RestrictedContainerLevel
|
||||||
|
case config.BestEffortTopologyManagerPolicy:
|
||||||
|
return v1alpha1.BestEffortContainerLevel
|
||||||
case config.NoneTopologyManagerPolicy:
|
case config.NoneTopologyManagerPolicy:
|
||||||
return v1alpha1.None
|
return v1alpha1.None
|
||||||
default:
|
default:
|
||||||
|
|
99
pkg/topologypolicy/topology-policy_test.go
Normal file
99
pkg/topologypolicy/topology-policy_test.go
Normal file
|
@ -0,0 +1,99 @@
|
||||||
|
/*
|
||||||
|
Copyright 2023 The Kubernetes Authors.
|
||||||
|
|
||||||
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
you may not use this file except in compliance with the License.
|
||||||
|
You may obtain a copy of the License at
|
||||||
|
|
||||||
|
http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
|
||||||
|
Unless required by applicable law or agreed to in writing, software
|
||||||
|
distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
See the License for the specific language governing permissions and
|
||||||
|
limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package topologypolicy
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
v1alpha1 "github.com/k8stopologyawareschedwg/noderesourcetopology-api/pkg/apis/topology/v1alpha1"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestDetectTopologyPolicy(t *testing.T) {
|
||||||
|
testCases := []struct {
|
||||||
|
scope string
|
||||||
|
policy string
|
||||||
|
expected v1alpha1.TopologyManagerPolicy
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
policy: "best-effort",
|
||||||
|
scope: "pod",
|
||||||
|
expected: v1alpha1.BestEffortPodLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "best-effort",
|
||||||
|
scope: "container",
|
||||||
|
expected: v1alpha1.BestEffortContainerLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "restricted",
|
||||||
|
scope: "container",
|
||||||
|
expected: v1alpha1.RestrictedContainerLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "restricted",
|
||||||
|
scope: "pod",
|
||||||
|
expected: v1alpha1.RestrictedPodLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "single-numa-node",
|
||||||
|
scope: "pod",
|
||||||
|
expected: v1alpha1.SingleNUMANodePodLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "single-numa-node",
|
||||||
|
scope: "container",
|
||||||
|
expected: v1alpha1.SingleNUMANodeContainerLevel,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "none",
|
||||||
|
scope: "container",
|
||||||
|
expected: v1alpha1.None,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "none",
|
||||||
|
scope: "pod",
|
||||||
|
expected: v1alpha1.None,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "non-existent",
|
||||||
|
scope: "pod",
|
||||||
|
expected: v1alpha1.None,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "non-existent",
|
||||||
|
scope: "container",
|
||||||
|
expected: v1alpha1.None,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "single-numa-node",
|
||||||
|
scope: "non-existent",
|
||||||
|
expected: v1alpha1.None,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
policy: "single-numa-node",
|
||||||
|
scope: "non-existent",
|
||||||
|
expected: v1alpha1.None,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tc := range testCases {
|
||||||
|
actual := DetectTopologyPolicy(tc.policy, tc.scope)
|
||||||
|
if actual != tc.expected {
|
||||||
|
t.Errorf("Expected TopologyPolicy to equal: %s not: %s", tc.expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue