Merge pull request #12780 from rhatdan/pod

Use the InfraImage defined in containers.conf
This commit is contained in:
OpenShift Merge Robot 2022-01-11 00:25:09 +01:00 committed by GitHub
commit ed9ef59e7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 48 additions and 18 deletions

View File

@ -388,10 +388,7 @@ func createPodIfNecessary(cmd *cobra.Command, s *specgen.SpecGenerator, netOpts
if err != nil { if err != nil {
return nil, err return nil, err
} }
imageName := config.DefaultInfraImage podGen.InfraContainerSpec = specgen.NewSpecGenerator("", false)
podGen.InfraImage = imageName
podGen.InfraContainerSpec = specgen.NewSpecGenerator(imageName, false)
podGen.InfraContainerSpec.RawImageName = imageName
podGen.InfraContainerSpec.NetworkOptions = podGen.NetworkOptions podGen.InfraContainerSpec.NetworkOptions = podGen.NetworkOptions
err = specgenutil.FillOutSpecGen(podGen.InfraContainerSpec, &infraOpts, []string{}) err = specgenutil.FillOutSpecGen(podGen.InfraContainerSpec, &infraOpts, []string{})
if err != nil { if err != nil {

View File

@ -71,7 +71,11 @@ func init() {
_ = createCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone) _ = createCommand.RegisterFlagCompletionFunc(nameFlagName, completion.AutocompleteNone)
infraImageFlagName := "infra-image" 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) _ = createCommand.RegisterFlagCompletionFunc(infraImageFlagName, common.AutocompleteImages)
podIDFileFlagName := "pod-id-file" podIDFileFlagName := "pod-id-file"
@ -109,7 +113,9 @@ func create(cmd *cobra.Command, args []string) error {
return errors.Wrapf(err, "unable to process labels") return errors.Wrapf(err, "unable to process labels")
} }
if cmd.Flag("infra-image").Changed {
imageName = infraImage imageName = infraImage
}
img := imageName img := imageName
if !createOptions.Infra { if !createOptions.Infra {
if cmd.Flag("no-hosts").Changed { if cmd.Flag("no-hosts").Changed {

View File

@ -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 // pause one and make sure it's in the storage by pulling it down if
// missing. // missing.
if image == "" && c.IsInfra() { 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 { if _, err := c.runtime.libimageRuntime.Pull(ctx, image, config.PullPolicyMissing, nil); err != nil {
return kubeContainer, nil, nil, nil, err return kubeContainer, nil, nil, nil, err
} }

View File

@ -7,7 +7,6 @@ import (
"strings" "strings"
"time" "time"
"github.com/containers/common/pkg/config"
"github.com/containers/podman/v3/libpod" "github.com/containers/podman/v3/libpod"
"github.com/containers/podman/v3/libpod/define" "github.com/containers/podman/v3/libpod/define"
"github.com/containers/podman/v3/pkg/api/handlers" "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.Name = psg.InfraName
psg.InfraContainerSpec.ConmonPidFile = psg.InfraConmonPidFile psg.InfraContainerSpec.ConmonPidFile = psg.InfraConmonPidFile
psg.InfraContainerSpec.ContainerCreateCommand = psg.InfraCommand psg.InfraContainerSpec.ContainerCreateCommand = psg.InfraCommand
imageName := psg.InfraImage psg.InfraContainerSpec.Image = psg.InfraImage
rawImageName := psg.InfraImage psg.InfraContainerSpec.RawImageName = psg.InfraImage
if imageName == "" {
imageName = config.DefaultInfraImage
rawImageName = config.DefaultInfraImage
}
psg.InfraImage = imageName
psg.InfraContainerSpec.Image = imageName
psg.InfraContainerSpec.RawImageName = rawImageName
} }
podSpecComplete := entities.PodSpec{PodSpecGen: psg} podSpecComplete := entities.PodSpec{PodSpecGen: psg}
pod, err := generate.MakePod(&podSpecComplete, runtime) pod, err := generate.MakePod(&podSpecComplete, runtime)

View File

@ -452,4 +452,36 @@ var _ = Describe("Podman run", func() {
Expect(result).Should(Exit(0)) Expect(result).Should(Exit(0))
Expect(result.OutputToString()).To(ContainSubstring("(default 1234)")) 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))
})
}) })

View File

@ -62,8 +62,8 @@ function teardown() {
@test "podman pod create - custom infra image" { @test "podman pod create - custom infra image" {
skip_if_remote "CONTAINERS_CONF only effects server side"
image="i.do/not/exist:image" image="i.do/not/exist:image"
tmpdir=$PODMAN_TMPDIR/pod-test tmpdir=$PODMAN_TMPDIR/pod-test
run mkdir -p $tmpdir run mkdir -p $tmpdir
containersconf=$tmpdir/containers.conf containersconf=$tmpdir/containers.conf
@ -77,6 +77,9 @@ EOF
CONTAINERS_CONF=$containersconf run_podman 125 pod create CONTAINERS_CONF=$containersconf run_podman 125 pod create
is "$output" ".*initializing source docker://$image:.*" 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" { @test "podman pod - communicating between pods" {