mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 09:22:44 +00:00
Merge pull request #79343 from nolancon/topology-manager-none
Add Policy None for Topology Manager
This commit is contained in:
commit
4197adaf2d
@ -4,6 +4,7 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"policy.go",
|
"policy.go",
|
||||||
|
"policy_none.go",
|
||||||
"policy_preferred.go",
|
"policy_preferred.go",
|
||||||
"policy_strict.go",
|
"policy_strict.go",
|
||||||
"topology_manager.go",
|
"topology_manager.go",
|
||||||
@ -37,6 +38,7 @@ filegroup(
|
|||||||
go_test(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
srcs = [
|
srcs = [
|
||||||
|
"policy_none_test.go",
|
||||||
"policy_preferred_test.go",
|
"policy_preferred_test.go",
|
||||||
"policy_strict_test.go",
|
"policy_strict_test.go",
|
||||||
],
|
],
|
||||||
|
43
pkg/kubelet/cm/topologymanager/policy_none.go
Normal file
43
pkg/kubelet/cm/topologymanager/policy_none.go
Normal 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,
|
||||||
|
}
|
||||||
|
}
|
68
pkg/kubelet/cm/topologymanager/policy_none_test.go
Normal file
68
pkg/kubelet/cm/topologymanager/policy_none_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -20,7 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanAdmitPodResult1(t *testing.T) {
|
func TestPolicyPreferredCanAdmitPodResult(t *testing.T) {
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
admit bool
|
admit bool
|
||||||
|
@ -20,7 +20,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestCanAdmitPodResult(t *testing.T) {
|
func TestPolicyStrictCanAdmitPodResult(t *testing.T) {
|
||||||
tcases := []struct {
|
tcases := []struct {
|
||||||
name string
|
name string
|
||||||
admit bool
|
admit bool
|
||||||
|
Loading…
Reference in New Issue
Block a user