Skip to content

Commit

Permalink
tests/e2e: Handle multi-node cluster
Browse files Browse the repository at this point in the history
If a cluster has multiple nodes running then it will also have
multiple caa daemon sets running, so we want to check the logs
for the correct one.

Get the node name for the pod we are testing and then use it
as a check when we identify the CAA pod to get the logs for

Signed-off-by: stevenhorsman <steven@uk.ibm.com>
  • Loading branch information
stevenhorsman authored and Qi Feng Huo committed Nov 8, 2023
1 parent b18675f commit b70c954
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
22 changes: 18 additions & 4 deletions test/e2e/assessment_helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,14 @@ func watchImagePullTime(ctx context.Context, client klient.Client, caaPod v1.Pod
// not
// <date time> 15:18:43 [adaptor/proxy] CreateContainer: calling PullImage for <image> before CreateContainer (cid: "<cid>")
// was output
func IsPulledWithNydusSnapshotter(ctx context.Context, t *testing.T, client klient.Client) (bool, error) {
func IsPulledWithNydusSnapshotter(ctx context.Context, t *testing.T, client klient.Client, nodeName string) (bool, error) {
var podlist v1.PodList

nydusSnapshotterPullRegex, err := regexp.Compile(`.*mount_point:/run/kata-containers.*driver:image_guest_pull.*$`)
if err != nil {
return false, err
}
legacPullRegex, err := regexp.Compile(`.*"CreateContainer: calling PullImage.*before CreateContainer.*$`)
legacyPullRegex, err := regexp.Compile(`.*"CreateContainer: calling PullImage.*before CreateContainer.*$`)
if err != nil {
return false, err
}
Expand All @@ -147,7 +147,7 @@ func IsPulledWithNydusSnapshotter(ctx context.Context, t *testing.T, client klie
t.Fatal(err)
}
for _, pod := range podlist.Items {
if pod.Labels["app"] == "cloud-api-adaptor" {
if pod.Labels["app"] == "cloud-api-adaptor" && pod.Spec.NodeName == nodeName {
podLogString, err := getPodLog(ctx, client, pod)
if err != nil {
return false, err
Expand All @@ -158,7 +158,7 @@ func IsPulledWithNydusSnapshotter(ctx context.Context, t *testing.T, client klie
if nydusSnapshotterPullRegex.MatchString(line) {
t.Log("Pulled with nydus-snapshotter driver:" + line)
return true, nil
} else if legacPullRegex.MatchString(line) {
} else if legacyPullRegex.MatchString(line) {
t.Log("Called PullImage explicitly, not using nydus-snapshotter :" + line)
return false, nil
}
Expand Down Expand Up @@ -216,6 +216,20 @@ func comparePodLogString(ctx context.Context, client klient.Client, customPod v1
return podLogString, nil
}

func getNodeNameFromPod(ctx context.Context, client klient.Client, customPod v1.Pod) (string, error) {
var podlist v1.PodList
if err := client.Resources(customPod.Namespace).List(ctx, &podlist); err != nil {
return "", err
}

for _, pod := range podlist.Items {
if pod.ObjectMeta.Name == customPod.Name {
return pod.Spec.NodeName, nil
}
}
return "", errors.New("Pod wasn't found")
}

func getSuccessfulAndErroredPods(ctx context.Context, t *testing.T, client klient.Client, job batchv1.Job) (int, int, string, error) {
podLogString := ""
errorPod := 0
Expand Down
7 changes: 6 additions & 1 deletion test/e2e/assessment_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,12 @@ func (tc *testCase) run() {
}

if tc.isNydusSnapshotter {
usedNydusSnapshotter, err := IsPulledWithNydusSnapshotter(ctx, t, client)
nodeName, err := getNodeNameFromPod(ctx, client, *tc.pod)
if err != nil {
t.Fatal(err)
}
log.Tracef("Test pod running on node %s", nodeName)
usedNydusSnapshotter, err := IsPulledWithNydusSnapshotter(ctx, t, client, nodeName)
if err != nil {
t.Fatal(err)
}
Expand Down

0 comments on commit b70c954

Please sign in to comment.