Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pod create: read infra image from containers.conf #12250

Merged
merged 1 commit into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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