Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[YUNIKORN-2963] E2E Test for Foreign Pod Tracking #935

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 113 additions & 0 deletions test/e2e/foreign_pod/foreign_pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,119 @@ var _ = Describe("", func() {
Ω(foreignNodes[uid]).To(Equal(kubeNodes[uid]), "pod %s is tracked under incorrect node", uid)
}
})
It("Verify foreign pod tracking fails for untracked or incorrectly mapped pods", func() {
By("Retrieving foreign pods from kube-system")
kClient = k8s.KubeCtl{}
Ω(kClient.SetClient()).To(BeNil())
podList, err := kClient.GetPods(kubeSystem)
Ω(err).NotTo(gomega.HaveOccurred())

kubeUIDs := make(map[string]bool)
kubeNodes := make(map[string]string)
for _, pod := range podList.Items {
kubeUIDs[string(pod.UID)] = true
kubeNodes[string(pod.UID)] = pod.Spec.NodeName
fmt.Fprintf(ginkgo.GinkgoWriter, "pod: %s, uid: %s, node: %s\n", pod.Name, pod.UID, pod.Spec.NodeName)
}

// Simulate an error in foreign pod tracking
By("Simulating incorrect foreign allocation tracking")
var restClient yunikorn.RClient
nodes, err := restClient.GetNodes("default")
Ω(err).NotTo(gomega.HaveOccurred())

foreignAllocs := make(map[string]bool)
foreignNodes := make(map[string]string)
for _, n := range *nodes {
fmt.Fprintf(ginkgo.GinkgoWriter, "Checking node %s\n", n.NodeID)
if len(n.ForeignAllocations) > 0 {
for _, falloc := range n.ForeignAllocations {
// Introduce a mismatch to simulate an error
if string(falloc.AllocationKey) == "incorrect-uid" {
foreignAllocs[falloc.AllocationKey] = true
foreignNodes[falloc.AllocationKey] = "wrong-node"
} else {
Comment on lines +101 to +105
Copy link
Contributor

@pbacsko pbacsko Nov 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I genuinely don't get this. I don't think this path is ever taken.

In all tests, you work with a fixed set of pods (allocations) from "kube-system". Those are system pods that are already running as they should be. You're not doing anything with those pods or with Yunikorn. The contents of n.ForeignAllocations will always be the same.

Unless there are some uncommitted/already-committed changes somewhere else which is not visible in the PR, this test (and the remaining ones) does not make any sense.

foreignAllocs[falloc.AllocationKey] = true
foreignNodes[falloc.AllocationKey] = falloc.NodeID
}
}
}
}

// Check that an incorrect UID or mapping triggers an error
for uid := range kubeUIDs {
if uid == "incorrect-uid" {
Ω(foreignAllocs[uid]).To(Equal(false), "Simulated error: pod %s from kube-system should not be tracked", uid)
Ω(foreignNodes[uid]).To(Equal("wrong-node"), "Simulated error: pod %s should be tracked under incorrect node", uid)
} else {
Ω(foreignAllocs[uid]).To(Equal(true), "pod %s from kube-system is not tracked in Yunikorn", uid)
Ω(foreignNodes[uid]).To(Equal(kubeNodes[uid]), "pod %s is tracked under incorrect node", uid)
}
}
})
It("Verify multiple foreign pods", func() {
By("Retrieving foreign pods from kube-system")
kClient = k8s.KubeCtl{}
Ω(kClient.SetClient()).To(BeNil())
podList, err := kClient.GetPods(kubeSystem)
Ω(err).NotTo(gomega.HaveOccurred())

kubeUIDs := make(map[string]bool)
for _, pod := range podList.Items {
kubeUIDs[string(pod.UID)] = true
}

// retrieve foreign pod info
By("Retrieving foreign allocations")
var restClient yunikorn.RClient
nodes, err := restClient.GetNodes("default")
Ω(err).NotTo(gomega.HaveOccurred())
foreignAllocs := make(map[string]bool)
for _, n := range *nodes {
for _, falloc := range n.ForeignAllocations {
foreignAllocs[falloc.AllocationKey] = true
}
}

// check that all UIDs from kube-system are tracked properly
for uid := range kubeUIDs {
Ω(foreignAllocs[uid]).To(Equal(true), "pod %s from kube-system is not tracked in Yunikorn", uid)
}
})
It("Verify foreign pods on different nodes", func() {
By("Retrieving foreign pods from kube-system")
kClient = k8s.KubeCtl{}
Ω(kClient.SetClient()).To(BeNil())
podList, err := kClient.GetPods(kubeSystem)
Ω(err).NotTo(gomega.HaveOccurred())

kubeUIDs := make(map[string]bool)
kubeNodes := make(map[string]string)
for _, pod := range podList.Items {
kubeUIDs[string(pod.UID)] = true
kubeNodes[string(pod.UID)] = pod.Spec.NodeName
}

// retrieve foreign pod info
By("Retrieving foreign allocations")
var restClient yunikorn.RClient
nodes, err := restClient.GetNodes("default")
Ω(err).NotTo(gomega.HaveOccurred())
foreignAllocs := make(map[string]bool)
foreignNodes := make(map[string]string)
for _, n := range *nodes {
for _, falloc := range n.ForeignAllocations {
foreignAllocs[falloc.AllocationKey] = true
foreignNodes[falloc.AllocationKey] = falloc.NodeID
}
}

// check that all UIDs from kube-system are tracked properly
for uid := range kubeUIDs {
Ω(foreignAllocs[uid]).To(Equal(true), "pod %s from kube-system is not tracked in Yunikorn", uid)
Ω(foreignNodes[uid]).To(Equal(kubeNodes[uid]), "pod %s is tracked under incorrect node", uid)
}
})

ginkgo.AfterEach(func() {
tests.DumpClusterInfoIfSpecFailed(suiteName, []string{kubeSystem})
Expand Down
Loading