Add conformance tests for terminationMessage(Path|Policy)

Test root, non-root, success and message, failure and message.
parent e6d35b03
...@@ -28,6 +28,7 @@ import ( ...@@ -28,6 +28,7 @@ import (
. "github.com/onsi/ginkgo" . "github.com/onsi/ginkgo"
. "github.com/onsi/gomega" . "github.com/onsi/gomega"
gomegatypes "github.com/onsi/gomega/types"
) )
const ( const (
...@@ -128,46 +129,112 @@ while true; do sleep 1; done ...@@ -128,46 +129,112 @@ while true; do sleep 1; done
} }
}) })
It("should report termination message if TerminationMessagePath is set [Conformance]", func() { rootUser := int64(0)
name := "termination-message-container" nonRootUser := int64(10000)
terminationMessage := "DONE" for _, testCase := range []struct {
terminationMessagePath := "/dev/termination-log" name string
priv := true container v1.Container
c := ConformanceContainer{ phase v1.PodPhase
PodClient: f.PodClient(), message gomegatypes.GomegaMatcher
Container: v1.Container{ }{
{
name: "if TerminationMessagePath is set [Conformance]",
container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24", Image: "gcr.io/google_containers/busybox:1.24",
Name: name,
Command: []string{"/bin/sh", "-c"}, Command: []string{"/bin/sh", "-c"},
Args: []string{fmt.Sprintf("/bin/echo -n %s > %s", terminationMessage, terminationMessagePath)}, Args: []string{"/bin/echo -n DONE > /dev/termination-log"},
TerminationMessagePath: terminationMessagePath, TerminationMessagePath: "/dev/termination-log",
SecurityContext: &v1.SecurityContext{ SecurityContext: &v1.SecurityContext{
Privileged: &priv, RunAsUser: &rootUser,
}, },
}, },
RestartPolicy: v1.RestartPolicyNever, phase: v1.PodSucceeded,
} message: Equal("DONE"),
},
{
name: "if TerminationMessagePath is set as non-root user and at a non-default path [Conformance]",
container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n DONE > /dev/termination-custom-log"},
TerminationMessagePath: "/dev/termination-custom-log",
SecurityContext: &v1.SecurityContext{
RunAsUser: &nonRootUser,
},
},
phase: v1.PodSucceeded,
message: Equal("DONE"),
},
{
name: "from log output if TerminationMessagePolicy FallbackToLogOnError is set [Conformance]",
container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n DONE; /bin/false"},
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
},
phase: v1.PodFailed,
message: Equal("DONE\n"),
},
By("create the container") {
c.Create() name: "as empty when pod succeeds and TerminationMessagePolicy FallbackToLogOnError is set",
defer c.Delete() container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo DONE; /bin/true"},
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
},
phase: v1.PodSucceeded,
message: Equal(""),
},
By("wait for the container to succeed") {
Eventually(c.GetPhase, retryTimeout, pollInterval).Should(Equal(v1.PodSucceeded)) name: "from file when pod succeeds and TerminationMessagePolicy FallbackToLogOnError is set [Conformance]",
container: v1.Container{
Image: "gcr.io/google_containers/busybox:1.24",
Command: []string{"/bin/sh", "-c"},
Args: []string{"/bin/echo -n OK > /dev/termination-log; /bin/echo DONE; /bin/true"},
TerminationMessagePath: "/dev/termination-log",
TerminationMessagePolicy: v1.TerminationMessageFallbackToLogsOnError,
},
phase: v1.PodSucceeded,
message: Equal("OK"),
},
} {
It(fmt.Sprintf("should report termination message %s", testCase.name), func() {
testCase.container.Name = "termination-message-container"
c := ConformanceContainer{
PodClient: f.PodClient(),
Container: testCase.container,
RestartPolicy: v1.RestartPolicyNever,
}
By("get the container status") By("create the container")
status, err := c.GetStatus() c.Create()
Expect(err).NotTo(HaveOccurred()) defer c.Delete()
By("the container should be terminated") By(fmt.Sprintf("wait for the container to reach %s", testCase.phase))
Expect(GetContainerState(status.State)).To(Equal(ContainerStateTerminated)) Eventually(c.GetPhase, retryTimeout, pollInterval).Should(Equal(testCase.phase))
By("the termination message should be set") By("get the container status")
Expect(status.State.Terminated.Message).Should(Equal(terminationMessage)) status, err := c.GetStatus()
Expect(err).NotTo(HaveOccurred())
By("delete the container") By("the container should be terminated")
Expect(c.Delete()).To(Succeed()) Expect(GetContainerState(status.State)).To(Equal(ContainerStateTerminated))
})
By("the termination message should be set")
Expect(status.State.Terminated.Message).Should(testCase.message)
By("delete the container")
Expect(c.Delete()).To(Succeed())
})
}
}) })
Context("when running a container with a new image", func() { Context("when running a container with a new image", func() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment