mirror of
https://github.com/containers/podman.git
synced 2025-06-25 12:20:42 +08:00
Merge pull request #9220 from vrothberg/fix-9211
generate kube: handle entrypoint
This commit is contained in:
@ -353,22 +353,21 @@ func containerToV1Container(c *Container) (v1.Container, []v1.Volume, *v1.PodDNS
|
|||||||
return kubeContainer, kubeVolumes, nil, err
|
return kubeContainer, kubeVolumes, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
containerCommands := c.Command()
|
// Handle command and arguments.
|
||||||
kubeContainer.Name = removeUnderscores(c.Name())
|
if ep := c.Entrypoint(); len(ep) > 0 {
|
||||||
|
// If we have an entrypoint, set the container's command as
|
||||||
|
// arguments.
|
||||||
|
kubeContainer.Command = ep
|
||||||
|
kubeContainer.Args = c.Command()
|
||||||
|
} else {
|
||||||
|
kubeContainer.Command = c.Command()
|
||||||
|
}
|
||||||
|
|
||||||
|
kubeContainer.Name = removeUnderscores(c.Name())
|
||||||
_, image := c.Image()
|
_, image := c.Image()
|
||||||
kubeContainer.Image = image
|
kubeContainer.Image = image
|
||||||
kubeContainer.Stdin = c.Stdin()
|
kubeContainer.Stdin = c.Stdin()
|
||||||
|
|
||||||
// prepend the entrypoint of the container to command
|
|
||||||
if ep := c.Entrypoint(); len(c.Entrypoint()) > 0 {
|
|
||||||
ep = append(ep, containerCommands...)
|
|
||||||
containerCommands = ep
|
|
||||||
}
|
|
||||||
kubeContainer.Command = containerCommands
|
|
||||||
// TODO need to figure out how we handle command vs entry point. Kube appears to prefer entrypoint.
|
|
||||||
// right now we just take the container's command
|
|
||||||
//container.Args = args
|
|
||||||
kubeContainer.WorkingDir = c.WorkingDir()
|
kubeContainer.WorkingDir = c.WorkingDir()
|
||||||
kubeContainer.Ports = ports
|
kubeContainer.Ports = ports
|
||||||
// This should not be applicable
|
// This should not be applicable
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package integration
|
package integration
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strconv"
|
"strconv"
|
||||||
@ -639,4 +640,63 @@ var _ = Describe("Podman generate kube", func() {
|
|||||||
Expect(pod.Spec.DNSConfig.Options[0].Name).To(Equal("color"))
|
Expect(pod.Spec.DNSConfig.Options[0].Name).To(Equal("color"))
|
||||||
Expect(*pod.Spec.DNSConfig.Options[0].Value).To(Equal("blue"))
|
Expect(*pod.Spec.DNSConfig.Options[0].Value).To(Equal("blue"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman generate kube - set entrypoint as command", func() {
|
||||||
|
session := podmanTest.Podman([]string{"create", "--pod", "new:testpod", "--entrypoint", "/bin/sleep", ALPINE, "10s"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
kube := podmanTest.Podman([]string{"generate", "kube", "testpod"})
|
||||||
|
kube.WaitWithDefaultTimeout()
|
||||||
|
Expect(kube.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
// Now make sure that the container's command is set to the
|
||||||
|
// entrypoint and it's arguments to "10s".
|
||||||
|
pod := new(v1.Pod)
|
||||||
|
err := yaml.Unmarshal(kube.Out.Contents(), pod)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
containers := pod.Spec.Containers
|
||||||
|
Expect(len(containers)).To(Equal(1))
|
||||||
|
|
||||||
|
Expect(containers[0].Command).To(Equal([]string{"/bin/sleep"}))
|
||||||
|
Expect(containers[0].Args).To(Equal([]string{"10s"}))
|
||||||
|
})
|
||||||
|
|
||||||
|
It("podman generate kube - use entrypoint from image", func() {
|
||||||
|
// Build an image with an entrypoint.
|
||||||
|
containerfile := `FROM quay.io/libpod/alpine:latest
|
||||||
|
ENTRYPOINT /bin/sleep`
|
||||||
|
|
||||||
|
targetPath, err := CreateTempDirInTempDir()
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
containerfilePath := filepath.Join(targetPath, "Containerfile")
|
||||||
|
err = ioutil.WriteFile(containerfilePath, []byte(containerfile), 0644)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
image := "generatekube:test"
|
||||||
|
session := podmanTest.Podman([]string{"build", "-f", containerfilePath, "-t", image})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
session = podmanTest.Podman([]string{"create", "--pod", "new:testpod", image, "10s"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
kube := podmanTest.Podman([]string{"generate", "kube", "testpod"})
|
||||||
|
kube.WaitWithDefaultTimeout()
|
||||||
|
Expect(kube.ExitCode()).To(Equal(0))
|
||||||
|
|
||||||
|
// Now make sure that the container's command is set to the
|
||||||
|
// entrypoint and it's arguments to "10s".
|
||||||
|
pod := new(v1.Pod)
|
||||||
|
err = yaml.Unmarshal(kube.Out.Contents(), pod)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
containers := pod.Spec.Containers
|
||||||
|
Expect(len(containers)).To(Equal(1))
|
||||||
|
|
||||||
|
Expect(containers[0].Command).To(Equal([]string{"/bin/sh", "-c", "/bin/sleep"}))
|
||||||
|
Expect(containers[0].Args).To(Equal([]string{"10s"}))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user