From 2ef99eeb4807a446b384ab3da1151268dbdf7ebe Mon Sep 17 00:00:00 2001 From: Artem Bortnikov Date: Thu, 6 Jun 2024 15:26:43 +0300 Subject: [PATCH 1/3] add volumeClaimTemplates only if storage.EmptyDir is nil Signed-off-by: Artem Bortnikov --- internal/controller/factory/statefulset.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/internal/controller/factory/statefulset.go b/internal/controller/factory/statefulset.go index 68dc9b1c..4fd5c91e 100644 --- a/internal/controller/factory/statefulset.go +++ b/internal/controller/factory/statefulset.go @@ -59,8 +59,9 @@ func CreateOrUpdateStatefulSet( podMetadata.Annotations = cluster.Spec.PodTemplate.Annotations } - volumeClaimTemplates := []corev1.PersistentVolumeClaim{ - { + volumeClaimTemplates := make([]corev1.PersistentVolumeClaim, 0) + if cluster.Spec.Storage.EmptyDir == nil { + volumeClaimTemplates = append(volumeClaimTemplates, corev1.PersistentVolumeClaim{ ObjectMeta: metav1.ObjectMeta{ Name: GetPVCName(cluster), Labels: cluster.Spec.Storage.VolumeClaimTemplate.Labels, @@ -68,7 +69,7 @@ func CreateOrUpdateStatefulSet( }, Spec: cluster.Spec.Storage.VolumeClaimTemplate.Spec, Status: cluster.Spec.Storage.VolumeClaimTemplate.Status, - }, + }) } volumes := generateVolumes(cluster) From a5f7cb9c7c07bbbedd818f3ddbd77e2e246fa175 Mon Sep 17 00:00:00 2001 From: Artem Bortnikov Date: Thu, 20 Jun 2024 17:44:57 +0300 Subject: [PATCH 2/3] e2e test for etcd cluster with empydir storage Signed-off-by: Artem Bortnikov --- examples/manifests/etcdcluster-emptydir.yaml | 10 ++++ test/e2e/e2e_test.go | 51 +++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 examples/manifests/etcdcluster-emptydir.yaml diff --git a/examples/manifests/etcdcluster-emptydir.yaml b/examples/manifests/etcdcluster-emptydir.yaml new file mode 100644 index 00000000..06871b89 --- /dev/null +++ b/examples/manifests/etcdcluster-emptydir.yaml @@ -0,0 +1,10 @@ +--- +apiVersion: etcd.aenix.io/v1alpha1 +kind: EtcdCluster +metadata: + name: test +spec: + storage: + emptyDir: + sizeLimit: 1Gi + replicas: 3 diff --git a/test/e2e/e2e_test.go b/test/e2e/e2e_test.go index c9967858..aadc826f 100644 --- a/test/e2e/e2e_test.go +++ b/test/e2e/e2e_test.go @@ -62,7 +62,7 @@ var _ = Describe("etcd-operator", Ordered, func() { }) - if os.Getenv("DO_NOT_CLEANUP_AFTER_E2E") == "true" { + if os.Getenv("DO_CLEANUP_AFTER_E2E") == "true" { AfterAll(func() { By("Delete kind environment", func() { cmd := exec.Command("make", "kind-delete") @@ -120,6 +120,55 @@ var _ = Describe("etcd-operator", Ordered, func() { }) }) + Context("With emptyDir", func() { + It("should deploy etcd cluster", func() { + var err error + const namespace = "test-emtydir-etcd-cluster" + var wg sync.WaitGroup + wg.Add(1) + + By("create namespace", func() { + cmd := exec.Command("sh", "-c", + fmt.Sprintf("kubectl create namespace %s --dry-run=client -o yaml | kubectl apply -f -", namespace)) // nolint:lll + _, err = utils.Run(cmd) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + }) + + By("apply etcd cluster with emptydir manifest", func() { + dir, _ := utils.GetProjectDir() + cmd := exec.Command("kubectl", "apply", + "--filename", dir+"/examples/manifests/etcdcluster-emptydir.yaml", + "--namespace", namespace, + ) + _, err = utils.Run(cmd) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + }) + + By("wait for statefulset is ready", func() { + cmd := exec.Command("kubectl", "wait", + "statefulset/test", + "--for", "jsonpath={.status.readyReplicas}=3", + "--namespace", namespace, + "--timeout", "5m", + ) + _, err = utils.Run(cmd) + ExpectWithOffset(1, err).NotTo(HaveOccurred()) + }) + + client, err := utils.GetEtcdClient(ctx, client.ObjectKey{Namespace: namespace, Name: "test"}) + Expect(err).NotTo(HaveOccurred()) + defer func() { + err := client.Close() + Expect(err).NotTo(HaveOccurred()) + }() + + By("check etcd cluster is healthy", func() { + Expect(utils.IsEtcdClusterHealthy(ctx, client)).To(BeTrue()) + }) + + }) + }) + Context("TLS and enabled auth", func() { It("should deploy etcd cluster with auth", func() { var err error From 5e27419dab668bb003448562bb8b0a0962e65434 Mon Sep 17 00:00:00 2001 From: Artem Bortnikov Date: Thu, 20 Jun 2024 21:06:58 +0300 Subject: [PATCH 3/3] upd golangci-lint rules Signed-off-by: Artem Bortnikov --- .golangci.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.golangci.yml b/.golangci.yml index aed8644d..32eec7ed 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -16,6 +16,9 @@ issues: linters: - dupl - lll + - path: _test\.go + linters: + - dupl linters: disable-all: true enable: