mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 21:17:23 +00:00
Add conformance tests for terminationMessage(Path|Policy)
Test root, non-root, success and message, failure and message.
This commit is contained in:
parent
e6d35b0362
commit
244734171e
@ -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,23 +129,88 @@ 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
|
||||||
|
phase v1.PodPhase
|
||||||
|
message gomegatypes.GomegaMatcher
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "if TerminationMessagePath 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 > /dev/termination-log"},
|
||||||
|
TerminationMessagePath: "/dev/termination-log",
|
||||||
|
SecurityContext: &v1.SecurityContext{
|
||||||
|
RunAsUser: &rootUser,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
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"),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
name: "as empty when pod succeeds and TerminationMessagePolicy FallbackToLogOnError is set",
|
||||||
|
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(""),
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
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{
|
c := ConformanceContainer{
|
||||||
PodClient: f.PodClient(),
|
PodClient: f.PodClient(),
|
||||||
Container: v1.Container{
|
Container: testCase.container,
|
||||||
Image: "gcr.io/google_containers/busybox:1.24",
|
|
||||||
Name: name,
|
|
||||||
Command: []string{"/bin/sh", "-c"},
|
|
||||||
Args: []string{fmt.Sprintf("/bin/echo -n %s > %s", terminationMessage, terminationMessagePath)},
|
|
||||||
TerminationMessagePath: terminationMessagePath,
|
|
||||||
SecurityContext: &v1.SecurityContext{
|
|
||||||
Privileged: &priv,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
RestartPolicy: v1.RestartPolicyNever,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,8 +218,8 @@ while true; do sleep 1; done
|
|||||||
c.Create()
|
c.Create()
|
||||||
defer c.Delete()
|
defer c.Delete()
|
||||||
|
|
||||||
By("wait for the container to succeed")
|
By(fmt.Sprintf("wait for the container to reach %s", testCase.phase))
|
||||||
Eventually(c.GetPhase, retryTimeout, pollInterval).Should(Equal(v1.PodSucceeded))
|
Eventually(c.GetPhase, retryTimeout, pollInterval).Should(Equal(testCase.phase))
|
||||||
|
|
||||||
By("get the container status")
|
By("get the container status")
|
||||||
status, err := c.GetStatus()
|
status, err := c.GetStatus()
|
||||||
@ -163,11 +229,12 @@ while true; do sleep 1; done
|
|||||||
Expect(GetContainerState(status.State)).To(Equal(ContainerStateTerminated))
|
Expect(GetContainerState(status.State)).To(Equal(ContainerStateTerminated))
|
||||||
|
|
||||||
By("the termination message should be set")
|
By("the termination message should be set")
|
||||||
Expect(status.State.Terminated.Message).Should(Equal(terminationMessage))
|
Expect(status.State.Terminated.Message).Should(testCase.message)
|
||||||
|
|
||||||
By("delete the container")
|
By("delete the container")
|
||||||
Expect(c.Delete()).To(Succeed())
|
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() {
|
||||||
|
Loading…
Reference in New Issue
Block a user