mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-15 14:53:44 +00:00
Add "kubectl describe node" resource tests
This commit is contained in:
parent
439a862bba
commit
28f8e52f32
@ -3503,9 +3503,28 @@ Events: <none>` + "\n"
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
func getHugePageResourceList(pageSize, value string) corev1.ResourceList {
|
||||||
|
res := corev1.ResourceList{}
|
||||||
|
if pageSize != "" && value != "" {
|
||||||
|
res[corev1.ResourceName(corev1.ResourceHugePagesPrefix+pageSize)] = resource.MustParse(value)
|
||||||
|
}
|
||||||
|
return res
|
||||||
|
}
|
||||||
|
|
||||||
func TestDescribeNode(t *testing.T) {
|
func TestDescribeNode(t *testing.T) {
|
||||||
holderIdentity := "holder"
|
holderIdentity := "holder"
|
||||||
|
nodeCapacity := corev1.ResourceList{}
|
||||||
|
for _, rl := range []corev1.ResourceList{getHugePageResourceList("2Mi", "4Gi"), getResourceList("8", "24Gi"), getHugePageResourceList("1Gi", "0")} {
|
||||||
|
for resource, value := range rl {
|
||||||
|
nodeCapacity[resource] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
nodeAllocatable := corev1.ResourceList{}
|
||||||
|
for _, rl := range []corev1.ResourceList{getHugePageResourceList("2Mi", "2Gi"), getResourceList("4", "12Gi"), getHugePageResourceList("1Gi", "0")} {
|
||||||
|
for resource, value := range rl {
|
||||||
|
nodeAllocatable[resource] = value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fake := fake.NewSimpleClientset(
|
fake := fake.NewSimpleClientset(
|
||||||
&corev1.Node{
|
&corev1.Node{
|
||||||
@ -3515,6 +3534,10 @@ func TestDescribeNode(t *testing.T) {
|
|||||||
Spec: corev1.NodeSpec{
|
Spec: corev1.NodeSpec{
|
||||||
Unschedulable: true,
|
Unschedulable: true,
|
||||||
},
|
},
|
||||||
|
Status: corev1.NodeStatus{
|
||||||
|
Capacity: nodeCapacity,
|
||||||
|
Allocatable: nodeAllocatable,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
&coordinationv1.Lease{
|
&coordinationv1.Lease{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
@ -3527,6 +3550,38 @@ func TestDescribeNode(t *testing.T) {
|
|||||||
RenewTime: &metav1.MicroTime{Time: time.Now()},
|
RenewTime: &metav1.MicroTime{Time: time.Now()},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
&corev1.Pod{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "pod-with-resources",
|
||||||
|
Namespace: "foo",
|
||||||
|
},
|
||||||
|
TypeMeta: metav1.TypeMeta{
|
||||||
|
Kind: "Pod",
|
||||||
|
},
|
||||||
|
Spec: corev1.PodSpec{
|
||||||
|
Containers: []corev1.Container{
|
||||||
|
{
|
||||||
|
Name: "cpu-mem",
|
||||||
|
Image: "image:latest",
|
||||||
|
Resources: corev1.ResourceRequirements{
|
||||||
|
Requests: getResourceList("1", "1Gi"),
|
||||||
|
Limits: getResourceList("2", "2Gi"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "hugepages",
|
||||||
|
Image: "image:latest",
|
||||||
|
Resources: corev1.ResourceRequirements{
|
||||||
|
Requests: getHugePageResourceList("2Mi", "512Mi"),
|
||||||
|
Limits: getHugePageResourceList("2Mi", "512Mi"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Status: corev1.PodStatus{
|
||||||
|
Phase: corev1.PodRunning,
|
||||||
|
},
|
||||||
|
},
|
||||||
)
|
)
|
||||||
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
c := &describeClient{T: t, Namespace: "foo", Interface: fake}
|
||||||
d := NodeDescriber{c}
|
d := NodeDescriber{c}
|
||||||
@ -3535,7 +3590,16 @@ func TestDescribeNode(t *testing.T) {
|
|||||||
t.Errorf("unexpected error: %v", err)
|
t.Errorf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
expectedOut := []string{"Unschedulable", "true", "holder"}
|
expectedOut := []string{"Unschedulable", "true", "holder",
|
||||||
|
`Allocated resources:
|
||||||
|
(Total limits may be over 100 percent, i.e., overcommitted.)
|
||||||
|
Resource Requests Limits
|
||||||
|
-------- -------- ------
|
||||||
|
cpu 1 (25%) 2 (50%)
|
||||||
|
memory 1Gi (8%) 2Gi (16%)
|
||||||
|
ephemeral-storage 0 (0%) 0 (0%)
|
||||||
|
hugepages-1Gi 0 (0%) 0 (0%)
|
||||||
|
hugepages-2Mi 512Mi (25%) 512Mi (25%)`}
|
||||||
for _, expected := range expectedOut {
|
for _, expected := range expectedOut {
|
||||||
if !strings.Contains(out, expected) {
|
if !strings.Contains(out, expected) {
|
||||||
t.Errorf("expected to find %q in output: %q", expected, out)
|
t.Errorf("expected to find %q in output: %q", expected, out)
|
||||||
|
Loading…
Reference in New Issue
Block a user