Skip to content

Commit

Permalink
pod create: read infra image from containers.conf
Browse files Browse the repository at this point in the history
Fix a bug where pods would be created with the hard-coded default infra
image instead of the custom one from containers.conf.  Add a simple
regression test.

Fixes: #12245
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Nov 10, 2021
1 parent 5437568 commit df06664
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 11 deletions.
14 changes: 3 additions & 11 deletions cmd/podman/pods/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"strings"

"github.com/containers/common/pkg/completion"
"github.com/containers/common/pkg/config"
"github.com/containers/common/pkg/sysinfo"
"github.com/containers/podman/v3/cmd/podman/common"
"github.com/containers/podman/v3/cmd/podman/containers"
Expand Down Expand Up @@ -48,6 +47,7 @@ var (
var (
createOptions entities.PodCreateOptions
infraOptions entities.ContainerCreateOptions
infraImage string
labels, labelFile []string
podIDFile string
replace bool
Expand All @@ -72,7 +72,7 @@ func init() {
_ = createCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone)

infraImageFlagName := "infra-image"
flags.String(infraImageFlagName, containerConfig.Engine.InfraImage, "The image of the infra container to associate with the pod")
flags.StringVar(&infraImage, infraImageFlagName, containerConfig.Engine.InfraImage, "The image of the infra container to associate with the pod")
_ = createCommand.RegisterFlagCompletionFunc(infraImageFlagName, common.AutocompleteImages)

podIDFileFlagName := "pod-id-file"
Expand Down Expand Up @@ -110,7 +110,7 @@ func create(cmd *cobra.Command, args []string) error {
return errors.Wrapf(err, "unable to process labels")
}

imageName = config.DefaultInfraImage
imageName = infraImage
img := imageName
if !createOptions.Infra {
if cmd.Flag("no-hosts").Changed {
Expand Down Expand Up @@ -151,14 +151,6 @@ func create(cmd *cobra.Command, args []string) error {
return err
}
}
if cmd.Flag("infra-image").Changed {
// Only send content to server side if user changed defaults
img, err = cmd.Flags().GetString("infra-image")
imageName = img
if err != nil {
return err
}
}
podName = createOptions.Name
err = common.ContainerToPodOptions(&infraOptions, &createOptions)
if err != nil {
Expand Down
19 changes: 19 additions & 0 deletions test/system/200-pod.bats
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,25 @@ function teardown() {
run_podman pod rm -f -t 0 $podid
}


@test "podman pod create - custom infra image" {
image="i.do/not/exist:image"

tmpdir=$PODMAN_TMPDIR/pod-test
run mkdir -p $tmpdir
containersconf=$tmpdir/containers.conf
cat >$containersconf <<EOF
[engine]
infra_image="$image"
EOF

run_podman 125 pod create --infra-image $image
is "$output" ".*initializing source docker://$image:.*"

CONTAINERS_CONF=$containersconf run_podman 125 pod create
is "$output" ".*initializing source docker://$image:.*"
}

function rm_podman_pause_image() {
run_podman version --format "{{.Server.Version}}-{{.Server.Built}}"
run_podman rmi -f "localhost/podman-pause:$output"
Expand Down

0 comments on commit df06664

Please sign in to comment.