Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure pod ID bucket is properly updated on rename #11774

Merged
merged 1 commit into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions libpod/boltdb_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,23 @@ func (s *BoltState) SafeRewriteContainerConfig(ctr *Container, oldName, newName
if err := allCtrsBkt.Put([]byte(ctr.ID()), []byte(newName)); err != nil {
return errors.Wrapf(err, "error renaming container %s in all containers bucket in DB", ctr.ID())
}
if ctr.config.Pod != "" {
podsBkt, err := getPodBucket(tx)
if err != nil {
return err
}
podBkt := podsBkt.Bucket([]byte(ctr.config.Pod))
if podBkt == nil {
return errors.Wrapf(define.ErrInternal, "bucket for pod %s does not exist", ctr.config.Pod)
}
podCtrBkt := podBkt.Bucket(containersBkt)
if podCtrBkt == nil {
return errors.Wrapf(define.ErrInternal, "pod %s does not have a containers bucket", ctr.config.Pod)
}
if err := podCtrBkt.Put([]byte(ctr.ID()), []byte(newName)); err != nil {
return errors.Wrapf(err, "error renaming container %s in pod %s members bucket", ctr.ID(), ctr.config.Pod)
}
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions test/e2e/rename_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,29 @@ var _ = Describe("podman rename", func() {
Expect(ps).Should(Exit(0))
Expect(ps.OutputToString()).To(ContainSubstring(newName))
})

It("Rename a container that is part of a pod", func() {
podName := "testPod"
infraName := "infra1"
pod := podmanTest.Podman([]string{"pod", "create", "--name", podName, "--infra-name", infraName})
pod.WaitWithDefaultTimeout()
Expect(pod).Should(Exit(0))

infraName2 := "infra2"
rename := podmanTest.Podman([]string{"rename", infraName, infraName2})
rename.WaitWithDefaultTimeout()
Expect(rename).Should(Exit(0))

remove := podmanTest.Podman([]string{"pod", "rm", "-f", podName})
remove.WaitWithDefaultTimeout()
Expect(remove).Should(Exit(0))

create := podmanTest.Podman([]string{"create", "--name", infraName2, ALPINE, "top"})
create.WaitWithDefaultTimeout()
Expect(create).Should(Exit(0))

create2 := podmanTest.Podman([]string{"create", "--name", infraName, ALPINE, "top"})
create2.WaitWithDefaultTimeout()
Expect(create2).Should(Exit(0))
})
})