mirror of
https://github.com/containers/podman
synced 2024-10-20 01:03:51 +00:00
Use the InfraImage defined in containers.conf
Remove hard code use of the DefaultInfraImage and rely on getting this from containers.conf. Fixes: https://github.com/containers/podman/issues/12771 Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
parent
87cd4b698c
commit
19a4759066
|
@ -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 {
|
||||
|
|
|
@ -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"
|
||||
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
@ -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)
|
||||
|
|
|
@ -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))
|
||||
})
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
@ -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" {
|
||||
|
|
Loading…
Reference in a new issue