Skip to content

Commit 4909bc5

Browse files
racevedoothbkrkr
authored andcommitted
Add statefulset list test (#1936)
This tests a statefulset list with an additional pod that does not belong to the sset and check it is not returned. This was blocked while the fake client did not support label list options. (See kubernetes-sigs/controller-runtime#311)
1 parent 383f59e commit 4909bc5

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

pkg/controller/elasticsearch/sset/list_test.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,20 @@ func TestStatefulSetList_GetExistingPods(t *testing.T) {
7979
},
8080
},
8181
}
82-
client := k8s.WrapClient(fake.NewFakeClient(&pod1, &pod2))
82+
// pod not belonging to the sset
83+
podNotInSset := corev1.Pod{
84+
ObjectMeta: metav1.ObjectMeta{
85+
Name: "pod-not-in-sset",
86+
Labels: map[string]string{
87+
label.StatefulSetNameLabelName: "different-sset",
88+
},
89+
},
90+
}
91+
client := k8s.WrapClient(fake.NewFakeClient(&pod1, &pod2, &podNotInSset))
8392
pods, err := StatefulSetList{ssetv7}.GetActualPods(client)
8493
require.NoError(t, err)
8594
require.Equal(t, []corev1.Pod{pod1, pod2}, pods)
86-
// TODO: test with an additional pod that does not belong to the sset and
87-
// check it is not returned.
88-
// This cannot be done currently since the fake client does not support label list options.
89-
// See https://github.com/kubernetes-sigs/controller-runtime/pull/311
95+
require.NotContains(t, pods, podNotInSset)
9096
}
9197

9298
func TestStatefulSetList_PodReconciliationDone(t *testing.T) {

0 commit comments

Comments
 (0)