Skip to content

Commit

Permalink
OCPBUGS-7980:e2e:ht-aware: exec on the correct worker node (#729)
Browse files Browse the repository at this point in the history
* e2e:ht-aware: fix log format

Signed-off-by: Talor Itzhak <titzhak@redhat.com>

* e2e:ht-aware: replace By with testlog

`By` used for spliting big test spec.
In this case we want to share more info, so using log
package is slightly more accurate.

Signed-off-by: Talor Itzhak <titzhak@redhat.com>

* e2e:ht-aware: exec command on the correct node

we retrive the worker node where the pod
located, before executing command against it.

Signed-off-by: Talor Itzhak <titzhak@redhat.com>

* e2e:ht-aware: dump pod resources

Print extra information for debug purposes.

Signed-off-by: Talor Itzhak <titzhak@redhat.com>

---------

Signed-off-by: Talor Itzhak <titzhak@redhat.com>
  • Loading branch information
Tal-or committed Aug 8, 2023
1 parent b7e820c commit 0102c9b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
Expand Up @@ -664,13 +664,16 @@ func checkPodHTSiblings(testpod *corev1.Pod) bool {
"-c",
fmt.Sprintf("/bin/crictl inspect %s | /bin/jq -r '.info.runtimeSpec.linux.resources.cpu.cpus'", containerID),
}
output, err := nodes.ExecCommandOnNode(cmd, workerRTNode)
Expect(err).ToNot(HaveOccurred(), "Unable to crictl inspect containerID %s", "containerID")
node, err := nodes.GetByName(testpod.Spec.NodeName)
Expect(err).ToNot(HaveOccurred(), "failed to get node %q", testpod.Spec.NodeName)
Expect(testpod.Spec.NodeName).ToNot(BeEmpty(), "testpod %s/%s still pending - no nodeName set", testpod.Namespace, testpod.Name)
output, err := nodes.ExecCommandOnNode(cmd, node)
Expect(err).ToNot(HaveOccurred(), "Unable to crictl inspect containerID %q", containerID)

podcpus, err := cpuset.Parse(strings.Trim(fmt.Sprint(output), "\n"))
podcpus, err := cpuset.Parse(strings.Trim(output, "\n"))
Expect(err).ToNot(
HaveOccurred(), "Unable to cpuset.Parse pod allocated cpu set from output %s", fmt.Sprint(output))
By(fmt.Sprintf("Test pod CPU list: %s", podcpus.String()))
HaveOccurred(), "Unable to cpuset.Parse pod allocated cpu set from output %s", output)
testlog.Infof("Test pod CPU list: %s", podcpus.String())

// aggregate cpu sibling paris from the host based on the cpus allocated to the pod
By("Get host cpu siblings for pod cpuset")
Expand Down Expand Up @@ -715,6 +718,7 @@ func startHTtestPod(cpuCount int) *corev1.Pod {
testpod.Namespace = testutils.NamespaceTesting

By(fmt.Sprintf("Creating test pod with %d cpus", cpuCount))
testlog.Info(pods.DumpResourceRequirements(testpod))
err := testclient.Client.Create(context.TODO(), testpod)
Expect(err).ToNot(HaveOccurred())
testpod, err = pods.WaitForCondition(client.ObjectKeyFromObject(testpod), corev1.PodReady, corev1.ConditionTrue, 10*time.Minute)
Expand Down
31 changes: 31 additions & 0 deletions test/e2e/performanceprofile/functests/utils/pods/pods.go
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io"
"os"
"sort"
"strings"
"time"

Expand Down Expand Up @@ -205,3 +206,33 @@ func GetContainerIDByName(pod *corev1.Pod, containerName string) (string, error)
}
return "", fmt.Errorf("failed to find the container ID for the container %q under the pod %q", containerName, pod.Name)
}

func DumpResourceRequirements(pod *corev1.Pod) string {
var sb strings.Builder
fmt.Fprintf(&sb, "resource requirements for pod %s/%s:\n", pod.Namespace, pod.Name)
allContainers := []corev1.Container{}
allContainers = append(allContainers, pod.Spec.Containers...)
allContainers = append(allContainers, pod.Spec.InitContainers...)
for _, container := range allContainers {
fmt.Fprintf(&sb, "+- container %q: %s\n", container.Name, resourceListToString(container.Resources.Limits))
}
fmt.Fprintf(&sb, "---\n")
return sb.String()
}

func resourceListToString(res corev1.ResourceList) string {
idx := 0
resNames := make([]string, len(res))
for resName := range res {
resNames[idx] = string(resName)
idx++
}
sort.Strings(resNames)

items := []string{}
for _, resName := range resNames {
resQty := res[corev1.ResourceName(resName)]
items = append(items, fmt.Sprintf("%s=%s", resName, resQty.String()))
}
return strings.Join(items, ", ")
}

0 comments on commit 0102c9b

Please sign in to comment.