Skip to content

Commit fcd2fcf

Browse files
authored
Merge pull request #2881 from clyang82/dynamic_watcher
✨ Add dynamic watcher tests
2 parents b33709f + c6937ff commit fcd2fcf

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

pkg/controller/controller_integration_test.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,35 @@ var _ = Describe("controller", func() {
171171
err = cm.GetClient().
172172
List(context.Background(), &controllertest.UnconventionalListTypeList{})
173173
Expect(err).NotTo(HaveOccurred())
174+
175+
By("Invoking Reconciling for a pod when it is created when adding watcher dynamically")
176+
// Add new watcher dynamically
177+
err = instance.Watch(source.Kind(cm.GetCache(), &corev1.Pod{}, &handler.TypedEnqueueRequestForObject[*corev1.Pod]{}))
178+
Expect(err).NotTo(HaveOccurred())
179+
180+
pod := &corev1.Pod{
181+
ObjectMeta: metav1.ObjectMeta{Name: "pod-name"},
182+
Spec: corev1.PodSpec{
183+
Containers: []corev1.Container{
184+
{
185+
Name: "nginx",
186+
Image: "nginx:latest",
187+
Ports: []corev1.ContainerPort{
188+
{
189+
ContainerPort: 80,
190+
},
191+
},
192+
},
193+
},
194+
},
195+
}
196+
expectedReconcileRequest = reconcile.Request{NamespacedName: types.NamespacedName{
197+
Namespace: "default",
198+
Name: "pod-name",
199+
}}
200+
_, err = clientset.CoreV1().Pods("default").Create(ctx, pod, metav1.CreateOptions{})
201+
Expect(err).NotTo(HaveOccurred())
202+
Expect(<-reconciled).To(Equal(expectedReconcileRequest))
174203
})
175204
})
176205
})

0 commit comments

Comments
 (0)