Skip to content

Commit

Permalink
Debug
Browse files Browse the repository at this point in the history
  • Loading branch information
pbacsko committed Oct 24, 2024
1 parent f196feb commit 371ad0b
Showing 1 changed file with 20 additions and 39 deletions.
59 changes: 20 additions & 39 deletions test/e2e/foreign_pod/foreign_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@ package foreign_pod

import (
"fmt"
"time"

"github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega"
v1 "k8s.io/api/core/v1"

"github.com/apache/yunikorn-core/pkg/webservice/dao"
tests "github.com/apache/yunikorn-k8shim/test/e2e"
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/common"
"github.com/apache/yunikorn-k8shim/test/e2e/framework/helpers/k8s"
Expand All @@ -51,59 +49,42 @@ var _ = Describe("", func() {
})

It("Verify foreign pod tracking", func() {
sleepPod1Config := k8s.SleepPodConfig{Name: "foreign-pod-1", NS: ns, Mem: 10, Time: 60}
sleepPod2Config := k8s.SleepPodConfig{Name: "foreign-pod-2", NS: ns, Mem: 15, Time: 60}

// create sleep pod1, scheduled by the default scheduler
sleepObj1, err := k8s.InitSleepPod(sleepPod1Config)
sleepObj1.Spec.SchedulerName = ""
Ω(err).NotTo(gomega.HaveOccurred())
By("Creating foreign sleep pod #1")
pod1, err := kClient.CreatePod(sleepObj1, ns)
Ω(err).NotTo(gomega.HaveOccurred())

// create sleep pod2, scheduled by the default scheduler
sleepObj2, err := k8s.InitSleepPod(sleepPod2Config)
sleepObj2.Spec.SchedulerName = ""
Ω(err).NotTo(gomega.HaveOccurred())
By("Creating foreign sleep pod #2")
pod2, err := kClient.CreatePod(sleepObj2, ns)
Ω(err).NotTo(gomega.HaveOccurred())

// wait until pod1 & pod2 are in Running state
By("Waiting for sleep pod #1 to be scheduled")
err = kClient.WaitForPodRunning(ns, sleepPod1Config.Name, 30*time.Second)
Ω(err).NotTo(gomega.HaveOccurred())
By("Waiting for sleep pod #2 to be scheduled")
err = kClient.WaitForPodRunning(ns, sleepPod2Config.Name, 30*time.Second)
By("Retrieving foreign pods from kube-system")
podList, err := kClient.GetPods("kube-system")
Ω(err).NotTo(gomega.HaveOccurred())

fmt.Fprintf(ginkgo.GinkgoWriter, "pod1 %s\n", pod1.UID)
fmt.Fprintf(ginkgo.GinkgoWriter, "pod2 %s\n", pod2.UID)
pods := make(map[string]bool)
for _, pod := range podList.Items {
pods[string(pod.UID)] = true
fmt.Fprintf(ginkgo.GinkgoWriter, "pod: %s\tuid: %s\n", pod.Name, pod.UID)
}

// retrieve foreign pod info
By("Retrieving foreign allocations")
nodes, err := restClient.GetNodes("default")
Ω(err).NotTo(gomega.HaveOccurred())
foreignAllocs := make([]*dao.ForeignAllocationDAOInfo, 0, 2)
foreignAllocs := make(map[string]bool)
for _, n := range *nodes {
fmt.Fprintf(ginkgo.GinkgoWriter, "Checking node %s\n", n.NodeID)
if len(n.ForeignAllocations) > 0 {
for _, falloc := range n.ForeignAllocations {
fmt.Fprintf(ginkgo.GinkgoWriter, "Found allocation %s\n", falloc.AllocationKey)
foreignAllocs = append(foreignAllocs, falloc)
fmt.Fprintf(ginkgo.GinkgoWriter, "Found allocation %s %v\n", falloc.AllocationKey, falloc.ResourcePerAlloc)
foreignAllocs[falloc.AllocationKey] = true
}
}
}
Ω(len(foreignAllocs)).To(Equal(2))

if foreignAllocs[0].AllocationKey == "foreign-pod-1" {
fmt.Fprintf(ginkgo.GinkgoWriter, "%v\n", foreignAllocs[0].ResourcePerAlloc)
fmt.Fprintf(ginkgo.GinkgoWriter, "%v\n", foreignAllocs[1].ResourcePerAlloc)
} else {
fmt.Fprintf(ginkgo.GinkgoWriter, "%v\n", foreignAllocs[0].ResourcePerAlloc)
fmt.Fprintf(ginkgo.GinkgoWriter, "%v\n", foreignAllocs[1].ResourcePerAlloc)
// check foreign alloc --> kube-system pods
for uid, _ := range foreignAllocs {
Ω(pods[uid]).To(Equal(true), "unexpected allocation found")
}

// check kube-system pods -> foreign alloc
for uid, _ := range pods {
Ω(foreignAllocs[uid]).To(Equal(true), "foreign allocation %s not found inside Yunikorn", uid)
}

Ω(len(foreignAllocs)).To(Equal(2))
})

ginkgo.AfterEach(func() {
Expand Down

0 comments on commit 371ad0b

Please sign in to comment.