Skip to content

Commit cb8a5e2

Browse files
committed
added e2e test with custom image
1 parent 7c11afd commit cb8a5e2

File tree

1 file changed

+115
-0
lines changed

1 file changed

+115
-0
lines changed

tests/e2e/srlinux_controller_e2e_test.go

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,3 +313,118 @@ func testReconciliationWithConfig(
313313

314314
g.Expect(string(b)).Should(ContainSubstring("set from e2e test"))
315315
}
316+
317+
// TestSrlinuxReconciler_WithCustomInitImage tests the reconciliation of the Srlinux custom resource
318+
// with a custom init image specified.
319+
func TestSrlinuxReconciler_WithCustomInitImage(t *testing.T) {
320+
namespace := &corev1.Namespace{
321+
ObjectMeta: metav1.ObjectMeta{
322+
Name: SrlinuxNamespace,
323+
},
324+
}
325+
326+
customInitImage := "us-west1-docker.pkg.dev/kne-external/kne/init-wait:ga"
327+
328+
t.Run("Should reconcile a Srlinux custom resource with custom init image", func(t *testing.T) {
329+
g := NewWithT(t)
330+
331+
createNamespace(t, g, namespace)
332+
defer deleteNamespace(t, g, namespace)
333+
334+
t.Log("Checking that Srlinux resource doesn't exist in the cluster")
335+
srlinux := &srlinuxv1.Srlinux{}
336+
337+
err := k8sClient.Get(ctx, namespacedName, srlinux)
338+
339+
g.Expect(errors.IsNotFound(err)).To(BeTrue())
340+
341+
t.Log("Creating the custom resource with custom init image for the Kind Srlinux")
342+
srlinux = &srlinuxv1.Srlinux{
343+
ObjectMeta: metav1.ObjectMeta{
344+
Name: SrlinuxName,
345+
Namespace: SrlinuxNamespace,
346+
},
347+
TypeMeta: metav1.TypeMeta{
348+
Kind: "Srlinux",
349+
APIVersion: "kne.srlinux.dev/v1",
350+
},
351+
Spec: srlinuxv1.SrlinuxSpec{
352+
Config: &srlinuxv1.NodeConfig{
353+
Image: testImageName,
354+
InitImage: customInitImage,
355+
},
356+
},
357+
}
358+
g.Expect(k8sClient.Create(ctx, srlinux)).Should(Succeed())
359+
360+
t.Log("Checking if the custom resource was successfully created")
361+
g.Eventually(func() error {
362+
found := &srlinuxv1.Srlinux{}
363+
364+
return k8sClient.Get(ctx, namespacedName, found)
365+
}).Should(Succeed())
366+
367+
// Reconcile is triggered by the creation of the custom resource
368+
369+
t.Log("Checking if Srlinux Pod was successfully created in the reconciliation")
370+
g.Eventually(func() error {
371+
found := &corev1.Pod{}
372+
373+
return k8sClient.Get(ctx, namespacedName, found)
374+
}).Should(Succeed())
375+
376+
t.Log("Ensuring the custom init image is used in the pod")
377+
g.Eventually(func() error {
378+
pod := &corev1.Pod{}
379+
g.Expect(k8sClient.Get(ctx, namespacedName, pod)).Should(Succeed())
380+
381+
if len(pod.Spec.InitContainers) == 0 {
382+
return fmt.Errorf("no init containers found in pod")
383+
}
384+
385+
initContainer := pod.Spec.InitContainers[0]
386+
if initContainer.Image != customInitImage {
387+
return fmt.Errorf("got init container image: %s, want: %s", initContainer.Image, customInitImage)
388+
}
389+
390+
return nil
391+
}).Should(Succeed())
392+
393+
t.Log("Ensuring the Srlinux CR pod is running")
394+
g.Eventually(func() bool {
395+
found := &corev1.Pod{}
396+
397+
g.Expect(k8sClient.Get(ctx, namespacedName, found)).Should(Succeed())
398+
399+
return found.Status.Phase == corev1.PodRunning
400+
}, srlinuxMaxStartupTime, time.Second).Should(BeTrue())
401+
402+
t.Log("Ensuring the Srlinux CR Ready status reached true")
403+
404+
g.Eventually(func() bool {
405+
srl := &srlinuxv1.Srlinux{}
406+
g.Expect(k8sClient.Get(ctx, namespacedName, srl)).Should(Succeed())
407+
408+
return srl.Status.Ready == true
409+
}, srlinuxMaxReadyTime).Should(BeTrue())
410+
411+
t.Log("Deleting the custom resource for the Kind Srlinux")
412+
g.Expect(k8sClient.Delete(ctx, srlinux)).Should(Succeed())
413+
414+
t.Log("Checking if the custom resource was successfully deleted")
415+
g.Eventually(func() error {
416+
found := &srlinuxv1.Srlinux{}
417+
418+
return k8sClient.Get(ctx, namespacedName, found)
419+
}).ShouldNot(Succeed())
420+
421+
// Reconcile is triggered by the deletion of the custom resource
422+
423+
t.Log("Checking if the pod was successfully deleted")
424+
g.Eventually(func() error {
425+
found := &corev1.Pod{}
426+
427+
return k8sClient.Get(ctx, namespacedName, found)
428+
}).ShouldNot(Succeed())
429+
})
430+
}

0 commit comments

Comments
 (0)