...
1
16
17 package noderesources
18
19 import (
20 "github.com/google/go-cmp/cmp/cmpopts"
21 v1 "k8s.io/api/core/v1"
22 "k8s.io/apimachinery/pkg/api/resource"
23 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
24 "k8s.io/apimachinery/pkg/util/validation/field"
25 "k8s.io/kubernetes/pkg/scheduler/apis/config"
26 )
27
28 var (
29 ignoreBadValueDetail = cmpopts.IgnoreFields(field.Error{}, "BadValue", "Detail")
30 defaultResources = []config.ResourceSpec{
31 {Name: string(v1.ResourceCPU), Weight: 1},
32 {Name: string(v1.ResourceMemory), Weight: 1},
33 }
34 extendedRes = "abc.com/xyz"
35 extendedResourceSet = []config.ResourceSpec{
36 {Name: string(v1.ResourceCPU), Weight: 1},
37 {Name: string(v1.ResourceMemory), Weight: 1},
38 {Name: extendedRes, Weight: 1},
39 }
40 )
41
42 func makeNode(node string, milliCPU, memory int64, extendedResource map[string]int64) *v1.Node {
43 resourceList := make(map[v1.ResourceName]resource.Quantity)
44 for res, quantity := range extendedResource {
45 resourceList[v1.ResourceName(res)] = *resource.NewQuantity(quantity, resource.DecimalSI)
46 }
47 resourceList[v1.ResourceCPU] = *resource.NewMilliQuantity(milliCPU, resource.DecimalSI)
48 resourceList[v1.ResourceMemory] = *resource.NewQuantity(memory, resource.BinarySI)
49 return &v1.Node{
50 ObjectMeta: metav1.ObjectMeta{Name: node},
51 Status: v1.NodeStatus{
52 Capacity: resourceList,
53 Allocatable: resourceList,
54 },
55 }
56 }
57
View as plain text