mirror of
https://github.com/containers/podman.git
synced 2025-12-15 11:42:28 +08:00
container: workdir resolution must consider symlink if explicitly configured
While resolving `workdir` we mostly create a `workdir` when `stat` fails with `ENOENT` or `ErrNotExist` however following cases are not true when user explicitly specifies a `workdir` while `running` using `--workdir` which tells `podman` to only use workdir if its exists on the container. Following configuration is implicity set with other `run` mechanism like `podman play kube` Problem with explicit `--workdir` or similar implicit config in `podman play kube` is that currently podman ignores the fact that workdir can also be a `symlink` and actual `link` could be valid. Hence following commit ensures that in such scenarios when a `workdir` is not found and we cannot create a `workdir` podman must perform a check to ensure that if `workdir` is a `symlink` and `link` is resolved successfully and resolved link is present on the container then we return as it is. Docker performs a similar behviour. Signed-off-by: Aditya R <arajan@redhat.com>
This commit is contained in:
5
test/e2e/build/workdir-symlink/Dockerfile
Normal file
5
test/e2e/build/workdir-symlink/Dockerfile
Normal file
@@ -0,0 +1,5 @@
|
||||
FROM alpine
|
||||
RUN mkdir /tmp/destination
|
||||
RUN ln -s /tmp/destination /tmp/link
|
||||
WORKDIR /tmp/link
|
||||
CMD ["echo", "hello"]
|
||||
@@ -259,6 +259,19 @@ var _ = Describe("Podman build", func() {
|
||||
Expect(session.OutputToString()).NotTo(ContainSubstring("io.podman.annotations.seccomp"))
|
||||
})
|
||||
|
||||
It("podman build where workdir is a symlink and run without creating new workdir", func() {
|
||||
session := podmanTest.Podman([]string{
|
||||
"build", "-f", "build/workdir-symlink/Dockerfile", "-t", "test-symlink",
|
||||
})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
session = podmanTest.Podman([]string{"run", "--workdir", "/tmp/link", "test-symlink"})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
Expect(session.OutputToString()).To(ContainSubstring("hello"))
|
||||
})
|
||||
|
||||
It("podman build --http_proxy flag", func() {
|
||||
os.Setenv("http_proxy", "1.2.3.4")
|
||||
if IsRemote() {
|
||||
|
||||
@@ -38,6 +38,21 @@ spec:
|
||||
hostname: unknown
|
||||
`
|
||||
|
||||
var workdirSymlinkPodYaml = `
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
metadata:
|
||||
labels:
|
||||
app: test-symlink
|
||||
name: test-symlink
|
||||
spec:
|
||||
containers:
|
||||
- image: test-symlink
|
||||
name: test-symlink
|
||||
resources: {}
|
||||
restartPolicy: Never
|
||||
`
|
||||
|
||||
var podnameEqualsContainerNameYaml = `
|
||||
apiVersion: v1
|
||||
kind: Pod
|
||||
@@ -1332,6 +1347,26 @@ var _ = Describe("Podman play kube", func() {
|
||||
Expect(sharednamespaces).To(ContainSubstring("pid"))
|
||||
})
|
||||
|
||||
It("podman play kube should be able to run image where workdir is a symlink", func() {
|
||||
session := podmanTest.Podman([]string{
|
||||
"build", "-f", "build/workdir-symlink/Dockerfile", "-t", "test-symlink",
|
||||
})
|
||||
session.WaitWithDefaultTimeout()
|
||||
Expect(session).Should(Exit(0))
|
||||
|
||||
err := writeYaml(workdirSymlinkPodYaml, kubeYaml)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
kube := podmanTest.Podman([]string{"play", "kube", kubeYaml})
|
||||
kube.WaitWithDefaultTimeout()
|
||||
Expect(kube).Should(Exit(0))
|
||||
|
||||
logs := podmanTest.Podman([]string{"pod", "logs", "-c", "test-symlink-test-symlink", "test-symlink"})
|
||||
logs.WaitWithDefaultTimeout()
|
||||
Expect(logs).Should(Exit(0))
|
||||
Expect(logs.OutputToString()).To(ContainSubstring("hello"))
|
||||
})
|
||||
|
||||
It("podman play kube should not rename pod if container in pod has same name", func() {
|
||||
err := writeYaml(podnameEqualsContainerNameYaml, kubeYaml)
|
||||
Expect(err).To(BeNil())
|
||||
|
||||
Reference in New Issue
Block a user