Skip to content

Commit

Permalink
feat(e2e): Allow flaky attempts and use ginkgo (#112)
Browse files Browse the repository at this point in the history
  • Loading branch information
Pothulapati authored Oct 10, 2023
1 parent 01a9977 commit 9531564
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 28 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected]
KUBEBUILDER_ASSETS="$(shell $(ENVTEST) use $(ENVTEST_K8S_VERSION) --bin-dir $(LOCALBIN) -p path)" $(GINKGO) -r -p -coverprofile cover.out

##@ Build

Expand Down Expand Up @@ -140,6 +141,7 @@ $(LOCALBIN):

## Tool Binaries
KUSTOMIZE ?= $(LOCALBIN)/kustomize
GINKGO ?= $(LOCALBIN)/ginkgo
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
ENVTEST ?= $(LOCALBIN)/setup-envtest

Expand Down
48 changes: 28 additions & 20 deletions e2e/dragonfly_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand All @@ -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())
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down
8 changes: 2 additions & 6 deletions e2e/dragonfly_pod_lifecycle_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package e2e

import (
"context"
"fmt"
"time"

dfv1alpha1 "github.com/dragonflydb/dragonfly-operator/api/v1alpha1"
Expand All @@ -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),
Expand All @@ -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"),
},
}

Expand Down Expand Up @@ -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())

Expand Down Expand Up @@ -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{
Expand Down

0 comments on commit 9531564

Please sign in to comment.