mirror of
https://github.com/containers/podman.git
synced 2025-07-03 17:27:18 +08:00
Merge pull request #26209 from jankaluza/26190
Recreate the Rootfs in mountStorage for infra-container.
This commit is contained in:
@ -1773,6 +1773,15 @@ func (c *Container) mountStorage() (_ string, deferredErr error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("rootfs-overlay: failed to create TempDir in the %s directory: %w", overlayDest, err)
|
return "", fmt.Errorf("rootfs-overlay: failed to create TempDir in the %s directory: %w", overlayDest, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Recreate the rootfs for infra container. It can be missing after system reboot if it's stored on tmpfs.
|
||||||
|
if c.IsDefaultInfra() || c.IsService() {
|
||||||
|
err := c.createInitRootfs()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
overlayMount, err := overlay.Mount(contentDir, c.config.Rootfs, overlayDest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
|
overlayMount, err := overlay.Mount(contentDir, c.config.Rootfs, overlayDest, c.RootUID(), c.RootGID(), c.runtime.store.GraphOptions())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", fmt.Errorf("rootfs-overlay: creating overlay failed %q: %w", c.config.Rootfs, err)
|
return "", fmt.Errorf("rootfs-overlay: creating overlay failed %q: %w", c.config.Rootfs, err)
|
||||||
|
@ -179,10 +179,26 @@ func getOverlayUpperAndWorkDir(options []string) (string, string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Internal only function which creates the Rootfs for default internal
|
// Internal only function which creates the Rootfs for default internal
|
||||||
// pause image, configures the Rootfs in the Container and returns
|
// pause image and configures the Rootfs in the Container.
|
||||||
// the mount-point for the /catatonit. This mount-point should be added
|
func (c *Container) createInitRootfs() error {
|
||||||
// to the Container spec.
|
tmpDir, err := c.runtime.TmpDir()
|
||||||
func (c *Container) prepareInitRootfs() (spec.Mount, error) {
|
if err != nil {
|
||||||
|
return fmt.Errorf("getting runtime temporary directory: %w", err)
|
||||||
|
}
|
||||||
|
tmpDir = filepath.Join(tmpDir, "infra-container")
|
||||||
|
err = os.MkdirAll(tmpDir, 0755)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("creating infra container temporary directory: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
c.config.Rootfs = tmpDir
|
||||||
|
c.config.RootfsOverlay = true
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Internal only function which returns the mount-point for the /catatonit.
|
||||||
|
// This mount-point should be added to the Container spec.
|
||||||
|
func (c *Container) prepareCatatonitMount() (spec.Mount, error) {
|
||||||
newMount := spec.Mount{
|
newMount := spec.Mount{
|
||||||
Type: define.TypeBind,
|
Type: define.TypeBind,
|
||||||
Source: "",
|
Source: "",
|
||||||
@ -190,15 +206,6 @@ func (c *Container) prepareInitRootfs() (spec.Mount, error) {
|
|||||||
Options: append(bindOptions, "ro", "nosuid", "nodev"),
|
Options: append(bindOptions, "ro", "nosuid", "nodev"),
|
||||||
}
|
}
|
||||||
|
|
||||||
tmpDir, err := c.runtime.TmpDir()
|
|
||||||
if err != nil {
|
|
||||||
return newMount, fmt.Errorf("getting runtime temporary directory: %w", err)
|
|
||||||
}
|
|
||||||
tmpDir = filepath.Join(tmpDir, "infra-container")
|
|
||||||
err = os.MkdirAll(tmpDir, 0755)
|
|
||||||
if err != nil {
|
|
||||||
return newMount, fmt.Errorf("creating infra container temporary directory: %w", err)
|
|
||||||
}
|
|
||||||
// Also look into the path as some distributions install catatonit in
|
// Also look into the path as some distributions install catatonit in
|
||||||
// /usr/bin.
|
// /usr/bin.
|
||||||
catatonitPath, err := c.runtime.config.FindInitBinary()
|
catatonitPath, err := c.runtime.config.FindInitBinary()
|
||||||
@ -213,8 +220,6 @@ func (c *Container) prepareInitRootfs() (spec.Mount, error) {
|
|||||||
newMount.Source = catatonitPath
|
newMount.Source = catatonitPath
|
||||||
newMount.Destination = "/" + filepath.Base(catatonitPath)
|
newMount.Destination = "/" + filepath.Base(catatonitPath)
|
||||||
|
|
||||||
c.config.Rootfs = tmpDir
|
|
||||||
c.config.RootfsOverlay = true
|
|
||||||
if len(c.config.Entrypoint) == 0 {
|
if len(c.config.Entrypoint) == 0 {
|
||||||
c.config.Entrypoint = []string{"/" + filepath.Base(catatonitPath), "-P"}
|
c.config.Entrypoint = []string{"/" + filepath.Base(catatonitPath), "-P"}
|
||||||
c.config.Spec.Process.Args = c.config.Entrypoint
|
c.config.Spec.Process.Args = c.config.Entrypoint
|
||||||
@ -426,7 +431,7 @@ func (c *Container) generateSpec(ctx context.Context) (s *spec.Spec, cleanupFunc
|
|||||||
c.setMountLabel(&g)
|
c.setMountLabel(&g)
|
||||||
|
|
||||||
if c.IsDefaultInfra() || c.IsService() {
|
if c.IsDefaultInfra() || c.IsService() {
|
||||||
newMount, err := c.prepareInitRootfs()
|
newMount, err := c.prepareCatatonitMount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
@ -250,7 +250,11 @@ func (r *Runtime) newContainer(ctx context.Context, rSpec *spec.Spec, options ..
|
|||||||
|
|
||||||
func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Container, retErr error) {
|
func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Container, retErr error) {
|
||||||
if ctr.IsDefaultInfra() || ctr.IsService() {
|
if ctr.IsDefaultInfra() || ctr.IsService() {
|
||||||
_, err := ctr.prepareInitRootfs()
|
err := ctr.createInitRootfs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
_, err = ctr.prepareCatatonitMount()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -1475,6 +1475,27 @@ VOLUME %s`, ALPINE, volPath, volPath)
|
|||||||
Expect(numContainers).To(Equal(0))
|
Expect(numContainers).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman run after infra-container rootfs removed", func() {
|
||||||
|
// Regression test for #26190
|
||||||
|
podmanTest.PodmanExitCleanly("run", "--name", "test", "--pod", "new:foobar", ALPINE, "ls")
|
||||||
|
|
||||||
|
podInspect := podmanTest.PodmanExitCleanly("pod", "inspect", "foobar", "--format", "{{.InfraContainerID}}")
|
||||||
|
infraID := podInspect.OutputToString()
|
||||||
|
|
||||||
|
infraInspect := podmanTest.PodmanExitCleanly("inspect", infraID, "--format", "{{.Rootfs}}")
|
||||||
|
rootfs := infraInspect.OutputToString()
|
||||||
|
|
||||||
|
podmanTest.PodmanExitCleanly("pod", "stop", "foobar")
|
||||||
|
|
||||||
|
_, statErr := os.Stat(rootfs)
|
||||||
|
Expect(statErr).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
err := os.RemoveAll(rootfs)
|
||||||
|
Expect(err).ToNot(HaveOccurred())
|
||||||
|
|
||||||
|
podmanTest.PodmanExitCleanly("run", "--replace", "--name", "test", "--pod", "foobar", ALPINE, "ls")
|
||||||
|
})
|
||||||
|
|
||||||
It("podman run --rm failed container should delete itself", func() {
|
It("podman run --rm failed container should delete itself", func() {
|
||||||
session := podmanTest.Podman([]string{"run", "--name", "test", "--rm", ALPINE, "foo"})
|
session := podmanTest.Podman([]string{"run", "--name", "test", "--rm", ALPINE, "foo"})
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user