Add Policy None for Topology Manager

Update naming of test functions.
This commit is contained in:
nolancon 2019-06-24 08:38:03 +01:00
parent ddc4ed0365
commit 2d7ac702d6
5 changed files with 115 additions and 2 deletions

View File

@ -4,6 +4,7 @@ go_library(
name = "go_default_library",
srcs = [
"policy.go",
"policy_none.go",
"policy_preferred.go",
"policy_strict.go",
"topology_manager.go",
@ -37,6 +38,7 @@ filegroup(
go_test(
name = "go_default_test",
srcs = [
"policy_none_test.go",
"policy_preferred_test.go",
"policy_strict_test.go",
],

View File

@ -0,0 +1,43 @@
/*
Copyright 2019 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 topologymanager
import (
"k8s.io/kubernetes/pkg/kubelet/lifecycle"
)
type nonePolicy struct{}
var _ Policy = &nonePolicy{}
// PolicyNone policy name.
const PolicyNone string = "none"
// NewNonePolicy returns none policy.
func NewNonePolicy() Policy {
return &nonePolicy{}
}
func (p *nonePolicy) Name() string {
return string(PolicyNone)
}
func (p *nonePolicy) CanAdmitPodResult(admit bool) lifecycle.PodAdmitResult {
return lifecycle.PodAdmitResult{
Admit: true,
}
}

View File

@ -0,0 +1,68 @@
/*
Copyright 2019 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 topologymanager
import (
"testing"
)
func TestName(t *testing.T) {
tcases := []struct {
name string
expected string
}{
{
name: "New None Policy",
expected: "none",
},
}
for _, tc := range tcases {
policy := NewNonePolicy()
if policy.Name() != tc.expected {
t.Errorf("Expected Policy Name to be %s, got %s", tc.expected, policy.Name())
}
}
}
func TestPolicyNoneCanAdmitPodResult(t *testing.T) {
tcases := []struct {
name string
admit bool
expected bool
}{
{
name: "Affinity is set to false in topology hints",
admit: false,
expected: true,
},
{
name: "Affinity is set to true in topology hints",
admit: true,
expected: true,
},
}
for _, tc := range tcases {
policy := NewNonePolicy()
admit := tc.admit
result := policy.CanAdmitPodResult(admit)
if result.Admit != tc.expected {
t.Errorf("Expected Admit field in result to be %t, got %t", tc.expected, result.Admit)
}
}
}

View File

@ -20,7 +20,7 @@ import (
"testing"
)
func TestCanAdmitPodResult1(t *testing.T) {
func TestPolicyPreferredCanAdmitPodResult(t *testing.T) {
tcases := []struct {
name string
admit bool

View File

@ -20,7 +20,7 @@ import (
"testing"
)
func TestCanAdmitPodResult(t *testing.T) {
func TestPolicyStrictCanAdmitPodResult(t *testing.T) {
tcases := []struct {
name string
admit bool