diff --git a/e2e/Makefile b/e2e/Makefile index 0153eeb1..b5db0fd0 100644 --- a/e2e/Makefile +++ b/e2e/Makefile @@ -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: diff --git a/e2e/partition_test.go b/e2e/partition_test.go index 060c66b8..abc2aaa3 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,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 { diff --git a/e2e/testdata/partition_volume_template.yaml b/e2e/testdata/partition_volume_template.yaml new file mode 100644 index 00000000..fa1e69dc --- /dev/null +++ b/e2e/testdata/partition_volume_template.yaml @@ -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