Skip to content

Commit 65c59f7

Browse files
authored
Improve the handling of random Pod picks (#2319)
1 parent 8e074dc commit 65c59f7

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

e2e/fixtures/pods.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ import (
3535
)
3636

3737
// ChooseRandomPod returns a random pod from the provided array, passing through the provided error.
38+
// TODO(johscheuer): Should we merge ChooseRandomPod and RandomPickOnePod?
3839
func (factory *Factory) ChooseRandomPod(pods *corev1.PodList) *corev1.Pod {
39-
items := pods.Items
40-
if len(items) == 0 {
40+
if len(pods.Items) == 0 {
4141
return nil
4242
}
4343
pickedPod := factory.RandomPickOnePod(pods.Items)
@@ -77,8 +77,13 @@ func (factory *Factory) RandomPickPod(input []corev1.Pod, count int) []corev1.Po
7777

7878
// RandomPickOnePod will pick one Pods randomly from the Pod slice.
7979
func (factory *Factory) RandomPickOnePod(input []corev1.Pod) corev1.Pod {
80-
// TODO(johscheuer): Handle the case where no pod is available.
81-
return factory.RandomPickPod(input, 1)[0]
80+
gomega.Expect(input).NotTo(gomega.BeEmpty(), "cannot pick a random Pod from an empty slice")
81+
randomPods := factory.RandomPickPod(input, 1)
82+
if len(randomPods) > 0 {
83+
return randomPods[0]
84+
}
85+
86+
return input[0]
8287
}
8388

8489
// RandomPickCluster randomly picks the number of FdbCluster from the slice. If the slice contains less than count FdbCluster, all FdbCluster
@@ -102,8 +107,13 @@ func (factory *Factory) RandomPickCluster(input []*FdbCluster, count int) []*Fdb
102107

103108
// RandomPickOneCluster will pick one FdbCluster randomly from the FdbCluster slice.
104109
func (factory *Factory) RandomPickOneCluster(input []*FdbCluster) *FdbCluster {
105-
// TODO(johscheuer): Handle the case where no cluster is available.
106-
return factory.RandomPickCluster(input, 1)[0]
110+
gomega.Expect(input).NotTo(gomega.BeEmpty(), "cannot pick a random FDB cluster from an empty slice")
111+
randomClusters := factory.RandomPickCluster(input, 1)
112+
if len(randomClusters) > 0 {
113+
return randomClusters[0]
114+
}
115+
116+
return input[0]
107117
}
108118

109119
// SetFinalizerForPod will set the provided finalizer slice for the Pods

e2e/test_operator_upgrades/operator_upgrades_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ var _ = Describe("Operator Upgrades", Label("e2e", "pr"), func() {
131131
Eventually(func() bool {
132132
pods := make([]corev1.Pod, 0)
133133
for _, pod := range fdbCluster.GetPods().Items {
134+
// Ignore pods that are in the deletion process.
135+
if !pod.DeletionTimestamp.IsZero() {
136+
continue
137+
}
138+
134139
for _, container := range pod.Spec.Containers {
135140
if container.Name != fdbv1beta2.MainContainerName {
136141
continue

0 commit comments

Comments
 (0)