github.com/kubewharf/katalyst-core@v0.5.3/pkg/scheduler/plugins/noderesourcetopology/plugin_test.go (about) 1 /* 2 Copyright 2022 The Katalyst Authors. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package noderesourcetopology 18 19 import ( 20 "fmt" 21 22 "github.com/kubewharf/katalyst-api/pkg/consts" 23 24 v1 "k8s.io/api/core/v1" 25 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 26 "k8s.io/kubernetes/pkg/scheduler/apis/config" 27 "k8s.io/kubernetes/pkg/scheduler/framework" 28 29 config2 "github.com/kubewharf/katalyst-api/pkg/apis/scheduling/config" 30 ) 31 32 func MakeTestTm(args *config2.NodeResourceTopologyArgs, h framework.Handle) (framework.Plugin, error) { 33 return New(args, h) 34 } 35 36 func MakeTestArgs(scoringType config.ScoringStrategyType, alignedResource []string, resourcePolicy consts.ResourcePluginPolicyName) *config2.NodeResourceTopologyArgs { 37 args := &config2.NodeResourceTopologyArgs{ 38 ScoringStrategy: &config2.ScoringStrategy{ 39 Type: scoringType, 40 Resources: []config.ResourceSpec{ 41 { 42 Name: v1.ResourceCPU.String(), 43 Weight: 50, 44 }, 45 { 46 Name: v1.ResourceMemory.String(), 47 Weight: 50, 48 }, 49 { 50 Name: v1.ResourceStorage.String(), 51 Weight: 10, 52 }, 53 }, 54 }, 55 AlignedResources: alignedResource, 56 ResourcePluginPolicy: resourcePolicy, 57 } 58 59 return args 60 } 61 62 func makePodByResourceList(resources *v1.ResourceList, annotation map[string]string) *v1.Pod { 63 return &v1.Pod{ 64 ObjectMeta: metav1.ObjectMeta{ 65 Annotations: annotation, 66 }, 67 Spec: v1.PodSpec{ 68 Containers: []v1.Container{ 69 { 70 Resources: v1.ResourceRequirements{ 71 Requests: *resources, 72 Limits: *resources, 73 }, 74 }, 75 }, 76 }, 77 } 78 } 79 80 func makePodByResourceLists(resources []v1.ResourceList, annotation map[string]string) *v1.Pod { 81 pod := &v1.Pod{ 82 ObjectMeta: metav1.ObjectMeta{ 83 Annotations: annotation, 84 }, 85 Spec: v1.PodSpec{ 86 Containers: []v1.Container{}, 87 }, 88 } 89 90 for i, r := range resources { 91 pod.Spec.Containers = append(pod.Spec.Containers, v1.Container{ 92 Name: fmt.Sprintf("container%v", i), 93 Resources: v1.ResourceRequirements{ 94 Requests: r, 95 Limits: r, 96 }, 97 }) 98 } 99 100 return pod 101 }