mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 05:27:21 +00:00
Merge pull request #12714 from gmarek/fix_test
Fix SchedulerPredicates test after event reason rename
This commit is contained in:
commit
563e6075ca
@ -31,12 +31,24 @@ import (
|
|||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Returns a number of currently running and not running Pods.
|
||||||
|
func getPodsNumbers(pods *api.PodList) (runningPods, notRunningPods int) {
|
||||||
|
for _, pod := range pods.Items {
|
||||||
|
if pod.Status.Phase == api.PodRunning {
|
||||||
|
runningPods += 1
|
||||||
|
} else {
|
||||||
|
notRunningPods += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
// Simplified version of RunRC, that does not create RC, but creates plain Pods and
|
// Simplified version of RunRC, that does not create RC, but creates plain Pods and
|
||||||
// requires passing whole Pod definition, which is needed to test various Scheduler predicates.
|
// requires passing whole Pod definition, which is needed to test various Scheduler predicates.
|
||||||
func startPods(c *client.Client, replicas int, ns string, podNamePrefix string, pod api.Pod) {
|
func startPods(c *client.Client, replicas int, ns string, podNamePrefix string, pod api.Pod) {
|
||||||
pods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
allPods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
||||||
expectNoError(err)
|
expectNoError(err)
|
||||||
podsRunningBefore := len(pods.Items)
|
podsRunningBefore, _ := getPodsNumbers(allPods)
|
||||||
|
|
||||||
for i := 0; i < replicas; i++ {
|
for i := 0; i < replicas; i++ {
|
||||||
podName := fmt.Sprintf("%v-%v", podNamePrefix, i)
|
podName := fmt.Sprintf("%v-%v", podNamePrefix, i)
|
||||||
@ -82,18 +94,10 @@ func getRequestedCPU(pod api.Pod) int64 {
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func verifyResult(c *client.Client, podName string, ns string) {
|
func verifyResult(c *client.Client, podName string, ns string, oldNotRunning int) {
|
||||||
allPods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
allPods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
||||||
expectNoError(err)
|
expectNoError(err)
|
||||||
runningPods := 0
|
_, notRunningPods := getPodsNumbers(allPods)
|
||||||
notRunningPods := make([]api.Pod, 0)
|
|
||||||
for _, pod := range allPods.Items {
|
|
||||||
if pod.Status.Phase == api.PodRunning {
|
|
||||||
runningPods += 1
|
|
||||||
} else {
|
|
||||||
notRunningPods = append(notRunningPods, pod)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
schedEvents, err := c.Events(ns).List(
|
schedEvents, err := c.Events(ns).List(
|
||||||
labels.Everything(),
|
labels.Everything(),
|
||||||
@ -102,7 +106,7 @@ func verifyResult(c *client.Client, podName string, ns string) {
|
|||||||
"involvedObject.name": podName,
|
"involvedObject.name": podName,
|
||||||
"involvedObject.namespace": ns,
|
"involvedObject.namespace": ns,
|
||||||
"source": "scheduler",
|
"source": "scheduler",
|
||||||
"reason": "failedScheduling",
|
"reason": "FailedScheduling",
|
||||||
}.AsSelector())
|
}.AsSelector())
|
||||||
expectNoError(err)
|
expectNoError(err)
|
||||||
|
|
||||||
@ -116,9 +120,8 @@ func verifyResult(c *client.Client, podName string, ns string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Expect(len(notRunningPods)).To(Equal(1), printOnce(fmt.Sprintf("Pods found in the cluster: %#v", allPods)))
|
Expect(notRunningPods).To(Equal(1+oldNotRunning), printOnce(fmt.Sprintf("Pods found in the cluster: %#v", allPods)))
|
||||||
Expect(schedEvents.Items).ToNot(BeEmpty(), printOnce(fmt.Sprintf("Pods found in the cluster: %#v", allPods)))
|
Expect(schedEvents.Items).ToNot(BeEmpty(), printOnce(fmt.Sprintf("Pods found in the cluster: %#v", allPods)))
|
||||||
Expect(notRunningPods[0].Name).To(Equal(podName), printOnce(fmt.Sprintf("Pods found in the cluster: %#v", allPods)))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var _ = Describe("SchedulerPredicates", func() {
|
var _ = Describe("SchedulerPredicates", func() {
|
||||||
@ -175,9 +178,9 @@ var _ = Describe("SchedulerPredicates", func() {
|
|||||||
Logf("Node: %v", node)
|
Logf("Node: %v", node)
|
||||||
}
|
}
|
||||||
|
|
||||||
pods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
allPods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
||||||
expectNoError(err)
|
expectNoError(err)
|
||||||
currentlyRunningPods := len(pods.Items)
|
currentlyRunningPods, currentlyDeadPods := getPodsNumbers(allPods)
|
||||||
podsNeededForSaturation := int(totalPodCapacity) - currentlyRunningPods
|
podsNeededForSaturation := int(totalPodCapacity) - currentlyRunningPods
|
||||||
|
|
||||||
By(fmt.Sprintf("Starting additional %v Pods to fully saturate the cluster max pods and trying to start another one", podsNeededForSaturation))
|
By(fmt.Sprintf("Starting additional %v Pods to fully saturate the cluster max pods and trying to start another one", podsNeededForSaturation))
|
||||||
@ -224,7 +227,7 @@ var _ = Describe("SchedulerPredicates", func() {
|
|||||||
Logf("Sleeping 10 seconds and crossing our fingers that scheduler will run in that time.")
|
Logf("Sleeping 10 seconds and crossing our fingers that scheduler will run in that time.")
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
verifyResult(c, podName, ns)
|
verifyResult(c, podName, ns, currentlyDeadPods)
|
||||||
})
|
})
|
||||||
|
|
||||||
// This test verifies we don't allow scheduling of pods in a way that sum of limits of pods is greater than machines capacit.
|
// This test verifies we don't allow scheduling of pods in a way that sum of limits of pods is greater than machines capacit.
|
||||||
@ -240,11 +243,16 @@ var _ = Describe("SchedulerPredicates", func() {
|
|||||||
|
|
||||||
pods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
pods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
||||||
expectNoError(err)
|
expectNoError(err)
|
||||||
|
var currentlyDeadPods int
|
||||||
for _, pod := range pods.Items {
|
for _, pod := range pods.Items {
|
||||||
_, found := nodeToCapacityMap[pod.Spec.NodeName]
|
_, found := nodeToCapacityMap[pod.Spec.NodeName]
|
||||||
Expect(found).To(Equal(true))
|
Expect(found).To(Equal(true))
|
||||||
Logf("Pod %v requesting capacity %v on Node %v", pod.Name, getRequestedCPU(pod), pod.Spec.NodeName)
|
if pod.Status.Phase == api.PodRunning {
|
||||||
nodeToCapacityMap[pod.Spec.NodeName] -= getRequestedCPU(pod)
|
Logf("Pod %v requesting capacity %v on Node %v", pod.Name, getRequestedCPU(pod), pod.Spec.NodeName)
|
||||||
|
nodeToCapacityMap[pod.Spec.NodeName] -= getRequestedCPU(pod)
|
||||||
|
} else {
|
||||||
|
currentlyDeadPods += 1
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var podsNeededForSaturation int
|
var podsNeededForSaturation int
|
||||||
@ -307,7 +315,7 @@ var _ = Describe("SchedulerPredicates", func() {
|
|||||||
Logf("Sleeping 10 seconds and crossing our fingers that scheduler will run in that time.")
|
Logf("Sleeping 10 seconds and crossing our fingers that scheduler will run in that time.")
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
verifyResult(c, podName, ns)
|
verifyResult(c, podName, ns, currentlyDeadPods)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Test Nodes does not have any label, hence it should be impossible to schedule Pod with
|
// Test Nodes does not have any label, hence it should be impossible to schedule Pod with
|
||||||
@ -316,7 +324,11 @@ var _ = Describe("SchedulerPredicates", func() {
|
|||||||
By("Trying to schedule Pod with nonempty NodeSelector.")
|
By("Trying to schedule Pod with nonempty NodeSelector.")
|
||||||
podName := "restricted-pod"
|
podName := "restricted-pod"
|
||||||
|
|
||||||
_, err := c.Pods(ns).Create(&api.Pod{
|
allPods, err := c.Pods(api.NamespaceAll).List(labels.Everything(), fields.Everything())
|
||||||
|
expectNoError(err)
|
||||||
|
_, currentlyDeadPods := getPodsNumbers(allPods)
|
||||||
|
|
||||||
|
_, err = c.Pods(ns).Create(&api.Pod{
|
||||||
TypeMeta: api.TypeMeta{
|
TypeMeta: api.TypeMeta{
|
||||||
Kind: "Pod",
|
Kind: "Pod",
|
||||||
},
|
},
|
||||||
@ -342,6 +354,6 @@ var _ = Describe("SchedulerPredicates", func() {
|
|||||||
Logf("Sleeping 10 seconds and crossing our fingers that scheduler will run in that time.")
|
Logf("Sleeping 10 seconds and crossing our fingers that scheduler will run in that time.")
|
||||||
time.Sleep(10 * time.Second)
|
time.Sleep(10 * time.Second)
|
||||||
|
|
||||||
verifyResult(c, podName, ns)
|
verifyResult(c, podName, ns, currentlyDeadPods)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user