mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-21 01:50:55 +00:00
Use NodeWrapper to directly initialize node with labels
Using NodeWrapper in the integration tests gives more flexibility when creating nodes. For instance, tests can create nodes with labels or with a specific sets of resources. Also, NodeWrapper initialises a node with a capacity of 32 pods, which can be overridden by the caller. This makes sure that a node is usable as soon as it is created.
This commit is contained in:
@@ -19,6 +19,7 @@ go_library(
|
||||
"//pkg/scheduler/framework/v1alpha1:go_default_library",
|
||||
"//pkg/scheduler/util:go_default_library",
|
||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/api/resource:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/runtime:go_default_library",
|
||||
"//staging/src/k8s.io/apimachinery/pkg/types:go_default_library",
|
||||
|
@@ -19,7 +19,8 @@ package testing
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"k8s.io/api/core/v1"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/api/resource"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
)
|
||||
@@ -362,7 +363,8 @@ type NodeWrapper struct{ v1.Node }
|
||||
|
||||
// MakeNode creates a Node wrapper.
|
||||
func MakeNode() *NodeWrapper {
|
||||
return &NodeWrapper{v1.Node{}}
|
||||
w := &NodeWrapper{v1.Node{}}
|
||||
return w.Capacity(nil)
|
||||
}
|
||||
|
||||
// Obj returns the inner Node.
|
||||
@@ -390,3 +392,28 @@ func (n *NodeWrapper) Label(k, v string) *NodeWrapper {
|
||||
n.Labels[k] = v
|
||||
return n
|
||||
}
|
||||
|
||||
// Capacity sets the capacity and the allocatable resources of the inner node.
|
||||
// Each entry in `resources` corresponds to a resource name and its quantity.
|
||||
// By default, the capacity and allocatable number of pods are set to 32.
|
||||
func (n *NodeWrapper) Capacity(resources map[v1.ResourceName]string) *NodeWrapper {
|
||||
res := v1.ResourceList{
|
||||
v1.ResourcePods: resource.MustParse("32"),
|
||||
}
|
||||
for name, value := range resources {
|
||||
res[name] = resource.MustParse(value)
|
||||
}
|
||||
n.Status.Capacity, n.Status.Allocatable = res, res
|
||||
return n
|
||||
}
|
||||
|
||||
// Images sets the images of the inner node. Each entry in `images` corresponds
|
||||
// to an image name and its size in bytes.
|
||||
func (n *NodeWrapper) Images(images map[string]int64) *NodeWrapper {
|
||||
var containerImages []v1.ContainerImage
|
||||
for name, size := range images {
|
||||
containerImages = append(containerImages, v1.ContainerImage{Names: []string{name}, SizeBytes: size})
|
||||
}
|
||||
n.Status.Images = containerImages
|
||||
return n
|
||||
}
|
||||
|
Reference in New Issue
Block a user