mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Update policy_none removing canAdmitPodResult
Update unit tests for none_policy Add Name test for policy_restricted
This commit is contained in:
parent
cf8b098dda
commit
dc36924c37
@ -36,12 +36,6 @@ func (p *nonePolicy) Name() string {
|
|||||||
return PolicyNone
|
return PolicyNone
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *nonePolicy) canAdmitPodResult(hint *TopologyHint) lifecycle.PodAdmitResult {
|
|
||||||
return lifecycle.PodAdmitResult{
|
|
||||||
Admit: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (p *nonePolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
|
func (p *nonePolicy) Merge(providersHints []map[string][]TopologyHint) (TopologyHint, lifecycle.PodAdmitResult) {
|
||||||
return TopologyHint{}, p.canAdmitPodResult(nil)
|
return TopologyHint{}, lifecycle.PodAdmitResult{Admit: true}
|
||||||
}
|
}
|
||||||
|
@ -17,10 +17,11 @@ limitations under the License.
|
|||||||
package topologymanager
|
package topologymanager
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestName(t *testing.T) {
|
func TestPolicyNoneName(t *testing.T) {
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
expected string
|
expected string
|
||||||
@ -38,30 +39,46 @@ func TestName(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPolicyNoneCanAdmitPodResult(t *testing.T) {
|
func TestPolicyNoneMerge(t *testing.T) {
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
hint TopologyHint
|
providersHints []map[string][]TopologyHint
|
||||||
expected bool
|
expectedHint TopologyHint
|
||||||
|
expectedAdmit lifecycle.PodAdmitResult
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
name: "Preferred is set to false in topology hints",
|
name: "merged empty providers hints",
|
||||||
hint: TopologyHint{nil, false},
|
providersHints: []map[string][]TopologyHint{},
|
||||||
expected: true,
|
expectedHint: TopologyHint{},
|
||||||
|
expectedAdmit: lifecycle.PodAdmitResult{Admit: true},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Preferred is set to true in topology hints",
|
name: "merge with a single provider with a single preferred resource",
|
||||||
hint: TopologyHint{nil, true},
|
providersHints: []map[string][]TopologyHint{
|
||||||
expected: true,
|
{
|
||||||
|
"resource": {{NUMANodeAffinity: NewTestBitMask(0, 1), Preferred: true}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedHint: TopologyHint{},
|
||||||
|
expectedAdmit: lifecycle.PodAdmitResult{Admit: true},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "merge with a single provider with a single non-preferred resource",
|
||||||
|
providersHints: []map[string][]TopologyHint{
|
||||||
|
{
|
||||||
|
"resource": {{NUMANodeAffinity: NewTestBitMask(0, 1), Preferred: false}},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expectedHint: TopologyHint{},
|
||||||
|
expectedAdmit: lifecycle.PodAdmitResult{Admit: true},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, tc := range tcases {
|
for _, tc := range tcases {
|
||||||
policy := NewNonePolicy()
|
policy := NewNonePolicy()
|
||||||
result := policy.(*nonePolicy).canAdmitPodResult(&tc.hint)
|
result, admit := policy.Merge(tc.providersHints)
|
||||||
|
if !result.IsEqual(tc.expectedHint) || admit.Admit != tc.expectedAdmit.Admit {
|
||||||
if result.Admit != tc.expected {
|
t.Errorf("Test Case: %s: Expected merge hint to be %v, got %v", tc.name, tc.expectedHint, result)
|
||||||
t.Errorf("Expected Admit field in result to be %t, got %t", tc.expected, result.Admit)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,24 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func TestPolicyRestrictedName(t *testing.T) {
|
||||||
|
tcases := []struct {
|
||||||
|
name string
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "New Restricted Policy",
|
||||||
|
expected: "restricted",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tc := range tcases {
|
||||||
|
policy := NewRestrictedPolicy([]int{0, 1})
|
||||||
|
if policy.Name() != tc.expected {
|
||||||
|
t.Errorf("Expected Policy Name to be %s, got %s", tc.expected, policy.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) {
|
func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) {
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
@ -58,7 +76,7 @@ func TestPolicyRestrictedCanAdmitPodResult(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestRestrictedPolicyMerge(t *testing.T) {
|
func TestPolicyRestrictedMerge(t *testing.T) {
|
||||||
numaNodes := []int{0, 1}
|
numaNodes := []int{0, 1}
|
||||||
policy := NewRestrictedPolicy(numaNodes)
|
policy := NewRestrictedPolicy(numaNodes)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user