Skip to content

Commit

Permalink
Use the InfraImage defined in containers.conf
Browse files Browse the repository at this point in the history
Remove hard code use of the DefaultInfraImage and rely on
getting this from containers.conf.

Fixes: containers#12771

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
  • Loading branch information
rhatdan committed Jan 10, 2022
1 parent 87cd4b6 commit 19a4759
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 18 deletions.
5 changes: 1 addition & 4 deletions cmd/podman/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,10 +388,7 @@ func createPodIfNecessary(cmd *cobra.Command, s *specgen.SpecGenerator, netOpts
if err != nil {
return nil, err
}
imageName := config.DefaultInfraImage
podGen.InfraImage = imageName
podGen.InfraContainerSpec = specgen.NewSpecGenerator(imageName, false)
podGen.InfraContainerSpec.RawImageName = imageName
podGen.InfraContainerSpec = specgen.NewSpecGenerator("", false)
podGen.InfraContainerSpec.NetworkOptions = podGen.NetworkOptions
err = specgenutil.FillOutSpecGen(podGen.InfraContainerSpec, &infraOpts, []string{})
if err != nil {
Expand Down
10 changes: 8 additions & 2 deletions cmd/podman/pods/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,11 @@ func init() {
_ = createCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone)

infraImageFlagName := "infra-image"
flags.StringVar(&infraImage, infraImageFlagName, containerConfig.Engine.InfraImage, "The image of the infra container to associate with the pod")
var defInfraImage string
if !registry.IsRemote() {
defInfraImage = containerConfig.Engine.InfraImage
}
flags.StringVar(&infraImage, infraImageFlagName, defInfraImage, "The image of the infra container to associate with the pod")
_ = createCommand.RegisterFlagCompletionFunc(infraImageFlagName, common.AutocompleteImages)

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

imageName = infraImage
if cmd.Flag("infra-image").Changed {
imageName = infraImage
}
img := imageName
if !createOptions.Infra {
if cmd.Flag("no-hosts").Changed {
Expand Down
2 changes: 1 addition & 1 deletion libpod/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ func containerToV1Container(ctx context.Context, c *Container) (v1.Container, []
// pause one and make sure it's in the storage by pulling it down if
// missing.
if image == "" && c.IsInfra() {
image = config.DefaultInfraImage
image = c.runtime.config.Engine.InfraImage
if _, err := c.runtime.libimageRuntime.Pull(ctx, image, config.PullPolicyMissing, nil); err != nil {
return kubeContainer, nil, nil, nil, err
}
Expand Down
12 changes: 2 additions & 10 deletions pkg/api/handlers/libpod/pods.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"
"time"

"github.com/containers/common/pkg/config"
"github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/api/handlers"
Expand Down Expand Up @@ -62,15 +61,8 @@ func PodCreate(w http.ResponseWriter, r *http.Request) {
psg.InfraContainerSpec.Name = psg.InfraName
psg.InfraContainerSpec.ConmonPidFile = psg.InfraConmonPidFile
psg.InfraContainerSpec.ContainerCreateCommand = psg.InfraCommand
imageName := psg.InfraImage
rawImageName := psg.InfraImage
if imageName == "" {
imageName = config.DefaultInfraImage
rawImageName = config.DefaultInfraImage
}
psg.InfraImage = imageName
psg.InfraContainerSpec.Image = imageName
psg.InfraContainerSpec.RawImageName = rawImageName
psg.InfraContainerSpec.Image = psg.InfraImage
psg.InfraContainerSpec.RawImageName = psg.InfraImage
}
podSpecComplete := entities.PodSpec{PodSpecGen: psg}
pod, err := generate.MakePod(&podSpecComplete, runtime)
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/containers_conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,4 +452,36 @@ var _ = Describe("Podman run", func() {
Expect(result).Should(Exit(0))
Expect(result.OutputToString()).To(ContainSubstring("(default 1234)"))
})

It("podman bad infra_image name in containers.conf", func() {
infra1 := "i.do/not/exist:image"
infra2 := "i.still.do/not/exist:image"
errorString := "initializing source docker://" + infra1
error2String := "initializing source docker://" + infra2
configPath := filepath.Join(podmanTest.TempDir, "containers.conf")
os.Setenv("CONTAINERS_CONF", configPath)

containersConf := []byte("[engine]\ninfra_image=\"" + infra1 + "\"")
err = ioutil.WriteFile(configPath, containersConf, os.ModePerm)
Expect(err).To(BeNil())

if IsRemote() {
podmanTest.RestartRemoteService()
}

result := podmanTest.Podman([]string{"pod", "create", "--infra-image", infra2})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring(error2String))

result = podmanTest.Podman([]string{"pod", "create"})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring(errorString))

result = podmanTest.Podman([]string{"create", "--pod", "new:pod1", ALPINE})
result.WaitWithDefaultTimeout()
Expect(result).Should(Exit(125))
Expect(result.ErrorToString()).To(ContainSubstring(errorString))
})
})
5 changes: 4 additions & 1 deletion test/system/200-pod.bats
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ function teardown() {


@test "podman pod create - custom infra image" {
skip_if_remote "CONTAINERS_CONF only effects server side"
image="i.do/not/exist:image"

tmpdir=$PODMAN_TMPDIR/pod-test
run mkdir -p $tmpdir
containersconf=$tmpdir/containers.conf
Expand All @@ -77,6 +77,9 @@ EOF

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

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

@test "podman pod - communicating between pods" {
Expand Down

0 comments on commit 19a4759

Please sign in to comment.