@@ -35,9 +35,9 @@ import (
35
35
)
36
36
37
37
// ChooseRandomPod returns a random pod from the provided array, passing through the provided error.
38
+ // TODO(johscheuer): Should we merge ChooseRandomPod and RandomPickOnePod?
38
39
func (factory * Factory ) ChooseRandomPod (pods * corev1.PodList ) * corev1.Pod {
39
- items := pods .Items
40
- if len (items ) == 0 {
40
+ if len (pods .Items ) == 0 {
41
41
return nil
42
42
}
43
43
pickedPod := factory .RandomPickOnePod (pods .Items )
@@ -77,8 +77,13 @@ func (factory *Factory) RandomPickPod(input []corev1.Pod, count int) []corev1.Po
77
77
78
78
// RandomPickOnePod will pick one Pods randomly from the Pod slice.
79
79
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 ]
82
87
}
83
88
84
89
// 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
102
107
103
108
// RandomPickOneCluster will pick one FdbCluster randomly from the FdbCluster slice.
104
109
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 ]
107
117
}
108
118
109
119
// SetFinalizerForPod will set the provided finalizer slice for the Pods
0 commit comments