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: 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/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) 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