Skip to content

Commit

Permalink
Merge pull request #6552 from walidghallab/testutil
Browse files Browse the repository at this point in the history
Add BuildTestNodeWithAllocatable test utility method.
  • Loading branch information
k8s-ci-robot authored Mar 5, 2024
2 parents b41a8a6 + aada657 commit b5f86a4
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions cluster-autoscaler/utils/test/test_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ func TolerateGpuForPod(pod *apiv1.Pod) {
}

// BuildTestNode creates a node with specified capacity.
func BuildTestNode(name string, millicpu int64, mem int64) *apiv1.Node {
func BuildTestNode(name string, millicpuCapacity int64, memCapacity int64) *apiv1.Node {
node := &apiv1.Node{
ObjectMeta: metav1.ObjectMeta{
Name: name,
Expand All @@ -229,11 +229,11 @@ func BuildTestNode(name string, millicpu int64, mem int64) *apiv1.Node {
},
}

if millicpu >= 0 {
node.Status.Capacity[apiv1.ResourceCPU] = *resource.NewMilliQuantity(millicpu, resource.DecimalSI)
if millicpuCapacity >= 0 {
node.Status.Capacity[apiv1.ResourceCPU] = *resource.NewMilliQuantity(millicpuCapacity, resource.DecimalSI)
}
if mem >= 0 {
node.Status.Capacity[apiv1.ResourceMemory] = *resource.NewQuantity(mem, resource.DecimalSI)
if memCapacity >= 0 {
node.Status.Capacity[apiv1.ResourceMemory] = *resource.NewQuantity(memCapacity, resource.DecimalSI)
}

node.Status.Allocatable = apiv1.ResourceList{}
Expand All @@ -244,6 +244,13 @@ func BuildTestNode(name string, millicpu int64, mem int64) *apiv1.Node {
return node
}

// WithAllocatable adds specified milliCpu and memory to Allocatable of the node in-place.
func WithAllocatable(node *apiv1.Node, millicpuAllocatable, memAllocatable int64) *apiv1.Node {
node.Status.Allocatable[apiv1.ResourceCPU] = *resource.NewMilliQuantity(millicpuAllocatable, resource.DecimalSI)
node.Status.Allocatable[apiv1.ResourceMemory] = *resource.NewQuantity(memAllocatable, resource.DecimalSI)
return node
}

// AddEphemeralStorageToNode adds ephemeral storage capacity to a given node.
func AddEphemeralStorageToNode(node *apiv1.Node, eph int64) *apiv1.Node {
if eph >= 0 {
Expand Down

0 comments on commit b5f86a4

Please sign in to comment.