mirror of
https://github.com/containers/podman.git
synced 2025-06-24 19:42:56 +08:00
Merge pull request #8426 from mheon/fix_infra_cmd_from_config
Do not ignore infra command from config files
This commit is contained in:
@ -34,40 +34,56 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, rawIm
|
|||||||
// Set Pod hostname
|
// Set Pod hostname
|
||||||
g.Config.Hostname = p.config.Hostname
|
g.Config.Hostname = p.config.Hostname
|
||||||
|
|
||||||
|
var options []CtrCreateOption
|
||||||
|
|
||||||
|
// Command: If user-specified, use that preferentially.
|
||||||
|
// If not set and the config file is set, fall back to that.
|
||||||
|
var infraCtrCommand []string
|
||||||
|
if p.config.InfraContainer.InfraCommand != nil {
|
||||||
|
logrus.Debugf("User-specified infra container entrypoint %v", p.config.InfraContainer.InfraCommand)
|
||||||
|
infraCtrCommand = p.config.InfraContainer.InfraCommand
|
||||||
|
} else if r.config.Engine.InfraCommand != "" {
|
||||||
|
logrus.Debugf("Config-specified infra container entrypoint %s", r.config.Engine.InfraCommand)
|
||||||
|
infraCtrCommand = []string{r.config.Engine.InfraCommand}
|
||||||
|
}
|
||||||
|
// Only if set by the user or containers.conf, we set entrypoint for the
|
||||||
|
// infra container.
|
||||||
|
// This is only used by commit, so it shouldn't matter... But someone
|
||||||
|
// may eventually want to commit an infra container?
|
||||||
|
// TODO: Should we actually do this if set by containers.conf?
|
||||||
|
if infraCtrCommand != nil {
|
||||||
|
// Need to duplicate the array - we are going to add Cmd later
|
||||||
|
// so the current array will be changed.
|
||||||
|
newArr := make([]string, 0, len(infraCtrCommand))
|
||||||
|
newArr = append(newArr, infraCtrCommand...)
|
||||||
|
options = append(options, WithEntrypoint(newArr))
|
||||||
|
}
|
||||||
|
|
||||||
isRootless := rootless.IsRootless()
|
isRootless := rootless.IsRootless()
|
||||||
|
|
||||||
entrypointSet := len(p.config.InfraContainer.InfraCommand) > 0
|
|
||||||
entryPoint := p.config.InfraContainer.InfraCommand
|
|
||||||
entryCmd := []string{}
|
|
||||||
var options []CtrCreateOption
|
|
||||||
// I've seen circumstances where config is being passed as nil.
|
// I've seen circumstances where config is being passed as nil.
|
||||||
// Let's err on the side of safety and make sure it's safe to use.
|
// Let's err on the side of safety and make sure it's safe to use.
|
||||||
if config != nil {
|
if config != nil {
|
||||||
// default to entrypoint in image if there is one
|
if infraCtrCommand == nil {
|
||||||
if !entrypointSet {
|
// If we have no entrypoint and command from the image,
|
||||||
if len(config.Entrypoint) > 0 {
|
// we can't go on - the infra container has no command.
|
||||||
entrypointSet = true
|
if len(config.Entrypoint) == 0 && len(config.Cmd) == 0 {
|
||||||
entryPoint = config.Entrypoint
|
return nil, errors.Errorf("infra container has no command")
|
||||||
entryCmd = config.Entrypoint
|
|
||||||
}
|
}
|
||||||
} else { // so use the InfraCommand
|
if len(config.Entrypoint) > 0 {
|
||||||
entrypointSet = true
|
infraCtrCommand = config.Entrypoint
|
||||||
entryCmd = entryPoint
|
} else {
|
||||||
}
|
|
||||||
|
|
||||||
if len(config.Cmd) > 0 {
|
|
||||||
// We can't use the default pause command, since we're
|
|
||||||
// sourcing from the image. If we didn't already set an
|
|
||||||
// entrypoint, set one now.
|
|
||||||
if !entrypointSet {
|
|
||||||
// Use the Docker default "/bin/sh -c"
|
// Use the Docker default "/bin/sh -c"
|
||||||
// entrypoint, as we're overriding command.
|
// entrypoint, as we're overriding command.
|
||||||
// If an image doesn't want this, it can
|
// If an image doesn't want this, it can
|
||||||
// override entrypoint too.
|
// override entrypoint too.
|
||||||
entryCmd = []string{"/bin/sh", "-c"}
|
infraCtrCommand = []string{"/bin/sh", "-c"}
|
||||||
}
|
}
|
||||||
entryCmd = append(entryCmd, config.Cmd...)
|
|
||||||
}
|
}
|
||||||
|
if len(config.Cmd) > 0 {
|
||||||
|
infraCtrCommand = append(infraCtrCommand, config.Cmd...)
|
||||||
|
}
|
||||||
|
|
||||||
if len(config.Env) > 0 {
|
if len(config.Env) > 0 {
|
||||||
for _, nameValPair := range config.Env {
|
for _, nameValPair := range config.Env {
|
||||||
nameValSlice := strings.Split(nameValPair, "=")
|
nameValSlice := strings.Split(nameValPair, "=")
|
||||||
@ -127,9 +143,9 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, rawIm
|
|||||||
}
|
}
|
||||||
|
|
||||||
g.SetRootReadonly(true)
|
g.SetRootReadonly(true)
|
||||||
g.SetProcessArgs(entryCmd)
|
g.SetProcessArgs(infraCtrCommand)
|
||||||
|
|
||||||
logrus.Debugf("Using %q as infra container entrypoint", entryCmd)
|
logrus.Debugf("Using %q as infra container command", infraCtrCommand)
|
||||||
|
|
||||||
g.RemoveMount("/dev/shm")
|
g.RemoveMount("/dev/shm")
|
||||||
if isRootless {
|
if isRootless {
|
||||||
@ -148,9 +164,6 @@ func (r *Runtime) makeInfraContainer(ctx context.Context, p *Pod, imgName, rawIm
|
|||||||
options = append(options, WithRootFSFromImage(imgID, imgName, rawImageName))
|
options = append(options, WithRootFSFromImage(imgID, imgName, rawImageName))
|
||||||
options = append(options, WithName(containerName))
|
options = append(options, WithName(containerName))
|
||||||
options = append(options, withIsInfra())
|
options = append(options, withIsInfra())
|
||||||
if entrypointSet {
|
|
||||||
options = append(options, WithEntrypoint(entryPoint))
|
|
||||||
}
|
|
||||||
if len(p.config.InfraContainer.ConmonPidFile) > 0 {
|
if len(p.config.InfraContainer.ConmonPidFile) > 0 {
|
||||||
options = append(options, WithConmonPidFile(p.config.InfraContainer.ConmonPidFile))
|
options = append(options, WithConmonPidFile(p.config.InfraContainer.ConmonPidFile))
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user