Skip to content

Commit

Permalink
Add volumeClaimTemplates only if storage.EmptyDir is nil (#234)
Browse files Browse the repository at this point in the history
  • Loading branch information
aobort authored Jun 20, 2024
2 parents 0c71ffa + 5e27419 commit 3bb0096
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ issues:
linters:
- dupl
- lll
- path: _test\.go
linters:
- dupl
linters:
disable-all: true
enable:
Expand Down
10 changes: 10 additions & 0 deletions examples/manifests/etcdcluster-emptydir.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
apiVersion: etcd.aenix.io/v1alpha1
kind: EtcdCluster
metadata:
name: test
spec:
storage:
emptyDir:
sizeLimit: 1Gi
replicas: 3
7 changes: 4 additions & 3 deletions internal/controller/factory/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,17 @@ 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,
Annotations: cluster.Spec.Storage.VolumeClaimTemplate.Annotations,
},
Spec: cluster.Spec.Storage.VolumeClaimTemplate.Spec,
Status: cluster.Spec.Storage.VolumeClaimTemplate.Status,
},
})
}

volumes := generateVolumes(cluster)
Expand Down
51 changes: 50 additions & 1 deletion test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3bb0096

Please sign in to comment.