1
16
17 package node
18
19 import (
20 "context"
21
22 "github.com/onsi/gomega"
23
24 v1 "k8s.io/api/core/v1"
25 "k8s.io/apimachinery/pkg/util/uuid"
26 "k8s.io/kubernetes/test/e2e/framework"
27 e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
28 e2epodoutput "k8s.io/kubernetes/test/e2e/framework/pod/output"
29 admissionapi "k8s.io/pod-security-admission/api"
30 )
31
32 var _ = SIGDescribe("Containers", func() {
33 f := framework.NewDefaultFramework("containers")
34 f.NamespacePodSecurityLevel = admissionapi.LevelBaseline
35
36
41 framework.ConformanceIt("should use the image defaults if command and args are blank", f.WithNodeConformance(), func(ctx context.Context) {
42 pod := entrypointTestPod(f.Namespace.Name)
43 pod.Spec.Containers[0].Args = nil
44 pod = e2epod.NewPodClient(f).Create(ctx, pod)
45 err := e2epod.WaitForPodNameRunningInNamespace(ctx, f.ClientSet, pod.Name, f.Namespace.Name)
46 framework.ExpectNoError(err, "Expected pod %q to be running, got error: %v", pod.Name, err)
47 pollLogs := func() (string, error) {
48 return e2epod.GetPodLogs(ctx, f.ClientSet, f.Namespace.Name, pod.Name, pod.Spec.Containers[0].Name)
49 }
50
51
52
53 gomega.Eventually(ctx, pollLogs, 3, framework.Poll).Should(gomega.ContainSubstring("Paused"))
54 })
55
56
61 framework.ConformanceIt("should be able to override the image's default arguments (container cmd)", f.WithNodeConformance(), func(ctx context.Context) {
62 pod := entrypointTestPod(f.Namespace.Name, "entrypoint-tester", "override", "arguments")
63 e2epodoutput.TestContainerOutput(ctx, f, "override arguments", pod, 0, []string{
64 "[/agnhost entrypoint-tester override arguments]",
65 })
66 })
67
68
69
70
75 framework.ConformanceIt("should be able to override the image's default command (container entrypoint)", f.WithNodeConformance(), func(ctx context.Context) {
76 pod := entrypointTestPod(f.Namespace.Name, "entrypoint-tester")
77 pod.Spec.Containers[0].Command = []string{"/agnhost-2"}
78
79 e2epodoutput.TestContainerOutput(ctx, f, "override command", pod, 0, []string{
80 "[/agnhost-2 entrypoint-tester]",
81 })
82 })
83
84
89 framework.ConformanceIt("should be able to override the image's default command and arguments", f.WithNodeConformance(), func(ctx context.Context) {
90 pod := entrypointTestPod(f.Namespace.Name, "entrypoint-tester", "override", "arguments")
91 pod.Spec.Containers[0].Command = []string{"/agnhost-2"}
92
93 e2epodoutput.TestContainerOutput(ctx, f, "override all", pod, 0, []string{
94 "[/agnhost-2 entrypoint-tester override arguments]",
95 })
96 })
97 })
98
99
100 func entrypointTestPod(namespace string, entrypointArgs ...string) *v1.Pod {
101 podName := "client-containers-" + string(uuid.NewUUID())
102 pod := e2epod.NewAgnhostPod(namespace, podName, nil, nil, nil, entrypointArgs...)
103
104 one := int64(1)
105 pod.Spec.TerminationGracePeriodSeconds = &one
106 pod.Spec.RestartPolicy = v1.RestartPolicyNever
107 return pod
108 }
109
View as plain text