From ddae9ebf39e2cc49ebe4a702a6abb1912a352638 Mon Sep 17 00:00:00 2001 From: d-kuro Date: Wed, 14 Aug 2024 10:27:45 +0900 Subject: [PATCH] Add pvc template update e2e tests. Signed-off-by: d-kuro --- e2e/partition_test.go | 36 +++++++++++++++++++++ e2e/testdata/partition_volume_template.yaml | 25 ++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 e2e/testdata/partition_volume_template.yaml diff --git a/e2e/partition_test.go b/e2e/partition_test.go index 060c66b8..d76b59a1 100644 --- a/e2e/partition_test.go +++ b/e2e/partition_test.go @@ -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 @@ -160,6 +163,39 @@ var _ = Context("partition_test", func() { Expect(updatedReplicasMetric.GetGauge().GetValue()).To(BeNumerically(">", 0)) }) + It("should volume template change succeed", func() { + // add label for pvc + kubectlSafe(fillTemplate(volumeTemplateApplyYAML), "apply", "-f", "-") + Eventually(func() error { + 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 { diff --git a/e2e/testdata/partition_volume_template.yaml b/e2e/testdata/partition_volume_template.yaml new file mode 100644 index 00000000..767e54e0 --- /dev/null +++ b/e2e/testdata/partition_volume_template.yaml @@ -0,0 +1,25 @@ +apiVersion: moco.cybozu.com/v1beta2 +kind: MySQLCluster +metadata: + namespace: partition + name: test +spec: + replicas: 3 + podTemplate: + 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