Skip to content

Commit 3bb0096

Browse files
authored
Add volumeClaimTemplates only if storage.EmptyDir is nil (#234)
2 parents 0c71ffa + 5e27419 commit 3bb0096

File tree

4 files changed

+67
-4
lines changed

4 files changed

+67
-4
lines changed

.golangci.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ issues:
1616
linters:
1717
- dupl
1818
- lll
19+
- path: _test\.go
20+
linters:
21+
- dupl
1922
linters:
2023
disable-all: true
2124
enable:
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
apiVersion: etcd.aenix.io/v1alpha1
3+
kind: EtcdCluster
4+
metadata:
5+
name: test
6+
spec:
7+
storage:
8+
emptyDir:
9+
sizeLimit: 1Gi
10+
replicas: 3

internal/controller/factory/statefulset.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,17 @@ func CreateOrUpdateStatefulSet(
5959
podMetadata.Annotations = cluster.Spec.PodTemplate.Annotations
6060
}
6161

62-
volumeClaimTemplates := []corev1.PersistentVolumeClaim{
63-
{
62+
volumeClaimTemplates := make([]corev1.PersistentVolumeClaim, 0)
63+
if cluster.Spec.Storage.EmptyDir == nil {
64+
volumeClaimTemplates = append(volumeClaimTemplates, corev1.PersistentVolumeClaim{
6465
ObjectMeta: metav1.ObjectMeta{
6566
Name: GetPVCName(cluster),
6667
Labels: cluster.Spec.Storage.VolumeClaimTemplate.Labels,
6768
Annotations: cluster.Spec.Storage.VolumeClaimTemplate.Annotations,
6869
},
6970
Spec: cluster.Spec.Storage.VolumeClaimTemplate.Spec,
7071
Status: cluster.Spec.Storage.VolumeClaimTemplate.Status,
71-
},
72+
})
7273
}
7374

7475
volumes := generateVolumes(cluster)

test/e2e/e2e_test.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ var _ = Describe("etcd-operator", Ordered, func() {
6262

6363
})
6464

65-
if os.Getenv("DO_NOT_CLEANUP_AFTER_E2E") == "true" {
65+
if os.Getenv("DO_CLEANUP_AFTER_E2E") == "true" {
6666
AfterAll(func() {
6767
By("Delete kind environment", func() {
6868
cmd := exec.Command("make", "kind-delete")
@@ -120,6 +120,55 @@ var _ = Describe("etcd-operator", Ordered, func() {
120120
})
121121
})
122122

123+
Context("With emptyDir", func() {
124+
It("should deploy etcd cluster", func() {
125+
var err error
126+
const namespace = "test-emtydir-etcd-cluster"
127+
var wg sync.WaitGroup
128+
wg.Add(1)
129+
130+
By("create namespace", func() {
131+
cmd := exec.Command("sh", "-c",
132+
fmt.Sprintf("kubectl create namespace %s --dry-run=client -o yaml | kubectl apply -f -", namespace)) // nolint:lll
133+
_, err = utils.Run(cmd)
134+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
135+
})
136+
137+
By("apply etcd cluster with emptydir manifest", func() {
138+
dir, _ := utils.GetProjectDir()
139+
cmd := exec.Command("kubectl", "apply",
140+
"--filename", dir+"/examples/manifests/etcdcluster-emptydir.yaml",
141+
"--namespace", namespace,
142+
)
143+
_, err = utils.Run(cmd)
144+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
145+
})
146+
147+
By("wait for statefulset is ready", func() {
148+
cmd := exec.Command("kubectl", "wait",
149+
"statefulset/test",
150+
"--for", "jsonpath={.status.readyReplicas}=3",
151+
"--namespace", namespace,
152+
"--timeout", "5m",
153+
)
154+
_, err = utils.Run(cmd)
155+
ExpectWithOffset(1, err).NotTo(HaveOccurred())
156+
})
157+
158+
client, err := utils.GetEtcdClient(ctx, client.ObjectKey{Namespace: namespace, Name: "test"})
159+
Expect(err).NotTo(HaveOccurred())
160+
defer func() {
161+
err := client.Close()
162+
Expect(err).NotTo(HaveOccurred())
163+
}()
164+
165+
By("check etcd cluster is healthy", func() {
166+
Expect(utils.IsEtcdClusterHealthy(ctx, client)).To(BeTrue())
167+
})
168+
169+
})
170+
})
171+
123172
Context("TLS and enabled auth", func() {
124173
It("should deploy etcd cluster with auth", func() {
125174
var err error

0 commit comments

Comments
 (0)