Skip to content

Commit

Permalink
issue-747: fix podname
Browse files Browse the repository at this point in the history
  • Loading branch information
shunki-fujita committed Nov 19, 2024
1 parent 4daa5e0 commit f537739
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions clustering/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,7 @@ var _ = Describe("manager", func() {
Expect(ms.backupWorkDirUsage).To(MetricsIs("==", 30))
Expect(ms.backupWarnings).To(MetricsIs("==", 2))
})

It("should detect replication delay and prevent deletion of primary", func() {
testSetupResources(ctx, 3, "")

Expand Down
16 changes: 8 additions & 8 deletions e2e/prevent_delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ var _ = Context("PreventDelete", func() {

// add prevent-delete annotation and wait for it to be removed
for i := 0; i < 3; i++ {
kubectlSafe(nil, "annotate", "pod", "-n", "prevent-delete", fmt.Sprintf("moco-test-%d", i), "moco.cybozu.com/prevent-delete=true")
kubectlSafe(nil, "annotate", "pod", "-n", "prevent-delete", cluster.PodName(i), "moco.cybozu.com/prevent-delete=true")
Eventually(func() error {
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", fmt.Sprintf("moco-test-%d", i), "-o", "json")
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", cluster.PodName(i), "-o", "json")
Expect(err).NotTo(HaveOccurred())
pod := &corev1.Pod{}
err = json.Unmarshal(out, pod)
Expand All @@ -119,7 +119,7 @@ var _ = Context("PreventDelete", func() {

// wait for prevent-delete annotation to be added
Eventually(func() error {
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", fmt.Sprintf("moco-test-%d", primary), "-o", "json")
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", cluster.PodName(primary), "-o", "json")
Expect(err).NotTo(HaveOccurred())
pod := &corev1.Pod{}
err = json.Unmarshal(out, pod)
Expand All @@ -133,15 +133,15 @@ var _ = Context("PreventDelete", func() {
}).Should(Succeed())

// fail to delete pod with prevent-delete annotation
_, err = kubectl(nil, "delete", "pod", "-n", "prevent-delete", fmt.Sprintf("moco-test-%d", primary))
Expect(err.Error()).To(ContainSubstring("moco-test-%d is protected from deletion", primary))
_, err = kubectl(nil, "delete", "pod", "-n", "prevent-delete", cluster.PodName(primary))
Expect(err.Error()).To(ContainSubstring("%s is protected from deletion", cluster.PodName(primary)))

// resolve replication delay
setSourceDelay(0, 0)

// wait for prevent-delete annotation to be removed
Eventually(func() error {
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", fmt.Sprintf("moco-test-%d", primary), "-o", "json")
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", cluster.PodName(primary), "-o", "json")
Expect(err).NotTo(HaveOccurred())
pod := &corev1.Pod{}
err = json.Unmarshal(out, pod)
Expand All @@ -163,7 +163,7 @@ var _ = Context("PreventDelete", func() {

// wait for prevent-delete annotation to be added
Eventually(func() error {
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", fmt.Sprintf("moco-test-%d", primary), "-o", "json")
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", cluster.PodName(primary), "-o", "json")
Expect(err).NotTo(HaveOccurred())
pod := &corev1.Pod{}
err = json.Unmarshal(out, pod)
Expand Down Expand Up @@ -234,7 +234,7 @@ var _ = Context("PreventDelete", func() {

// wait for prevent-delete annotation to be added
Eventually(func() error {
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", fmt.Sprintf("moco-test-%d", primary), "-o", "json")
out, err := kubectl(nil, "get", "pod", "-n", "prevent-delete", cluster.PodName(primary), "-o", "json")
Expect(err).NotTo(HaveOccurred())
pod := &corev1.Pod{}
err = json.Unmarshal(out, pod)
Expand Down

0 comments on commit f537739

Please sign in to comment.