mirror of
https://github.com/containers/podman.git
synced 2025-10-24 06:54:17 +08:00
Merge pull request #9240 from rhatdan/reset
Do not reset storage when running inside of a container
This commit is contained in:
@ -1627,7 +1627,7 @@ func (c *Container) makeBindMounts() error {
|
|||||||
|
|
||||||
// Make .containerenv if it does not exist
|
// Make .containerenv if it does not exist
|
||||||
if _, ok := c.state.BindMounts["/run/.containerenv"]; !ok {
|
if _, ok := c.state.BindMounts["/run/.containerenv"]; !ok {
|
||||||
var containerenv string
|
containerenv := c.runtime.graphRootMountedFlag(c.config.Spec.Mounts)
|
||||||
isRootless := 0
|
isRootless := 0
|
||||||
if rootless.IsRootless() {
|
if rootless.IsRootless() {
|
||||||
isRootless = 1
|
isRootless = 1
|
||||||
@ -1642,7 +1642,7 @@ id=%q
|
|||||||
image=%q
|
image=%q
|
||||||
imageid=%q
|
imageid=%q
|
||||||
rootless=%d
|
rootless=%d
|
||||||
`, version.Version.String(), c.Name(), c.ID(), imageName, imageID, isRootless)
|
%s`, version.Version.String(), c.Name(), c.ID(), imageName, imageID, isRootless, containerenv)
|
||||||
}
|
}
|
||||||
containerenvPath, err := c.writeStringToRundir(".containerenv", containerenv)
|
containerenvPath, err := c.writeStringToRundir(".containerenv", containerenv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
@ -26,6 +27,7 @@ import (
|
|||||||
"github.com/containers/storage"
|
"github.com/containers/storage"
|
||||||
"github.com/cri-o/ocicni/pkg/ocicni"
|
"github.com/cri-o/ocicni/pkg/ocicni"
|
||||||
"github.com/docker/docker/pkg/namesgenerator"
|
"github.com/docker/docker/pkg/namesgenerator"
|
||||||
|
spec "github.com/opencontainers/runtime-spec/specs-go"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
)
|
)
|
||||||
@ -622,10 +624,13 @@ func (r *Runtime) Shutdown(force bool) error {
|
|||||||
func (r *Runtime) refresh(alivePath string) error {
|
func (r *Runtime) refresh(alivePath string) error {
|
||||||
logrus.Debugf("Podman detected system restart - performing state refresh")
|
logrus.Debugf("Podman detected system restart - performing state refresh")
|
||||||
|
|
||||||
|
// Clear state of database if not running in container
|
||||||
|
if !graphRootMounted() {
|
||||||
// First clear the state in the database
|
// First clear the state in the database
|
||||||
if err := r.state.Refresh(); err != nil {
|
if err := r.state.Refresh(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Next refresh the state of all containers to recreate dirs and
|
// Next refresh the state of all containers to recreate dirs and
|
||||||
// namespaces, and all the pods to recreate cgroups.
|
// namespaces, and all the pods to recreate cgroups.
|
||||||
@ -904,3 +909,29 @@ func (r *Runtime) getVolumePlugin(name string) (*plugin.VolumePlugin, error) {
|
|||||||
func (r *Runtime) GetSecretsStorageDir() string {
|
func (r *Runtime) GetSecretsStorageDir() string {
|
||||||
return filepath.Join(r.store.GraphRoot(), "secrets")
|
return filepath.Join(r.store.GraphRoot(), "secrets")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func graphRootMounted() bool {
|
||||||
|
f, err := os.OpenFile("/run/.containerenv", os.O_RDONLY, os.ModePerm)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
|
||||||
|
scanner := bufio.NewScanner(f)
|
||||||
|
for scanner.Scan() {
|
||||||
|
if scanner.Text() == "graphRootMounted=1" {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *Runtime) graphRootMountedFlag(mounts []spec.Mount) string {
|
||||||
|
root := r.store.GraphRoot()
|
||||||
|
for _, val := range mounts {
|
||||||
|
if strings.HasPrefix(root, val.Source) {
|
||||||
|
return "graphRootMounted=1"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|||||||
@ -47,6 +47,29 @@ var _ = Describe("Podman run", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman run check /run/.containerenv", func() {
|
||||||
|
session := podmanTest.Podman([]string{"run", ALPINE, "cat", "/run/.containerenv"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(session.OutputToString()).To(Equal(""))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"run", "--privileged", "--name=test1", ALPINE, "cat", "/run/.containerenv"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring("name=\"test1\""))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring("image=\"" + ALPINE + "\""))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"run", "-v", "/:/host", ALPINE, "cat", "/run/.containerenv"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring("graphRootMounted=1"))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"run", "-v", "/:/host", "--privileged", ALPINE, "cat", "/run/.containerenv"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(session.OutputToString()).To(ContainSubstring("graphRootMounted=1"))
|
||||||
|
})
|
||||||
|
|
||||||
It("podman run a container based on a complex local image name", func() {
|
It("podman run a container based on a complex local image name", func() {
|
||||||
imageName := strings.TrimPrefix(nginx, "quay.io/")
|
imageName := strings.TrimPrefix(nginx, "quay.io/")
|
||||||
session := podmanTest.Podman([]string{"run", imageName, "ls"})
|
session := podmanTest.Podman([]string{"run", imageName, "ls"})
|
||||||
|
|||||||
Reference in New Issue
Block a user