Skip to content

Commit

Permalink
Add pvc template update e2e tests.
Browse files Browse the repository at this point in the history
Signed-off-by: d-kuro <[email protected]>
  • Loading branch information
d-kuro committed Aug 14, 2024
1 parent 61123fc commit c97f237
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 1 deletion.
2 changes: 1 addition & 1 deletion e2e/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ endif
.PHONY: test
test:
env PATH="$$(pwd)/../bin:$$PATH" RUN_E2E=1 \
go test -v -race -timeout 60m . -ginkgo.progress -ginkgo.v -ginkgo.failFast
go test -v -race -timeout 90m . -ginkgo.progress -ginkgo.v -ginkgo.failFast

.PHONY: test-upgrade
test-upgrade:
Expand Down
52 changes: 52 additions & 0 deletions e2e/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ var forceRollingUpdateApplyYAML string
//go:embed testdata/partition_image_pull_backoff.yaml
var imagePullBackoffApplyYAML string

//go:embed testdata/partition_volume_template.yaml
var volumeTemplateApplyYAML string

var _ = Context("partition_test", func() {
if doUpgrade {
return
Expand Down Expand Up @@ -160,6 +163,55 @@ var _ = Context("partition_test", func() {
Expect(updatedReplicasMetric.GetGauge().GetValue()).To(BeNumerically(">", 0))
})

It("should volume template change succeed", func() {
// add labels to the volume template and pods.
kubectlSafe(fillTemplate(volumeTemplateApplyYAML), "apply", "-f", "-")
Eventually(func() error {
out, err := kubectl(nil, "get", "-n", "partition", "pod", "-o", "json")
if err != nil {
return err
}
pods := &corev1.PodList{}
if err := json.Unmarshal(out, pods); err != nil {
return err
}

for _, pod := range pods.Items {
_, ok := pod.Labels["foo"]
if !ok {
return fmt.Errorf("pod %s is not changed", pod.Name)
}
}

cluster, err := getCluster("partition", "test")
if err != nil {
return err
}
for _, cond := range cluster.Status.Conditions {
if cond.Type != mocov1beta2.ConditionHealthy {
continue
}
if cond.Status == metav1.ConditionTrue {
return nil
}
return fmt.Errorf("cluster is not healthy: %s", cond.Status)
}

return errors.New("no health condition")
}).WithTimeout(time.Minute * 10).Should(Succeed())
})

It("should recreate statefulset", func() {
out, err := kubectl(nil, "get", "-n", "partition", "statefulset", "moco-test", "-o", "json")
Expect(err).NotTo(HaveOccurred())
sts := &appsv1.StatefulSet{}
err = json.Unmarshal(out, sts)
Expect(err).NotTo(HaveOccurred())
Expect(sts.Spec.UpdateStrategy.RollingUpdate).NotTo(BeNil())
Expect(*sts.Spec.UpdateStrategy.RollingUpdate.Partition).To(Equal(int32(0)))
Expect(sts.Spec.VolumeClaimTemplates[0].Labels["foo"]).To(Equal("bar"))
})

It("should image pull backoff", func() {
kubectlSafe(fillTemplate(imagePullBackoffApplyYAML), "apply", "-f", "-")
Eventually(func() error {
Expand Down
28 changes: 28 additions & 0 deletions e2e/testdata/partition_volume_template.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
apiVersion: moco.cybozu.com/v1beta2
kind: MySQLCluster
metadata:
namespace: partition
name: test
spec:
replicas: 3
podTemplate:
metadata:
labels:
foo: bar
spec:
containers:
- name: mysqld
image: ghcr.io/cybozu-go/moco/mysql:{{ . }}
resources:
requests:
cpu: 1m
volumeClaimTemplates:
- metadata:
name: mysql-data
labels:
foo: bar
spec:
accessModes: [ "ReadWriteOnce" ]
resources:
requests:
storage: 1Gi

0 comments on commit c97f237

Please sign in to comment.