From 9531564d6f14b01d8547efe3507143cddfe1ea92 Mon Sep 17 00:00:00 2001 From: Tarun Pothulapati Date: Tue, 10 Oct 2023 19:22:21 +0530 Subject: [PATCH] feat(e2e): Allow flaky attempts and use ginkgo (#112) --- .github/workflows/ci.yml | 2 +- Makefile | 4 +- e2e/dragonfly_controller_test.go | 48 +++++++++++-------- ...dragonfly_pod_lifecycle_controller_test.go | 8 +--- 4 files changed, 34 insertions(+), 28 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 4750275..a2dae76 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -78,7 +78,7 @@ jobs: DOCKER_BUILDKIT: 1 DOCKER_USERNAME: ${{ github.actor }} DOCKER_PASSWORD: ${{ secrets.GITHUB_TOKEN }} - + - name: publish github release uses: softprops/action-gh-release@v1 with: diff --git a/Makefile b/Makefile index 7e6b87b..3b0b3ab 100644 --- a/Makefile +++ b/Makefile @@ -58,7 +58,8 @@ vet: ## Run go vet against code. .PHONY: test test: manifests generate fmt vet envtest ## Run tests. - KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" go test ./... -coverprofile cover.out + GOBIN=$(LOCALBIN) go install github.com/onsi/ginkgo/v2/ginkgo@v2.12.1 + KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -r -p -coverprofile cover.out ##@ Build @@ -140,6 +141,7 @@ $(LOCALBIN): ## Tool Binaries KUSTOMIZE ?= $(LOCALBIN)/kustomize +GINKGO ?= $(LOCALBIN)/ginkgo CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen ENVTEST ?= $(LOCALBIN)/setup-envtest diff --git a/e2e/dragonfly_controller_test.go b/e2e/dragonfly_controller_test.go index 0cd7285..70092f1 100644 --- a/e2e/dragonfly_controller_test.go +++ b/e2e/dragonfly_controller_test.go @@ -40,7 +40,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -var _ = Describe("Dragonfly Lifecycle tests", Ordered, func() { +var _ = Describe("Dragonfly Lifecycle tests", Ordered, FlakeAttempts(3), func() { ctx := context.Background() name := "df-test" namespace := "default" @@ -131,17 +131,22 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, func() { }, }) Expect(err).To(BeNil()) + }) - err = k8sClient.Create(ctx, &df) + It("Should create successfully", func() { + err := k8sClient.Create(ctx, &df) Expect(err).To(BeNil()) // Wait until Dragonfly object is marked initialized waitForDragonflyPhase(ctx, k8sClient, name, namespace, controller.PhaseResourcesCreated, 2*time.Minute) waitForStatefulSetReady(ctx, k8sClient, name, namespace, 2*time.Minute) + }) + + var ss appsv1.StatefulSet + It("Check for values in statefulset", func() { // Check for service and statefulset - var ss appsv1.StatefulSet - err = k8sClient.Get(ctx, types.NamespacedName{ + err := k8sClient.Get(ctx, types.NamespacedName{ Name: name, Namespace: namespace, }, &ss) @@ -160,17 +165,6 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, func() { expectArgs := append(resources.DefaultDragonflyArgs, df.Spec.Args...) Expect(ss.Spec.Template.Spec.Containers[0].Args).To(ContainElements(expectArgs)) - // Check if there are relevant pods with expected roles - var pods corev1.PodList - err = k8sClient.List(ctx, &pods, client.InNamespace(namespace), client.MatchingLabels{ - "app": name, - resources.KubernetesPartOfLabelKey: "dragonfly", - }) - Expect(err).To(BeNil()) - - // 3 pod replicas = 1 master + 2 replicas - Expect(pods.Items).To(HaveLen(3)) - // check for pod resources Expect(ss.Spec.Template.Spec.Containers[0].Resources.Limits[corev1.ResourceCPU].Equal(resourcesReq.Limits[corev1.ResourceCPU])).To(BeTrue()) Expect(ss.Spec.Template.Spec.Containers[0].Resources.Limits[corev1.ResourceMemory].Equal(resourcesReq.Limits[corev1.ResourceMemory])).To(BeTrue()) @@ -207,7 +201,23 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, func() { }, }, })) + }) + It("Check for pod values", func() { + // Check if there are relevant pods with expected roles + var pods corev1.PodList + err := k8sClient.List(ctx, &pods, client.InNamespace(namespace), client.MatchingLabels{ + "app": name, + resources.KubernetesPartOfLabelKey: "dragonfly", + }) + Expect(err).To(BeNil()) + + // 3 pod replicas = 1 master + 2 replicas + Expect(pods.Items).To(HaveLen(3)) + + }) + + It("Check for connectivity", func() { stopChan := make(chan struct{}, 1) rc, err := InitRunCmd(ctx, stopChan, name, namespace, "df-pass-1") defer close(stopChan) @@ -271,12 +281,10 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, func() { err = k8sClient.Update(ctx, &df) Expect(err).To(BeNil()) - // Wait until Dragonfly object is marked resources-created + // Wait until Dragonfly object is marked ready waitForDragonflyPhase(ctx, k8sClient, name, namespace, controller.PhaseReady, 2*time.Minute) waitForStatefulSetReady(ctx, k8sClient, name, namespace, 2*time.Minute) - time.Sleep(40 * time.Second) - // Check for service and statefulset var ss appsv1.StatefulSet err = k8sClient.Get(ctx, types.NamespacedName{ @@ -486,7 +494,7 @@ var _ = Describe("Dragonfly Lifecycle tests", Ordered, func() { }) }) -var _ = Describe("Dragonfly PVC Test", Ordered, func() { +var _ = Describe("Dragonfly PVC Test", Ordered, FlakeAttempts(3), func() { ctx := context.Background() name := "df-pvc" @@ -571,7 +579,7 @@ var _ = Describe("Dragonfly PVC Test", Ordered, func() { }) }) -var _ = Describe("Dragonfly TLS tests", Ordered, func() { +var _ = Describe("Dragonfly TLS tests", Ordered, FlakeAttempts(3), func() { ctx := context.Background() name := "df-tls" namespace := "default" diff --git a/e2e/dragonfly_pod_lifecycle_controller_test.go b/e2e/dragonfly_pod_lifecycle_controller_test.go index f27df92..682ca61 100644 --- a/e2e/dragonfly_pod_lifecycle_controller_test.go +++ b/e2e/dragonfly_pod_lifecycle_controller_test.go @@ -18,7 +18,6 @@ package e2e import ( "context" - "fmt" "time" dfv1alpha1 "github.com/dragonflydb/dragonfly-operator/api/v1alpha1" @@ -33,7 +32,7 @@ import ( "sigs.k8s.io/controller-runtime/pkg/client" ) -var _ = Describe("DF Pod Lifecycle Reconciler", Ordered, func() { +var _ = Describe("DF Pod Lifecycle Reconciler", Ordered, FlakeAttempts(3), func() { ctx := context.Background() podRoles := map[string][]string{ resources.Master: make([]string, 0), @@ -50,7 +49,6 @@ var _ = Describe("DF Pod Lifecycle Reconciler", Ordered, func() { }, Spec: dfv1alpha1.DragonflySpec{ Replicas: int32(replicas), - Image: fmt.Sprintf("%s:%s", resources.DragonflyImage, "latest"), }, } @@ -78,9 +76,6 @@ var _ = Describe("DF Pod Lifecycle Reconciler", Ordered, func() { }, &svc) Expect(err).To(BeNil()) - err = waitForStatefulSetReady(ctx, k8sClient, name, namespace, 1*time.Minute) - Expect(err).To(BeNil()) - err = waitForDragonflyPhase(ctx, k8sClient, name, namespace, controller.PhaseReady, 1*time.Minute) Expect(err).To(BeNil()) @@ -110,6 +105,7 @@ var _ = Describe("DF Pod Lifecycle Reconciler", Ordered, func() { }) It("New Master is elected as old one dies", func() { + // Get & Delete the old master var pod corev1.Pod err := k8sClient.Get(ctx, types.NamespacedName{