mirror of https://github.com/k3s-io/k3s
Merge pull request #7198 from yujuhong/fix_filter
Fix pod filtering in replication controllerpull/6/head
commit
35cbbe6bde
|
@ -190,10 +190,10 @@ func (rm *ReplicationManager) watchControllers(resourceVersion *string) {
|
||||||
// filterActivePods returns pods that have not terminated.
|
// filterActivePods returns pods that have not terminated.
|
||||||
func filterActivePods(pods []api.Pod) []*api.Pod {
|
func filterActivePods(pods []api.Pod) []*api.Pod {
|
||||||
var result []*api.Pod
|
var result []*api.Pod
|
||||||
for _, value := range pods {
|
for i := range pods {
|
||||||
if api.PodSucceeded != value.Status.Phase &&
|
if api.PodSucceeded != pods[i].Status.Phase &&
|
||||||
api.PodFailed != value.Status.Phase {
|
api.PodFailed != pods[i].Status.Phase {
|
||||||
result = append(result, &value)
|
result = append(result, &pods[i])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -379,6 +379,25 @@ func TestWatchControllers(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestActivePodFiltering(t *testing.T) {
|
||||||
|
podList := newPodList(5)
|
||||||
|
podList.Items[0].Status.Phase = api.PodSucceeded
|
||||||
|
podList.Items[1].Status.Phase = api.PodFailed
|
||||||
|
expectedNames := util.NewStringSet()
|
||||||
|
for _, pod := range podList.Items[2:] {
|
||||||
|
expectedNames.Insert(pod.Name)
|
||||||
|
}
|
||||||
|
|
||||||
|
got := filterActivePods(podList.Items)
|
||||||
|
gotNames := util.NewStringSet()
|
||||||
|
for _, pod := range got {
|
||||||
|
gotNames.Insert(pod.Name)
|
||||||
|
}
|
||||||
|
if expectedNames.Difference(gotNames).Len() != 0 || gotNames.Difference(expectedNames).Len() != 0 {
|
||||||
|
t.Errorf("expected %v, got %v", expectedNames.List(), gotNames.List())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestSortingActivePods(t *testing.T) {
|
func TestSortingActivePods(t *testing.T) {
|
||||||
numPods := 5
|
numPods := 5
|
||||||
podList := newPodList(numPods)
|
podList := newPodList(numPods)
|
||||||
|
|
Loading…
Reference in New Issue