diff options
Diffstat (limited to 'libpod/container_internal.go')
-rw-r--r-- | libpod/container_internal.go | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 414def120..62960fa0f 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1,6 +1,7 @@ package libpod import ( + "context" "encoding/json" "fmt" "io" @@ -176,7 +177,7 @@ func newContainer(rspec *spec.Spec, lockDir string) (*Container, error) { } // Create container root filesystem for use -func (c *Container) setupStorage() error { +func (c *Container) setupStorage(ctx context.Context) error { if !c.valid { return errors.Wrapf(ErrCtrRemoved, "container %s is not valid", c.ID()) } @@ -190,7 +191,7 @@ func (c *Container) setupStorage() error { return errors.Wrapf(ErrInvalidArg, "must provide image ID and image name to use an image") } - containerInfo, err := c.runtime.storageService.CreateContainerStorage(c.runtime.imageContext, c.config.RootfsImageName, c.config.RootfsImageID, c.config.Name, c.config.ID, c.config.MountLabel) + containerInfo, err := c.runtime.storageService.CreateContainerStorage(ctx, c.runtime.imageContext, c.config.RootfsImageName, c.config.RootfsImageID, c.config.Name, c.config.ID, c.config.MountLabel) if err != nil { return errors.Wrapf(err, "error creating container storage") } @@ -412,13 +413,13 @@ func (c *Container) checkDependenciesRunningLocked(depCtrs map[string]*Container } // Initialize a container, creating it in the runtime -func (c *Container) init() error { +func (c *Container) init(ctx context.Context) error { if err := c.makeBindMounts(); err != nil { return err } // Generate the OCI spec - spec, err := c.generateSpec() + spec, err := c.generateSpec(ctx) if err != nil { return err } @@ -443,7 +444,7 @@ func (c *Container) init() error { // Reinitialize a container // Deletes and recreates a container in the runtime // Should only be done on ContainerStateStopped containers -func (c *Container) reinit() error { +func (c *Container) reinit(ctx context.Context) error { logrus.Debugf("Recreating container %s in OCI runtime", c.ID()) // If necessary, delete attach and ctl files @@ -468,13 +469,13 @@ func (c *Container) reinit() error { logrus.Debugf("Successfully cleaned up container %s", c.ID()) // Initialize the container again - return c.init() + return c.init(ctx) } // Initialize (if necessary) and start a container // Performs all necessary steps to start a container that is not running // Does not lock or check validity -func (c *Container) initAndStart() (err error) { +func (c *Container) initAndStart(ctx context.Context) (err error) { // If we are ContainerStateUnknown, throw an error if c.state.State == ContainerStateUnknown { return errors.Wrapf(ErrCtrStateInvalid, "container %s is in an unknown state", c.ID()) @@ -527,7 +528,7 @@ func (c *Container) initAndStart() (err error) { // If we are ContainerStateConfigured we need to init() if c.state.State == ContainerStateConfigured { - if err := c.init(); err != nil { + if err := c.init(ctx); err != nil { return err } } @@ -753,8 +754,7 @@ func (c *Container) makeBindMounts() error { } // Add Secret Mounts - secretMounts := c.getSecretMounts(secrets.OverrideMountsFile) - secretMounts = append(secretMounts, c.getSecretMounts(secrets.DefaultMountsFile)...) + secretMounts := secrets.SecretMounts(c.config.MountLabel, c.state.RunDir) for _, mount := range secretMounts { if _, ok := c.state.BindMounts[mount.Destination]; !ok { c.state.BindMounts[mount.Destination] = mount.Source @@ -764,15 +764,6 @@ func (c *Container) makeBindMounts() error { return nil } -// addSecrets mounts the secrets from the override and/or default mounts file -func (c *Container) getSecretMounts(mountFile string) (secretMounts []spec.Mount) { - secretMounts, err := secrets.SecretMounts(mountFile, c.config.MountLabel, c.state.RunDir) - if err != nil { - logrus.Warn("error mounting secrets, skipping...") - } - return secretMounts -} - // writeStringToRundir copies the provided file to the runtimedir func (c *Container) writeStringToRundir(destFile, output string) (string, error) { destFileName := filepath.Join(c.state.RunDir, destFile) @@ -910,7 +901,7 @@ func (c *Container) generateHosts() (string, error) { // Generate spec for a container // Accepts a map of the container's dependencies -func (c *Container) generateSpec() (*spec.Spec, error) { +func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) { g := generate.NewFromSpec(c.config.Spec) // If network namespace was requested, add it now @@ -931,6 +922,8 @@ func (c *Container) generateSpec() (*spec.Spec, error) { } if !MountExists(g.Mounts(), dstPath) { g.AddMount(newMount) + } else { + logrus.Warnf("User mount overriding libpod mount at %q", dstPath) } } @@ -939,7 +932,7 @@ func (c *Container) generateSpec() (*spec.Spec, error) { } // Bind builtin image volumes if c.config.ImageVolumes { - if err := c.addImageVolumes(&g); err != nil { + if err := c.addImageVolumes(ctx, &g); err != nil { return nil, errors.Wrapf(err, "error mounting image volumes") } } @@ -1059,7 +1052,7 @@ func (c *Container) addNamespaceContainer(g *generate.Generator, ns LinuxNS, ctr return nil } -func (c *Container) addImageVolumes(g *generate.Generator) error { +func (c *Container) addImageVolumes(ctx context.Context, g *generate.Generator) error { mountPoint := c.state.Mountpoint if !c.state.Mounted { return errors.Wrapf(ErrInternal, "container is not mounted") @@ -1068,7 +1061,7 @@ func (c *Container) addImageVolumes(g *generate.Generator) error { if err != nil { return err } - imageData, err := newImage.Inspect() + imageData, err := newImage.Inspect(ctx) if err != nil { return err } |