e2e framework: move pod exec and create into sub package

This commit is contained in:
Patrick Ohly 2022-08-25 19:54:24 +02:00
parent 8af3258526
commit a46fea53e6
30 changed files with 154 additions and 140 deletions

View File

@ -26,7 +26,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/uuid"
podutil "k8s.io/kubernetes/pkg/api/v1/pod" podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/test/e2e/framework" e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
) )
const ( const (
@ -44,7 +44,7 @@ type ConformanceContainer struct {
Volumes []v1.Volume Volumes []v1.Volume
ImagePullSecrets []string ImagePullSecrets []string
PodClient *framework.PodClient PodClient *e2etodopod.PodClient
podName string podName string
PodSecurityContext *v1.PodSecurityContext PodSecurityContext *v1.PodSecurityContext
} }

View File

@ -40,6 +40,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2eevents "k8s.io/kubernetes/test/e2e/framework/events" e2eevents "k8s.io/kubernetes/test/e2e/framework/events"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
testutils "k8s.io/kubernetes/test/utils" testutils "k8s.io/kubernetes/test/utils"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
@ -57,11 +58,11 @@ const (
var _ = SIGDescribe("Probing container", func() { var _ = SIGDescribe("Probing container", func() {
f := framework.NewDefaultFramework("container-probe") f := framework.NewDefaultFramework("container-probe")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
probe := webserverProbeBuilder{} probe := webserverProbeBuilder{}
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
}) })
/* /*
@ -561,7 +562,7 @@ var _ = SIGDescribe("Probing container", func() {
ginkgo.It("should mark readiness on pods to false while pod is in progress of terminating when a pod has a readiness probe", func() { ginkgo.It("should mark readiness on pods to false while pod is in progress of terminating when a pod has a readiness probe", func() {
podName := "probe-test-" + string(uuid.NewUUID()) podName := "probe-test-" + string(uuid.NewUUID())
podClient := f.PodClient() podClient := e2etodopod.NewPodClient(f)
terminationGracePeriod := int64(30) terminationGracePeriod := int64(30)
script := ` script := `
_term() { _term() {
@ -625,7 +626,7 @@ done
ginkgo.It("should mark readiness on pods to false and disable liveness probes while pod is in progress of terminating", func() { ginkgo.It("should mark readiness on pods to false and disable liveness probes while pod is in progress of terminating", func() {
podName := "probe-test-" + string(uuid.NewUUID()) podName := "probe-test-" + string(uuid.NewUUID())
podClient := f.PodClient() podClient := e2etodopod.NewPodClient(f)
terminationGracePeriod := int64(30) terminationGracePeriod := int64(30)
script := ` script := `
_term() { _term() {
@ -937,7 +938,7 @@ func (b webserverProbeBuilder) build() *v1.Probe {
// RunLivenessTest verifies the number of restarts for pod with given expected number of restarts // RunLivenessTest verifies the number of restarts for pod with given expected number of restarts
func RunLivenessTest(f *framework.Framework, pod *v1.Pod, expectNumRestarts int, timeout time.Duration) { func RunLivenessTest(f *framework.Framework, pod *v1.Pod, expectNumRestarts int, timeout time.Duration) {
podClient := f.PodClient() podClient := e2etodopod.NewPodClient(f)
ns := f.Namespace.Name ns := f.Namespace.Name
gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty()) gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty())
containerName := pod.Spec.Containers[0].Name containerName := pod.Spec.Containers[0].Name
@ -997,7 +998,7 @@ func RunLivenessTest(f *framework.Framework, pod *v1.Pod, expectNumRestarts int,
} }
func runReadinessFailTest(f *framework.Framework, pod *v1.Pod, notReadyUntil time.Duration) { func runReadinessFailTest(f *framework.Framework, pod *v1.Pod, notReadyUntil time.Duration) {
podClient := f.PodClient() podClient := e2etodopod.NewPodClient(f)
ns := f.Namespace.Name ns := f.Namespace.Name
gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty()) gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty())

View File

@ -39,7 +39,7 @@ var _ = SIGDescribe("Containers", func() {
framework.ConformanceIt("should use the image defaults if command and args are blank [NodeConformance]", func() { framework.ConformanceIt("should use the image defaults if command and args are blank [NodeConformance]", func() {
pod := entrypointTestPod(f.Namespace.Name) pod := entrypointTestPod(f.Namespace.Name)
pod.Spec.Containers[0].Args = nil pod.Spec.Containers[0].Args = nil
pod = f.PodClient().Create(pod) pod = e2etodopod.NewPodClient(f).Create(pod)
err := e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) err := e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
framework.ExpectNoError(err, "Expected pod %q to be running, got error: %v", pod.Name, err) framework.ExpectNoError(err, "Expected pod %q to be running, got error: %v", pod.Name, err)
pollLogs := func() (string, error) { pollLogs := func() (string, error) {

View File

@ -24,6 +24,7 @@ import (
"k8s.io/kubernetes/pkg/kubelet/util/format" "k8s.io/kubernetes/pkg/kubelet/util/format"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
@ -34,9 +35,9 @@ import (
var _ = SIGDescribe("Ephemeral Containers [NodeConformance]", func() { var _ = SIGDescribe("Ephemeral Containers [NodeConformance]", func() {
f := framework.NewDefaultFramework("ephemeral-containers-test") f := framework.NewDefaultFramework("ephemeral-containers-test")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
}) })
// Release: 1.25 // Release: 1.25
@ -74,7 +75,7 @@ var _ = SIGDescribe("Ephemeral Containers [NodeConformance]", func() {
ginkgo.By("checking pod container endpoints") ginkgo.By("checking pod container endpoints")
// Can't use anything depending on kubectl here because it's not available in the node test environment // Can't use anything depending on kubectl here because it's not available in the node test environment
output := f.ExecCommandInContainer(pod.Name, ecName, "/bin/echo", "marco") output := e2etodopod.ExecCommandInContainer(f, pod.Name, ecName, "/bin/echo", "marco")
gomega.Expect(output).To(gomega.ContainSubstring("marco")) gomega.Expect(output).To(gomega.ContainSubstring("marco"))
log, err := e2epod.GetPodLogs(f.ClientSet, pod.Namespace, pod.Name, ecName) log, err := e2epod.GetPodLogs(f.ClientSet, pod.Namespace, pod.Name, ecName)
framework.ExpectNoError(err, "Failed to get logs for pod %q ephemeral container %q", format.Pod(pod), ecName) framework.ExpectNoError(err, "Failed to get logs for pod %q ephemeral container %q", format.Pod(pod), ecName)

View File

@ -262,7 +262,7 @@ var _ = SIGDescribe("Variable Expansion", func() {
pod.ObjectMeta.Annotations = map[string]string{"notmysubpath": "mypath"} pod.ObjectMeta.Annotations = map[string]string{"notmysubpath": "mypath"}
ginkgo.By("creating the pod with failed condition") ginkgo.By("creating the pod with failed condition")
var podClient *framework.PodClient = f.PodClient() podClient := e2etodopod.NewPodClient(f)
pod = podClient.Create(pod) pod = podClient.Create(pod)
err := e2epod.WaitTimeoutForPodRunningInNamespace(f.ClientSet, pod.Name, pod.Namespace, framework.PodStartShortTimeout) err := e2epod.WaitTimeoutForPodRunningInNamespace(f.ClientSet, pod.Name, pod.Namespace, framework.PodStartShortTimeout)
@ -334,7 +334,7 @@ var _ = SIGDescribe("Variable Expansion", func() {
pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "mypath"} pod.ObjectMeta.Annotations = map[string]string{"mysubpath": "mypath"}
ginkgo.By("creating the pod") ginkgo.By("creating the pod")
var podClient *framework.PodClient = f.PodClient() podClient := e2etodopod.NewPodClient(f)
pod = podClient.Create(pod) pod = podClient.Create(pod)
ginkgo.By("waiting for pod running") ginkgo.By("waiting for pod running")
@ -343,14 +343,14 @@ var _ = SIGDescribe("Variable Expansion", func() {
ginkgo.By("creating a file in subpath") ginkgo.By("creating a file in subpath")
cmd := "touch /volume_mount/mypath/foo/test.log" cmd := "touch /volume_mount/mypath/foo/test.log"
_, _, err = f.ExecShellInPodWithFullOutput(pod.Name, cmd) _, _, err = e2etodopod.ExecShellInPodWithFullOutput(f, pod.Name, cmd)
if err != nil { if err != nil {
framework.Failf("expected to be able to write to subpath") framework.Failf("expected to be able to write to subpath")
} }
ginkgo.By("test for file in mounted path") ginkgo.By("test for file in mounted path")
cmd = "test -f /subpath_mount/test.log" cmd = "test -f /subpath_mount/test.log"
_, _, err = f.ExecShellInPodWithFullOutput(pod.Name, cmd) _, _, err = e2etodopod.ExecShellInPodWithFullOutput(f, pod.Name, cmd)
if err != nil { if err != nil {
framework.Failf("expected to be able to verify file") framework.Failf("expected to be able to verify file")
} }
@ -371,7 +371,7 @@ var _ = SIGDescribe("Variable Expansion", func() {
}) })
func testPodFailSubpath(f *framework.Framework, pod *v1.Pod) { func testPodFailSubpath(f *framework.Framework, pod *v1.Pod) {
var podClient *framework.PodClient = f.PodClient() podClient := e2etodopod.NewPodClient(f)
pod = podClient.Create(pod) pod = podClient.Create(pod)
defer func() { defer func() {

View File

@ -39,6 +39,7 @@ import (
podutil "k8s.io/kubernetes/pkg/api/v1/pod" podutil "k8s.io/kubernetes/pkg/api/v1/pod"
"k8s.io/kubernetes/pkg/client/conditions" "k8s.io/kubernetes/pkg/client/conditions"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
) )
@ -160,9 +161,9 @@ func initContainersInvariants(pod *v1.Pod) error {
var _ = SIGDescribe("InitContainer [NodeConformance]", func() { var _ = SIGDescribe("InitContainer [NodeConformance]", func() {
f := framework.NewDefaultFramework("init-container") f := framework.NewDefaultFramework("init-container")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
}) })
/* /*

View File

@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
@ -37,9 +38,9 @@ import (
var _ = SIGDescribe("Kubelet", func() { var _ = SIGDescribe("Kubelet", func() {
f := framework.NewDefaultFramework("kubelet-test") f := framework.NewDefaultFramework("kubelet-test")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
}) })
ginkgo.Context("when scheduling a busybox command in a pod", func() { ginkgo.Context("when scheduling a busybox command in a pod", func() {
podName := "busybox-scheduling-" + string(uuid.NewUUID()) podName := "busybox-scheduling-" + string(uuid.NewUUID())

View File

@ -26,6 +26,7 @@ import (
"k8s.io/klog/v2" "k8s.io/klog/v2"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
) )
@ -92,12 +93,12 @@ func (config *KubeletManagedHostConfig) setup() {
func (config *KubeletManagedHostConfig) createPodWithoutHostNetwork() { func (config *KubeletManagedHostConfig) createPodWithoutHostNetwork() {
podSpec := config.createPodSpec(etcHostsPodName) podSpec := config.createPodSpec(etcHostsPodName)
config.pod = config.f.PodClient().CreateSync(podSpec) config.pod = e2etodopod.NewPodClient(config.f).CreateSync(podSpec)
} }
func (config *KubeletManagedHostConfig) createPodWithHostNetwork() { func (config *KubeletManagedHostConfig) createPodWithHostNetwork() {
podSpec := config.createPodSpecWithHostNetwork(etcHostsHostNetworkPodName) podSpec := config.createPodSpecWithHostNetwork(etcHostsHostNetworkPodName)
config.hostNetworkPod = config.f.PodClient().CreateSync(podSpec) config.hostNetworkPod = e2etodopod.NewPodClient(config.f).CreateSync(podSpec)
} }
func assertManagedStatus( func assertManagedStatus(
@ -148,7 +149,7 @@ func assertManagedStatus(
} }
func (config *KubeletManagedHostConfig) getFileContents(podName, containerName, path string) string { func (config *KubeletManagedHostConfig) getFileContents(podName, containerName, path string) string {
return config.f.ExecCommandInContainer(podName, containerName, "cat", path) return e2etodopod.ExecCommandInContainer(config.f, podName, containerName, "cat", path)
} }
func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod { func (config *KubeletManagedHostConfig) createPodSpec(podName string) *v1.Pod {

View File

@ -27,6 +27,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2enode "k8s.io/kubernetes/test/e2e/framework/node" e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
@ -37,7 +38,7 @@ import (
var _ = SIGDescribe("Container Lifecycle Hook", func() { var _ = SIGDescribe("Container Lifecycle Hook", func() {
f := framework.NewDefaultFramework("container-lifecycle-hook") f := framework.NewDefaultFramework("container-lifecycle-hook")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
const ( const (
podCheckInterval = 1 * time.Second podCheckInterval = 1 * time.Second
postStartWaitTimeout = 2 * time.Minute postStartWaitTimeout = 2 * time.Minute
@ -60,7 +61,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
e2epod.SetAffinity(&nodeSelection, targetNode) e2epod.SetAffinity(&nodeSelection, targetNode)
e2epod.SetNodeSelection(&podHandleHookRequest.Spec, nodeSelection) e2epod.SetNodeSelection(&podHandleHookRequest.Spec, nodeSelection)
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
ginkgo.By("create the container to handle the HTTPGet hook request.") ginkgo.By("create the container to handle the HTTPGet hook request.")
newPod := podClient.CreateSync(podHandleHookRequest) newPod := podClient.CreateSync(podHandleHookRequest)
targetIP = newPod.Status.PodIP targetIP = newPod.Status.PodIP
@ -80,7 +81,7 @@ var _ = SIGDescribe("Container Lifecycle Hook", func() {
}, postStartWaitTimeout, podCheckInterval).Should(gomega.BeNil()) }, postStartWaitTimeout, podCheckInterval).Should(gomega.BeNil())
} }
ginkgo.By("delete the pod with lifecycle hook") ginkgo.By("delete the pod with lifecycle hook")
podClient.DeleteSync(podWithHook.Name, *metav1.NewDeleteOptions(15), framework.DefaultPodDeletionTimeout) podClient.DeleteSync(podWithHook.Name, *metav1.NewDeleteOptions(15), e2etodopod.DefaultPodDeletionTimeout)
if podWithHook.Spec.Containers[0].Lifecycle.PreStop != nil { if podWithHook.Spec.Containers[0].Lifecycle.PreStop != nil {
ginkgo.By("check prestop hook") ginkgo.By("check prestop hook")
gomega.Eventually(func() error { gomega.Eventually(func() error {

View File

@ -28,6 +28,7 @@ import (
e2enode "k8s.io/kubernetes/test/e2e/framework/node" e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
) )
@ -57,7 +58,7 @@ var _ = SIGDescribe("PodOSRejection [NodeConformance]", func() {
NodeName: linuxNode.Name, // Set the node to an node which doesn't support NodeName: linuxNode.Name, // Set the node to an node which doesn't support
}, },
} }
pod = f.PodClient().Create(pod) pod = e2etodopod.NewPodClient(f).Create(pod)
// Check the pod is still not running // Check the pod is still not running
err = e2epod.WaitForPodFailedReason(f.ClientSet, pod, "PodOSNotSupported", f.Timeouts.PodStartShort) err = e2epod.WaitForPodFailedReason(f.ClientSet, pod, "PodOSNotSupported", f.Timeouts.PodStartShort)
framework.ExpectNoError(err) framework.ExpectNoError(err)

View File

@ -69,7 +69,7 @@ const (
) )
// testHostIP tests that a pod gets a host IP // testHostIP tests that a pod gets a host IP
func testHostIP(podClient *framework.PodClient, pod *v1.Pod) { func testHostIP(podClient *e2etodopod.PodClient, pod *v1.Pod) {
ginkgo.By("creating pod") ginkgo.By("creating pod")
podClient.CreateSync(pod) podClient.CreateSync(pod)
@ -92,7 +92,7 @@ func testHostIP(podClient *framework.PodClient, pod *v1.Pod) {
} }
} }
func startPodAndGetBackOffs(podClient *framework.PodClient, pod *v1.Pod, sleepAmount time.Duration) (time.Duration, time.Duration) { func startPodAndGetBackOffs(podClient *e2etodopod.PodClient, pod *v1.Pod, sleepAmount time.Duration) (time.Duration, time.Duration) {
podClient.CreateSync(pod) podClient.CreateSync(pod)
time.Sleep(sleepAmount) time.Sleep(sleepAmount)
gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty()) gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty())
@ -119,7 +119,7 @@ func startPodAndGetBackOffs(podClient *framework.PodClient, pod *v1.Pod, sleepAm
return delay1, delay2 return delay1, delay2
} }
func getRestartDelay(podClient *framework.PodClient, podName string, containerName string) (time.Duration, error) { func getRestartDelay(podClient *e2etodopod.PodClient, podName string, containerName string) (time.Duration, error) {
beginTime := time.Now() beginTime := time.Now()
var previousRestartCount int32 = -1 var previousRestartCount int32 = -1
var previousFinishedAt time.Time var previousFinishedAt time.Time
@ -188,11 +188,11 @@ func expectNoErrorWithRetries(fn func() error, maxRetries int, explain ...interf
var _ = SIGDescribe("Pods", func() { var _ = SIGDescribe("Pods", func() {
f := framework.NewDefaultFramework("pods") f := framework.NewDefaultFramework("pods")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelRestricted f.NamespacePodSecurityEnforceLevel = admissionapi.LevelRestricted
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
var dc dynamic.Interface var dc dynamic.Interface
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
dc = f.DynamicClient dc = f.DynamicClient
}) })
@ -306,7 +306,7 @@ var _ = SIGDescribe("Pods", func() {
ginkgo.By("verifying pod deletion was observed") ginkgo.By("verifying pod deletion was observed")
deleted := false deleted := false
var lastPod *v1.Pod var lastPod *v1.Pod
timer := time.After(framework.DefaultPodDeletionTimeout) timer := time.After(e2etodopod.DefaultPodDeletionTimeout)
for !deleted { for !deleted {
select { select {
case event := <-w.ResultChan(): case event := <-w.ResultChan():
@ -808,7 +808,7 @@ var _ = SIGDescribe("Pods", func() {
} }
ginkgo.By("submitting the pod to kubernetes") ginkgo.By("submitting the pod to kubernetes")
f.PodClient().Create(pod) e2etodopod.NewPodClient(f).Create(pod)
e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
if podClient.PodIsReady(podName) { if podClient.PodIsReady(podName) {
framework.Failf("Expect pod(%s/%s)'s Ready condition to be false initially.", f.Namespace.Name, pod.Name) framework.Failf("Expect pod(%s/%s)'s Ready condition to be false initially.", f.Namespace.Name, pod.Name)

View File

@ -20,9 +20,10 @@ import (
"fmt" "fmt"
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
"k8s.io/api/core/v1" v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
) )
@ -66,16 +67,16 @@ func (c *PrivilegedPodTestConfig) run(containerName string, expectSuccess bool)
cmd := []string{"ip", "link", "add", "dummy1", "type", "dummy"} cmd := []string{"ip", "link", "add", "dummy1", "type", "dummy"}
reverseCmd := []string{"ip", "link", "del", "dummy1"} reverseCmd := []string{"ip", "link", "del", "dummy1"}
stdout, stderr, err := c.f.ExecCommandInContainerWithFullOutput( stdout, stderr, err := e2etodopod.ExecCommandInContainerWithFullOutput(
c.privilegedPod, containerName, cmd...) c.f, c.privilegedPod, containerName, cmd...)
msg := fmt.Sprintf("cmd %v, stdout %q, stderr %q", cmd, stdout, stderr) msg := fmt.Sprintf("cmd %v, stdout %q, stderr %q", cmd, stdout, stderr)
if expectSuccess { if expectSuccess {
framework.ExpectNoError(err, msg) framework.ExpectNoError(err, msg)
// We need to clean up the dummy link that was created, as it // We need to clean up the dummy link that was created, as it
// leaks out into the node level -- yuck. // leaks out into the node level -- yuck.
_, _, err := c.f.ExecCommandInContainerWithFullOutput( _, _, err := e2etodopod.ExecCommandInContainerWithFullOutput(
c.privilegedPod, containerName, reverseCmd...) c.f, c.privilegedPod, containerName, reverseCmd...)
framework.ExpectNoError(err, framework.ExpectNoError(err,
fmt.Sprintf("could not remove dummy1 link: %v", err)) fmt.Sprintf("could not remove dummy1 link: %v", err))
} else { } else {
@ -115,5 +116,5 @@ func (c *PrivilegedPodTestConfig) createPodsSpec() *v1.Pod {
func (c *PrivilegedPodTestConfig) createPods() { func (c *PrivilegedPodTestConfig) createPods() {
podSpec := c.createPodsSpec() podSpec := c.createPodsSpec()
c.pod = c.f.PodClient().CreateSync(podSpec) c.pod = e2etodopod.NewPodClient(c.f).CreateSync(podSpec)
} }

View File

@ -28,6 +28,7 @@ import (
"k8s.io/apimachinery/pkg/util/uuid" "k8s.io/apimachinery/pkg/util/uuid"
"k8s.io/kubernetes/pkg/kubelet/images" "k8s.io/kubernetes/pkg/kubelet/images"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
@ -98,7 +99,7 @@ while true; do sleep 1; done
testContainer.Name = testCase.Name testContainer.Name = testCase.Name
testContainer.Command = []string{"sh", "-c", tmpCmd} testContainer.Command = []string{"sh", "-c", tmpCmd}
terminateContainer := ConformanceContainer{ terminateContainer := ConformanceContainer{
PodClient: f.PodClient(), PodClient: e2etodopod.NewPodClient(f),
Container: testContainer, Container: testContainer,
RestartPolicy: testCase.RestartPolicy, RestartPolicy: testCase.RestartPolicy,
Volumes: testVolumes, Volumes: testVolumes,
@ -143,7 +144,7 @@ while true; do sleep 1; done
matchTerminationMessage := func(container v1.Container, expectedPhase v1.PodPhase, expectedMsg gomegatypes.GomegaMatcher) { matchTerminationMessage := func(container v1.Container, expectedPhase v1.PodPhase, expectedMsg gomegatypes.GomegaMatcher) {
container.Name = "termination-message-container" container.Name = "termination-message-container"
c := ConformanceContainer{ c := ConformanceContainer{
PodClient: f.PodClient(), PodClient: e2etodopod.NewPodClient(f),
Container: container, Container: container,
RestartPolicy: v1.RestartPolicyNever, RestartPolicy: v1.RestartPolicyNever,
} }
@ -268,7 +269,7 @@ while true; do sleep 1; done
command = []string{"ping", "-t", "localhost"} command = []string{"ping", "-t", "localhost"}
} }
container := ConformanceContainer{ container := ConformanceContainer{
PodClient: f.PodClient(), PodClient: e2etodopod.NewPodClient(f),
Container: v1.Container{ Container: v1.Container{
Name: "image-pull-test", Name: "image-pull-test",
Image: image, Image: image,

View File

@ -38,6 +38,7 @@ import (
e2enode "k8s.io/kubernetes/test/e2e/framework/node" e2enode "k8s.io/kubernetes/test/e2e/framework/node"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
@ -62,7 +63,7 @@ var _ = SIGDescribe("RuntimeClass", func() {
handler := f.Namespace.Name + "-handler" handler := f.Namespace.Name + "-handler"
rcName := createRuntimeClass(f, "unconfigured-handler", handler, nil) rcName := createRuntimeClass(f, "unconfigured-handler", handler, nil)
defer deleteRuntimeClass(f, rcName) defer deleteRuntimeClass(f, rcName)
pod := f.PodClient().Create(e2enode.NewRuntimeClassPod(rcName)) pod := e2etodopod.NewPodClient(f).Create(e2enode.NewRuntimeClassPod(rcName))
eventSelector := fields.Set{ eventSelector := fields.Set{
"involvedObject.kind": "Pod", "involvedObject.kind": "Pod",
"involvedObject.name": pod.Name, "involvedObject.name": pod.Name,
@ -89,7 +90,7 @@ var _ = SIGDescribe("RuntimeClass", func() {
rcName := createRuntimeClass(f, "preconfigured-handler", e2enode.PreconfiguredRuntimeClassHandler, nil) rcName := createRuntimeClass(f, "preconfigured-handler", e2enode.PreconfiguredRuntimeClassHandler, nil)
defer deleteRuntimeClass(f, rcName) defer deleteRuntimeClass(f, rcName)
pod := f.PodClient().Create(e2enode.NewRuntimeClassPod(rcName)) pod := e2etodopod.NewPodClient(f).Create(e2enode.NewRuntimeClassPod(rcName))
expectPodSuccess(f, pod) expectPodSuccess(f, pod)
}) })
@ -104,7 +105,7 @@ var _ = SIGDescribe("RuntimeClass", func() {
framework.ConformanceIt("should schedule a Pod requesting a RuntimeClass without PodOverhead [NodeConformance]", func() { framework.ConformanceIt("should schedule a Pod requesting a RuntimeClass without PodOverhead [NodeConformance]", func() {
rcName := createRuntimeClass(f, "preconfigured-handler", e2enode.PreconfiguredRuntimeClassHandler, nil) rcName := createRuntimeClass(f, "preconfigured-handler", e2enode.PreconfiguredRuntimeClassHandler, nil)
defer deleteRuntimeClass(f, rcName) defer deleteRuntimeClass(f, rcName)
pod := f.PodClient().Create(e2enode.NewRuntimeClassPod(rcName)) pod := e2etodopod.NewPodClient(f).Create(e2enode.NewRuntimeClassPod(rcName))
// there is only one pod in the namespace // there is only one pod in the namespace
label := labels.SelectorFromSet(labels.Set(map[string]string{})) label := labels.SelectorFromSet(labels.Set(map[string]string{}))
pods, err := e2epod.WaitForPodsWithLabelScheduled(f.ClientSet, f.Namespace.Name, label) pods, err := e2epod.WaitForPodsWithLabelScheduled(f.ClientSet, f.Namespace.Name, label)
@ -134,7 +135,7 @@ var _ = SIGDescribe("RuntimeClass", func() {
}, },
}) })
defer deleteRuntimeClass(f, rcName) defer deleteRuntimeClass(f, rcName)
pod := f.PodClient().Create(e2enode.NewRuntimeClassPod(rcName)) pod := e2etodopod.NewPodClient(f).Create(e2enode.NewRuntimeClassPod(rcName))
// there is only one pod in the namespace // there is only one pod in the namespace
label := labels.SelectorFromSet(labels.Set(map[string]string{})) label := labels.SelectorFromSet(labels.Set(map[string]string{}))
pods, err := e2epod.WaitForPodsWithLabelScheduled(f.ClientSet, f.Namespace.Name, label) pods, err := e2epod.WaitForPodsWithLabelScheduled(f.ClientSet, f.Namespace.Name, label)

View File

@ -46,9 +46,9 @@ var (
var _ = SIGDescribe("Security Context", func() { var _ = SIGDescribe("Security Context", func() {
f := framework.NewDefaultFramework("security-context-test") f := framework.NewDefaultFramework("security-context-test")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
}) })
ginkgo.Context("When creating a pod with HostUsers", func() { ginkgo.Context("When creating a pod with HostUsers", func() {
@ -74,14 +74,14 @@ var _ = SIGDescribe("Security Context", func() {
ginkgo.It("must create the user namespace if set to false [LinuxOnly] [Feature:UserNamespacesStatelessPodsSupport]", func() { ginkgo.It("must create the user namespace if set to false [LinuxOnly] [Feature:UserNamespacesStatelessPodsSupport]", func() {
// with hostUsers=false the pod must use a new user namespace // with hostUsers=false the pod must use a new user namespace
podClient := f.PodClientNS(f.Namespace.Name) podClient := e2etodopod.PodClientNS(f, f.Namespace.Name)
createdPod1 := podClient.Create(makePod(false)) createdPod1 := podClient.Create(makePod(false))
createdPod2 := podClient.Create(makePod(false)) createdPod2 := podClient.Create(makePod(false))
defer func() { defer func() {
ginkgo.By("delete the pods") ginkgo.By("delete the pods")
podClient.DeleteSync(createdPod1.Name, metav1.DeleteOptions{}, framework.DefaultPodDeletionTimeout) podClient.DeleteSync(createdPod1.Name, metav1.DeleteOptions{}, e2etodopod.DefaultPodDeletionTimeout)
podClient.DeleteSync(createdPod2.Name, metav1.DeleteOptions{}, framework.DefaultPodDeletionTimeout) podClient.DeleteSync(createdPod2.Name, metav1.DeleteOptions{}, e2etodopod.DefaultPodDeletionTimeout)
}() }()
getLogs := func(pod *v1.Pod) (string, error) { getLogs := func(pod *v1.Pod) (string, error) {
err := e2epod.WaitForPodSuccessInNamespaceTimeout(f.ClientSet, createdPod1.Name, f.Namespace.Name, f.Timeouts.PodStart) err := e2epod.WaitForPodSuccessInNamespaceTimeout(f.ClientSet, createdPod1.Name, f.Namespace.Name, f.Timeouts.PodStart)

View File

@ -25,6 +25,7 @@ import (
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper" e2eskipper "k8s.io/kubernetes/test/e2e/framework/skipper"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
admissionapi "k8s.io/pod-security-admission/api" admissionapi "k8s.io/pod-security-admission/api"
@ -41,7 +42,7 @@ var _ = SIGDescribe("Sysctls [LinuxOnly] [NodeConformance]", func() {
f := framework.NewDefaultFramework("sysctl") f := framework.NewDefaultFramework("sysctl")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged f.NamespacePodSecurityEnforceLevel = admissionapi.LevelPrivileged
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
testPod := func() *v1.Pod { testPod := func() *v1.Pod {
podName := "sysctl-" + string(uuid.NewUUID()) podName := "sysctl-" + string(uuid.NewUUID())
@ -65,7 +66,7 @@ var _ = SIGDescribe("Sysctls [LinuxOnly] [NodeConformance]", func() {
} }
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
}) })
/* /*
@ -93,7 +94,7 @@ var _ = SIGDescribe("Sysctls [LinuxOnly] [NodeConformance]", func() {
// watch for events instead of termination of pod because the kubelet deletes // watch for events instead of termination of pod because the kubelet deletes
// failed pods without running containers. This would create a race as the pod // failed pods without running containers. This would create a race as the pod
// might have already been deleted here. // might have already been deleted here.
ev, err := f.PodClient().WaitForErrorEventOrSuccess(pod) ev, err := e2etodopod.NewPodClient(f).WaitForErrorEventOrSuccess(pod)
framework.ExpectNoError(err) framework.ExpectNoError(err)
gomega.Expect(ev).To(gomega.BeNil()) gomega.Expect(ev).To(gomega.BeNil())
@ -201,7 +202,7 @@ var _ = SIGDescribe("Sysctls [LinuxOnly] [NodeConformance]", func() {
// watch for events instead of termination of pod because the kubelet deletes // watch for events instead of termination of pod because the kubelet deletes
// failed pods without running containers. This would create a race as the pod // failed pods without running containers. This would create a race as the pod
// might have already been deleted here. // might have already been deleted here.
ev, err := f.PodClient().WaitForErrorEventOrSuccess(pod) ev, err := e2etodopod.NewPodClient(f).WaitForErrorEventOrSuccess(pod)
framework.ExpectNoError(err) framework.ExpectNoError(err)
gomega.Expect(ev).To(gomega.BeNil()) gomega.Expect(ev).To(gomega.BeNil())

View File

@ -149,7 +149,7 @@ var _ = SIGDescribe("ConfigMap", func() {
"--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volume/data-1") "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/configmap-volume/data-1")
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
f.PodClient().CreateSync(pod) e2etodopod.NewPodClient(f).CreateSync(pod)
pollLogs := func() (string, error) { pollLogs := func() (string, error) {
return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, pod.Spec.Containers[0].Name) return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, pod.Spec.Containers[0].Name)
@ -216,7 +216,7 @@ var _ = SIGDescribe("ConfigMap", func() {
}) })
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
f.PodClient().Create(pod) e2etodopod.NewPodClient(f).Create(pod)
e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
pollLogs1 := func() (string, error) { pollLogs1 := func() (string, error) {
@ -375,7 +375,7 @@ var _ = SIGDescribe("ConfigMap", func() {
}, },
} }
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
f.PodClient().CreateSync(pod) e2etodopod.NewPodClient(f).CreateSync(pod)
pollCreateLogs := func() (string, error) { pollCreateLogs := func() (string, error) {
return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName) return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName)
@ -691,7 +691,7 @@ func createNonOptionalConfigMapPod(f *framework.Framework, volumeMountPath strin
pod.Spec.Volumes[0].VolumeSource.ConfigMap.Optional = &falseValue pod.Spec.Volumes[0].VolumeSource.ConfigMap.Optional = &falseValue
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
pod = f.PodClient().Create(pod) pod = e2etodopod.NewPodClient(f).Create(pod)
return pod, e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) return pod, e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
} }
@ -721,7 +721,7 @@ func createNonOptionalConfigMapPodWithConfig(f *framework.Framework, volumeMount
} }
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
pod = f.PodClient().Create(pod) pod = e2etodopod.NewPodClient(f).Create(pod)
return pod, e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) return pod, e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
} }

View File

@ -40,9 +40,9 @@ var _ = SIGDescribe("Downward API volume", func() {
const podLogTimeout = 3 * time.Minute const podLogTimeout = 3 * time.Minute
f := framework.NewDefaultFramework("downward-api") f := framework.NewDefaultFramework("downward-api")
f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline f.NamespacePodSecurityEnforceLevel = admissionapi.LevelBaseline
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
}) })
/* /*

View File

@ -283,11 +283,11 @@ var _ = SIGDescribe("EmptyDir volumes", func() {
} }
ginkgo.By("Creating Pod") ginkgo.By("Creating Pod")
f.PodClient().Create(pod) e2etodopod.NewPodClient(f).Create(pod)
e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
ginkgo.By("Reading file content from the nginx-container") ginkgo.By("Reading file content from the nginx-container")
result := f.ExecShellInContainer(pod.Name, busyBoxMainContainerName, fmt.Sprintf("cat %s", busyBoxMainVolumeFilePath)) result := e2etodopod.ExecShellInContainer(f, pod.Name, busyBoxMainContainerName, fmt.Sprintf("cat %s", busyBoxMainVolumeFilePath))
framework.ExpectEqual(result, message, "failed to match expected string %s with %s", message, resultString) framework.ExpectEqual(result, message, "failed to match expected string %s with %s", message, resultString)
}) })
@ -343,18 +343,18 @@ var _ = SIGDescribe("EmptyDir volumes", func() {
var err error var err error
ginkgo.By("Creating Pod") ginkgo.By("Creating Pod")
pod = f.PodClient().CreateSync(pod) pod = e2etodopod.NewPodClient(f).CreateSync(pod)
ginkgo.By("Waiting for the pod running") ginkgo.By("Waiting for the pod running")
err = e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) err = e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
framework.ExpectNoError(err, "failed to deploy pod %s", pod.Name) framework.ExpectNoError(err, "failed to deploy pod %s", pod.Name)
ginkgo.By("Getting the pod") ginkgo.By("Getting the pod")
pod, err = f.PodClient().Get(context.TODO(), pod.Name, metav1.GetOptions{}) pod, err = e2etodopod.NewPodClient(f).Get(context.TODO(), pod.Name, metav1.GetOptions{})
framework.ExpectNoError(err, "failed to get pod %s", pod.Name) framework.ExpectNoError(err, "failed to get pod %s", pod.Name)
ginkgo.By("Reading empty dir size") ginkgo.By("Reading empty dir size")
result := f.ExecShellInContainer(pod.Name, busyBoxMainContainerName, fmt.Sprintf("df | grep %s | awk '{print $2}'", busyBoxMainVolumeMountPath)) result := e2etodopod.ExecShellInContainer(f, pod.Name, busyBoxMainContainerName, fmt.Sprintf("df | grep %s | awk '{print $2}'", busyBoxMainVolumeMountPath))
framework.ExpectEqual(result, expectedResult, "failed to match expected string %s with %s", expectedResult, result) framework.ExpectEqual(result, expectedResult, "failed to match expected string %s with %s", expectedResult, result)
}) })
}) })

View File

@ -148,7 +148,7 @@ var _ = SIGDescribe("Projected configMap", func() {
"--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/projected-configmap-volume/data-1") "--break_on_expected_content=false", containerTimeoutArg, "--file_content_in_loop=/etc/projected-configmap-volume/data-1")
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
f.PodClient().CreateSync(pod) e2etodopod.NewPodClient(f).CreateSync(pod)
pollLogs := func() (string, error) { pollLogs := func() (string, error) {
return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, pod.Spec.Containers[0].Name) return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, pod.Spec.Containers[0].Name)
@ -327,7 +327,7 @@ var _ = SIGDescribe("Projected configMap", func() {
}, },
} }
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
f.PodClient().CreateSync(pod) e2etodopod.NewPodClient(f).CreateSync(pod)
pollCreateLogs := func() (string, error) { pollCreateLogs := func() (string, error) {
return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName) return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName)

View File

@ -40,9 +40,9 @@ var _ = SIGDescribe("Projected downwardAPI", func() {
// How long to wait for a log pod to be displayed // How long to wait for a log pod to be displayed
const podLogTimeout = 2 * time.Minute const podLogTimeout = 2 * time.Minute
var podClient *framework.PodClient var podClient *e2etodopod.PodClient
ginkgo.BeforeEach(func() { ginkgo.BeforeEach(func() {
podClient = f.PodClient() podClient = e2etodopod.NewPodClient(f)
}) })
/* /*

View File

@ -368,7 +368,7 @@ var _ = SIGDescribe("Projected secret", func() {
}, },
} }
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
f.PodClient().CreateSync(pod) e2etodopod.NewPodClient(f).CreateSync(pod)
pollCreateLogs := func() (string, error) { pollCreateLogs := func() (string, error) {
return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName) return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName)

View File

@ -334,7 +334,7 @@ var _ = SIGDescribe("Secrets", func() {
}, },
} }
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
f.PodClient().CreateSync(pod) e2etodopod.NewPodClient(f).CreateSync(pod)
pollCreateLogs := func() (string, error) { pollCreateLogs := func() (string, error) {
return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName) return e2epod.GetPodLogs(f.ClientSet, f.Namespace.Name, pod.Name, createContainerName)
@ -650,7 +650,7 @@ func createNonOptionalSecretPod(f *framework.Framework, volumeMountPath, podName
}, },
} }
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
pod = f.PodClient().Create(pod) pod = e2etodopod.NewPodClient(f).Create(pod)
return e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) return e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
} }
@ -711,6 +711,6 @@ func createNonOptionalSecretPodWithSecret(f *framework.Framework, volumeMountPat
}, },
} }
ginkgo.By("Creating the pod") ginkgo.By("Creating the pod")
pod = f.PodClient().Create(pod) pod = e2etodopod.NewPodClient(f).Create(pod)
return e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name) return e2epod.WaitForPodNameRunningInNamespace(f.ClientSet, pod.Name, f.Namespace.Name)
} }

View File

@ -177,7 +177,7 @@ type NetworkingTestConfig struct {
// 1 pod per node running the netexecImage. // 1 pod per node running the netexecImage.
EndpointPods []*v1.Pod EndpointPods []*v1.Pod
f *framework.Framework f *framework.Framework
podClient *framework.PodClient podClient *e2etodopod.PodClient
// NodePortService is a Service with Type=NodePort spanning over all // NodePortService is a Service with Type=NodePort spanning over all
// endpointPods. // endpointPods.
NodePortService *v1.Service NodePortService *v1.Service
@ -359,7 +359,7 @@ func (config *NetworkingTestConfig) GetEndpointsFromContainer(protocol, containe
eps := sets.NewString() eps := sets.NewString()
for i := 0; i < tries; i++ { for i := 0; i < tries; i++ {
stdout, stderr, err := config.f.ExecShellInPodWithFullOutput(config.TestContainerPod.Name, cmd) stdout, stderr, err := e2etodopod.ExecShellInPodWithFullOutput(config.f, config.TestContainerPod.Name, cmd)
if err != nil { if err != nil {
// A failure to kubectl exec counts as a try, not a hard fail. // A failure to kubectl exec counts as a try, not a hard fail.
// Also note that we will keep failing for maxTries in tests where // Also note that we will keep failing for maxTries in tests where
@ -394,7 +394,7 @@ func (config *NetworkingTestConfig) GetResponseFromContainer(protocol, dialComma
ipPort := net.JoinHostPort(containerIP, strconv.Itoa(containerHTTPPort)) ipPort := net.JoinHostPort(containerIP, strconv.Itoa(containerHTTPPort))
cmd := makeCURLDialCommand(ipPort, dialCommand, protocol, targetIP, targetPort) cmd := makeCURLDialCommand(ipPort, dialCommand, protocol, targetIP, targetPort)
stdout, stderr, err := config.f.ExecShellInPodWithFullOutput(config.TestContainerPod.Name, cmd) stdout, stderr, err := e2etodopod.ExecShellInPodWithFullOutput(config.f, config.TestContainerPod.Name, cmd)
if err != nil { if err != nil {
return NetexecDialResponse{}, fmt.Errorf("failed to execute %q: %v, stdout: %q, stderr: %q", cmd, err, stdout, stderr) return NetexecDialResponse{}, fmt.Errorf("failed to execute %q: %v, stdout: %q, stderr: %q", cmd, err, stdout, stderr)
} }
@ -418,7 +418,7 @@ func (config *NetworkingTestConfig) GetHTTPCodeFromTestContainer(path, targetIP
targetIP, targetIP,
targetPort, targetPort,
path) path)
stdout, stderr, err := config.f.ExecShellInPodWithFullOutput(config.TestContainerPod.Name, cmd) stdout, stderr, err := e2etodopod.ExecShellInPodWithFullOutput(config.f, config.TestContainerPod.Name, cmd)
// We only care about the status code reported by curl, // We only care about the status code reported by curl,
// and want to return any other errors, such as cannot execute command in the Pod. // and want to return any other errors, such as cannot execute command in the Pod.
// If curl failed to connect to host, it would exit with code 7, which makes `ExecShellInPodWithFullOutput` // If curl failed to connect to host, it would exit with code 7, which makes `ExecShellInPodWithFullOutput`
@ -466,7 +466,7 @@ func (config *NetworkingTestConfig) DialFromNode(protocol, targetIP string, targ
filterCmd := fmt.Sprintf("%s | grep -v '^\\s*$'", cmd) filterCmd := fmt.Sprintf("%s | grep -v '^\\s*$'", cmd)
framework.Logf("Going to poll %v on port %v at least %v times, with a maximum of %v tries before failing", targetIP, targetPort, minTries, maxTries) framework.Logf("Going to poll %v on port %v at least %v times, with a maximum of %v tries before failing", targetIP, targetPort, minTries, maxTries)
for i := 0; i < maxTries; i++ { for i := 0; i < maxTries; i++ {
stdout, stderr, err := config.f.ExecShellInPodWithFullOutput(config.HostTestContainerPod.Name, filterCmd) stdout, stderr, err := e2etodopod.ExecShellInPodWithFullOutput(config.f, config.HostTestContainerPod.Name, filterCmd)
if err != nil || len(stderr) > 0 { if err != nil || len(stderr) > 0 {
// A failure to exec command counts as a try, not a hard fail. // A failure to exec command counts as a try, not a hard fail.
// Also note that we will keep failing for maxTries in tests where // Also note that we will keep failing for maxTries in tests where
@ -896,9 +896,9 @@ func (config *NetworkingTestConfig) createPod(pod *v1.Pod) *v1.Pod {
return config.getPodClient().Create(pod) return config.getPodClient().Create(pod)
} }
func (config *NetworkingTestConfig) getPodClient() *framework.PodClient { func (config *NetworkingTestConfig) getPodClient() *e2etodopod.PodClient {
if config.podClient == nil { if config.podClient == nil {
config.podClient = config.f.PodClient() config.podClient = e2etodopod.NewPodClient(config.f)
} }
return config.podClient return config.podClient
} }

View File

@ -26,6 +26,7 @@ import (
clientset "k8s.io/client-go/kubernetes" clientset "k8s.io/client-go/kubernetes"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
imageutils "k8s.io/kubernetes/test/utils/image" imageutils "k8s.io/kubernetes/test/utils/image"
) )
@ -47,7 +48,7 @@ func LoadAppArmorProfiles(nsName string, clientset clientset.Interface) {
// CreateAppArmorTestPod creates a pod that tests apparmor profile enforcement. The pod exits with // CreateAppArmorTestPod creates a pod that tests apparmor profile enforcement. The pod exits with
// an error code if the profile is incorrectly enforced. If runOnce is true the pod will exit after // an error code if the profile is incorrectly enforced. If runOnce is true the pod will exit after
// a single test, otherwise it will repeat the test every 1 second until failure. // a single test, otherwise it will repeat the test every 1 second until failure.
func CreateAppArmorTestPod(nsName string, clientset clientset.Interface, podClient *framework.PodClient, unconfined bool, runOnce bool) *v1.Pod { func CreateAppArmorTestPod(nsName string, clientset clientset.Interface, podClient *e2etodopod.PodClient, unconfined bool, runOnce bool) *v1.Pod {
profile := "localhost/" + appArmorProfilePrefix + nsName profile := "localhost/" + appArmorProfilePrefix + nsName
testCmd := fmt.Sprintf(` testCmd := fmt.Sprintf(`
if touch %[1]s; then if touch %[1]s; then

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package framework package pod
import ( import (
"bytes" "bytes"
@ -28,6 +28,7 @@ import (
"k8s.io/client-go/kubernetes/scheme" "k8s.io/client-go/kubernetes/scheme"
restclient "k8s.io/client-go/rest" restclient "k8s.io/client-go/rest"
"k8s.io/client-go/tools/remotecommand" "k8s.io/client-go/tools/remotecommand"
"k8s.io/kubernetes/test/e2e/framework"
"github.com/onsi/gomega" "github.com/onsi/gomega"
) )
@ -49,16 +50,16 @@ type ExecOptions struct {
// ExecWithOptions executes a command in the specified container, // ExecWithOptions executes a command in the specified container,
// returning stdout, stderr and error. `options` allowed for // returning stdout, stderr and error. `options` allowed for
// additional parameters to be passed. // additional parameters to be passed.
func (f *Framework) ExecWithOptions(options ExecOptions) (string, string, error) { func ExecWithOptions(f *framework.Framework, options ExecOptions) (string, string, error) {
if !options.Quiet { if !options.Quiet {
Logf("ExecWithOptions %+v", options) framework.Logf("ExecWithOptions %+v", options)
} }
config, err := LoadConfig() config, err := framework.LoadConfig()
ExpectNoError(err, "failed to load restclient config") framework.ExpectNoError(err, "failed to load restclient config")
const tty = false const tty = false
Logf("ExecWithOptions: Clientset creation") framework.Logf("ExecWithOptions: Clientset creation")
req := f.ClientSet.CoreV1().RESTClient().Post(). req := f.ClientSet.CoreV1().RESTClient().Post().
Resource("pods"). Resource("pods").
Name(options.PodName). Name(options.PodName).
@ -75,7 +76,7 @@ func (f *Framework) ExecWithOptions(options ExecOptions) (string, string, error)
}, scheme.ParameterCodec) }, scheme.ParameterCodec)
var stdout, stderr bytes.Buffer var stdout, stderr bytes.Buffer
Logf("ExecWithOptions: execute(POST %s)", req.URL()) framework.Logf("ExecWithOptions: execute(POST %s)", req.URL())
err = execute("POST", req.URL(), config, options.Stdin, &stdout, &stderr, tty) err = execute("POST", req.URL(), config, options.Stdin, &stdout, &stderr, tty)
if options.PreserveWhitespace { if options.PreserveWhitespace {
return stdout.String(), stderr.String(), err return stdout.String(), stderr.String(), err
@ -85,8 +86,8 @@ func (f *Framework) ExecWithOptions(options ExecOptions) (string, string, error)
// ExecCommandInContainerWithFullOutput executes a command in the // ExecCommandInContainerWithFullOutput executes a command in the
// specified container and return stdout, stderr and error // specified container and return stdout, stderr and error
func (f *Framework) ExecCommandInContainerWithFullOutput(podName, containerName string, cmd ...string) (string, string, error) { func ExecCommandInContainerWithFullOutput(f *framework.Framework, podName, containerName string, cmd ...string) (string, string, error) {
return f.ExecWithOptions(ExecOptions{ return ExecWithOptions(f, ExecOptions{
Command: cmd, Command: cmd,
Namespace: f.Namespace.Name, Namespace: f.Namespace.Name,
PodName: podName, PodName: podName,
@ -99,42 +100,42 @@ func (f *Framework) ExecCommandInContainerWithFullOutput(podName, containerName
} }
// ExecCommandInContainer executes a command in the specified container. // ExecCommandInContainer executes a command in the specified container.
func (f *Framework) ExecCommandInContainer(podName, containerName string, cmd ...string) string { func ExecCommandInContainer(f *framework.Framework, podName, containerName string, cmd ...string) string {
stdout, stderr, err := f.ExecCommandInContainerWithFullOutput(podName, containerName, cmd...) stdout, stderr, err := ExecCommandInContainerWithFullOutput(f, podName, containerName, cmd...)
Logf("Exec stderr: %q", stderr) framework.Logf("Exec stderr: %q", stderr)
ExpectNoError(err, framework.ExpectNoError(err,
"failed to execute command in pod %v, container %v: %v", "failed to execute command in pod %v, container %v: %v",
podName, containerName, err) podName, containerName, err)
return stdout return stdout
} }
// ExecShellInContainer executes the specified command on the pod's container. // ExecShellInContainer executes the specified command on the pod's container.
func (f *Framework) ExecShellInContainer(podName, containerName string, cmd string) string { func ExecShellInContainer(f *framework.Framework, podName, containerName string, cmd string) string {
return f.ExecCommandInContainer(podName, containerName, "/bin/sh", "-c", cmd) return ExecCommandInContainer(f, podName, containerName, "/bin/sh", "-c", cmd)
} }
func (f *Framework) execCommandInPod(podName string, cmd ...string) string { func execCommandInPod(f *framework.Framework, podName string, cmd ...string) string {
pod, err := f.PodClient().Get(context.TODO(), podName, metav1.GetOptions{}) pod, err := NewPodClient(f).Get(context.TODO(), podName, metav1.GetOptions{})
ExpectNoError(err, "failed to get pod %v", podName) framework.ExpectNoError(err, "failed to get pod %v", podName)
gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty()) gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty())
return f.ExecCommandInContainer(podName, pod.Spec.Containers[0].Name, cmd...) return ExecCommandInContainer(f, podName, pod.Spec.Containers[0].Name, cmd...)
} }
func (f *Framework) execCommandInPodWithFullOutput(podName string, cmd ...string) (string, string, error) { func execCommandInPodWithFullOutput(f *framework.Framework, podName string, cmd ...string) (string, string, error) {
pod, err := f.PodClient().Get(context.TODO(), podName, metav1.GetOptions{}) pod, err := NewPodClient(f).Get(context.TODO(), podName, metav1.GetOptions{})
ExpectNoError(err, "failed to get pod %v", podName) framework.ExpectNoError(err, "failed to get pod %v", podName)
gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty()) gomega.Expect(pod.Spec.Containers).NotTo(gomega.BeEmpty())
return f.ExecCommandInContainerWithFullOutput(podName, pod.Spec.Containers[0].Name, cmd...) return ExecCommandInContainerWithFullOutput(f, podName, pod.Spec.Containers[0].Name, cmd...)
} }
// ExecShellInPod executes the specified command on the pod. // ExecShellInPod executes the specified command on the pod.
func (f *Framework) ExecShellInPod(podName string, cmd string) string { func ExecShellInPod(f *framework.Framework, podName string, cmd string) string {
return f.execCommandInPod(podName, "/bin/sh", "-c", cmd) return execCommandInPod(f, podName, "/bin/sh", "-c", cmd)
} }
// ExecShellInPodWithFullOutput executes the specified command on the Pod and returns stdout, stderr and error. // ExecShellInPodWithFullOutput executes the specified command on the Pod and returns stdout, stderr and error.
func (f *Framework) ExecShellInPodWithFullOutput(podName string, cmd string) (string, string, error) { func ExecShellInPodWithFullOutput(f *framework.Framework, podName string, cmd string) (string, string, error) {
return f.execCommandInPodWithFullOutput(podName, "/bin/sh", "-c", cmd) return execCommandInPodWithFullOutput(f, podName, "/bin/sh", "-c", cmd)
} }
func execute(method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error { func execute(method string, url *url.URL, config *restclient.Config, stdin io.Reader, stdout, stderr io.Writer, tty bool) error {

View File

@ -151,12 +151,12 @@ func MatchContainerOutput(
if ns == "" { if ns == "" {
ns = f.Namespace.Name ns = f.Namespace.Name
} }
podClient := f.PodClientNS(ns) podClient := PodClientNS(f, ns)
createdPod := podClient.Create(pod) createdPod := podClient.Create(pod)
defer func() { defer func() {
ginkgo.By("delete the pod") ginkgo.By("delete the pod")
podClient.DeleteSync(createdPod.Name, metav1.DeleteOptions{}, framework.DefaultPodDeletionTimeout) podClient.DeleteSync(createdPod.Name, metav1.DeleteOptions{}, DefaultPodDeletionTimeout)
}() }()
// Wait for client pod to complete. // Wait for client pod to complete.

View File

@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package framework package pod
import ( import (
"context" "context"
@ -39,8 +39,8 @@ import (
"github.com/onsi/ginkgo/v2" "github.com/onsi/ginkgo/v2"
"github.com/onsi/gomega" "github.com/onsi/gomega"
// TODO: Remove the following imports (ref: https://github.com/kubernetes/kubernetes/issues/81245)
"k8s.io/kubernetes/pkg/kubelet/util/format" "k8s.io/kubernetes/pkg/kubelet/util/format"
"k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
) )
@ -66,10 +66,10 @@ const (
// node e2e test. // node e2e test.
var ImagePrePullList sets.String var ImagePrePullList sets.String
// PodClient is a convenience method for getting a pod client interface in the framework's namespace, // NewPodClient is a convenience method for getting a pod client interface in the framework's namespace,
// possibly applying test-suite specific transformations to the pod spec, e.g. for // possibly applying test-suite specific transformations to the pod spec, e.g. for
// node e2e pod scheduling. // node e2e pod scheduling.
func (f *Framework) PodClient() *PodClient { func NewPodClient(f *framework.Framework) *PodClient {
return &PodClient{ return &PodClient{
f: f, f: f,
PodInterface: f.ClientSet.CoreV1().Pods(f.Namespace.Name), PodInterface: f.ClientSet.CoreV1().Pods(f.Namespace.Name),
@ -79,7 +79,7 @@ func (f *Framework) PodClient() *PodClient {
// PodClientNS is a convenience method for getting a pod client interface in an alternative namespace, // PodClientNS is a convenience method for getting a pod client interface in an alternative namespace,
// possibly applying test-suite specific transformations to the pod spec, e.g. for // possibly applying test-suite specific transformations to the pod spec, e.g. for
// node e2e pod scheduling. // node e2e pod scheduling.
func (f *Framework) PodClientNS(namespace string) *PodClient { func PodClientNS(f *framework.Framework, namespace string) *PodClient {
return &PodClient{ return &PodClient{
f: f, f: f,
PodInterface: f.ClientSet.CoreV1().Pods(namespace), PodInterface: f.ClientSet.CoreV1().Pods(namespace),
@ -88,7 +88,7 @@ func (f *Framework) PodClientNS(namespace string) *PodClient {
// PodClient is a struct for pod client. // PodClient is a struct for pod client.
type PodClient struct { type PodClient struct {
f *Framework f *framework.Framework
v1core.PodInterface v1core.PodInterface
} }
@ -96,7 +96,7 @@ type PodClient struct {
func (c *PodClient) Create(pod *v1.Pod) *v1.Pod { func (c *PodClient) Create(pod *v1.Pod) *v1.Pod {
c.mungeSpec(pod) c.mungeSpec(pod)
p, err := c.PodInterface.Create(context.TODO(), pod, metav1.CreateOptions{}) p, err := c.PodInterface.Create(context.TODO(), pod, metav1.CreateOptions{})
ExpectNoError(err, "Error creating Pod") framework.ExpectNoError(err, "Error creating Pod")
return p return p
} }
@ -104,10 +104,10 @@ func (c *PodClient) Create(pod *v1.Pod) *v1.Pod {
func (c *PodClient) CreateSync(pod *v1.Pod) *v1.Pod { func (c *PodClient) CreateSync(pod *v1.Pod) *v1.Pod {
namespace := c.f.Namespace.Name namespace := c.f.Namespace.Name
p := c.Create(pod) p := c.Create(pod)
ExpectNoError(e2epod.WaitTimeoutForPodReadyInNamespace(c.f.ClientSet, p.Name, namespace, PodStartTimeout)) framework.ExpectNoError(e2epod.WaitTimeoutForPodReadyInNamespace(c.f.ClientSet, p.Name, namespace, framework.PodStartTimeout))
// Get the newest pod after it becomes running and ready, some status may change after pod created, such as pod ip. // Get the newest pod after it becomes running and ready, some status may change after pod created, such as pod ip.
p, err := c.Get(context.TODO(), p.Name, metav1.GetOptions{}) p, err := c.Get(context.TODO(), p.Name, metav1.GetOptions{})
ExpectNoError(err) framework.ExpectNoError(err)
return p return p
} }
@ -131,7 +131,7 @@ func (c *PodClient) CreateBatch(pods []*v1.Pod) []*v1.Pod {
// there is any other apierrors. name is the pod name, updateFn is the function updating the // there is any other apierrors. name is the pod name, updateFn is the function updating the
// pod object. // pod object.
func (c *PodClient) Update(name string, updateFn func(pod *v1.Pod)) { func (c *PodClient) Update(name string, updateFn func(pod *v1.Pod)) {
ExpectNoError(wait.Poll(time.Millisecond*500, time.Second*30, func() (bool, error) { framework.ExpectNoError(wait.Poll(time.Millisecond*500, time.Second*30, func() (bool, error) {
pod, err := c.PodInterface.Get(context.TODO(), name, metav1.GetOptions{}) pod, err := c.PodInterface.Get(context.TODO(), name, metav1.GetOptions{})
if err != nil { if err != nil {
return false, fmt.Errorf("failed to get pod %q: %v", name, err) return false, fmt.Errorf("failed to get pod %q: %v", name, err)
@ -139,11 +139,11 @@ func (c *PodClient) Update(name string, updateFn func(pod *v1.Pod)) {
updateFn(pod) updateFn(pod)
_, err = c.PodInterface.Update(context.TODO(), pod, metav1.UpdateOptions{}) _, err = c.PodInterface.Update(context.TODO(), pod, metav1.UpdateOptions{})
if err == nil { if err == nil {
Logf("Successfully updated pod %q", name) framework.Logf("Successfully updated pod %q", name)
return true, nil return true, nil
} }
if apierrors.IsConflict(err) { if apierrors.IsConflict(err) {
Logf("Conflicting update to pod %q, re-get and re-update: %v", name, err) framework.Logf("Conflicting update to pod %q, re-get and re-update: %v", name, err)
return false, nil return false, nil
} }
return false, fmt.Errorf("failed to update pod %q: %v", name, err) return false, fmt.Errorf("failed to update pod %q: %v", name, err)
@ -155,22 +155,22 @@ func (c *PodClient) AddEphemeralContainerSync(pod *v1.Pod, ec *v1.EphemeralConta
namespace := c.f.Namespace.Name namespace := c.f.Namespace.Name
podJS, err := json.Marshal(pod) podJS, err := json.Marshal(pod)
ExpectNoError(err, "error creating JSON for pod %q", format.Pod(pod)) framework.ExpectNoError(err, "error creating JSON for pod %q", format.Pod(pod))
ecPod := pod.DeepCopy() ecPod := pod.DeepCopy()
ecPod.Spec.EphemeralContainers = append(ecPod.Spec.EphemeralContainers, *ec) ecPod.Spec.EphemeralContainers = append(ecPod.Spec.EphemeralContainers, *ec)
ecJS, err := json.Marshal(ecPod) ecJS, err := json.Marshal(ecPod)
ExpectNoError(err, "error creating JSON for pod with ephemeral container %q", format.Pod(pod)) framework.ExpectNoError(err, "error creating JSON for pod with ephemeral container %q", format.Pod(pod))
patch, err := strategicpatch.CreateTwoWayMergePatch(podJS, ecJS, pod) patch, err := strategicpatch.CreateTwoWayMergePatch(podJS, ecJS, pod)
ExpectNoError(err, "error creating patch to add ephemeral container %q", format.Pod(pod)) framework.ExpectNoError(err, "error creating patch to add ephemeral container %q", format.Pod(pod))
// Clients may optimistically attempt to add an ephemeral container to determine whether the EphemeralContainers feature is enabled. // Clients may optimistically attempt to add an ephemeral container to determine whether the EphemeralContainers feature is enabled.
if _, err := c.Patch(context.TODO(), pod.Name, types.StrategicMergePatchType, patch, metav1.PatchOptions{}, "ephemeralcontainers"); err != nil { if _, err := c.Patch(context.TODO(), pod.Name, types.StrategicMergePatchType, patch, metav1.PatchOptions{}, "ephemeralcontainers"); err != nil {
return err return err
} }
ExpectNoError(e2epod.WaitForContainerRunning(c.f.ClientSet, namespace, pod.Name, ec.Name, timeout)) framework.ExpectNoError(e2epod.WaitForContainerRunning(c.f.ClientSet, namespace, pod.Name, ec.Name, timeout))
return nil return nil
} }
@ -180,7 +180,7 @@ func (c *PodClient) DeleteSync(name string, options metav1.DeleteOptions, timeou
namespace := c.f.Namespace.Name namespace := c.f.Namespace.Name
err := c.Delete(context.TODO(), name, options) err := c.Delete(context.TODO(), name, options)
if err != nil && !apierrors.IsNotFound(err) { if err != nil && !apierrors.IsNotFound(err) {
Failf("Failed to delete pod %q: %v", name, err) framework.Failf("Failed to delete pod %q: %v", name, err)
} }
gomega.Expect(e2epod.WaitForPodToDisappear(c.f.ClientSet, namespace, name, labels.Everything(), gomega.Expect(e2epod.WaitForPodToDisappear(c.f.ClientSet, namespace, name, labels.Everything(),
2*time.Second, timeout)).To(gomega.Succeed(), "wait for pod %q to disappear", name) 2*time.Second, timeout)).To(gomega.Succeed(), "wait for pod %q to disappear", name)
@ -188,19 +188,19 @@ func (c *PodClient) DeleteSync(name string, options metav1.DeleteOptions, timeou
// mungeSpec apply test-suite specific transformations to the pod spec. // mungeSpec apply test-suite specific transformations to the pod spec.
func (c *PodClient) mungeSpec(pod *v1.Pod) { func (c *PodClient) mungeSpec(pod *v1.Pod) {
if !TestContext.NodeE2E { if !framework.TestContext.NodeE2E {
return return
} }
gomega.Expect(pod.Spec.NodeName).To(gomega.Or(gomega.BeZero(), gomega.Equal(TestContext.NodeName)), "Test misconfigured") gomega.Expect(pod.Spec.NodeName).To(gomega.Or(gomega.BeZero(), gomega.Equal(framework.TestContext.NodeName)), "Test misconfigured")
pod.Spec.NodeName = TestContext.NodeName pod.Spec.NodeName = framework.TestContext.NodeName
// Node e2e does not support the default DNSClusterFirst policy. Set // Node e2e does not support the default DNSClusterFirst policy. Set
// the policy to DNSDefault, which is configured per node. // the policy to DNSDefault, which is configured per node.
pod.Spec.DNSPolicy = v1.DNSDefault pod.Spec.DNSPolicy = v1.DNSDefault
// PrepullImages only works for node e2e now. For cluster e2e, image prepull is not enforced, // PrepullImages only works for node e2e now. For cluster e2e, image prepull is not enforced,
// we should not munge ImagePullPolicy for cluster e2e pods. // we should not munge ImagePullPolicy for cluster e2e pods.
if !TestContext.PrepullImages { if !framework.TestContext.PrepullImages {
return return
} }
// If prepull is enabled, munge the container spec to make sure the images are not pulled // If prepull is enabled, munge the container spec to make sure the images are not pulled
@ -260,7 +260,7 @@ func (c *PodClient) WaitForFinish(name string, timeout time.Duration) {
// WaitForErrorEventOrSuccess waits for pod to succeed or an error event for that pod. // WaitForErrorEventOrSuccess waits for pod to succeed or an error event for that pod.
func (c *PodClient) WaitForErrorEventOrSuccess(pod *v1.Pod) (*v1.Event, error) { func (c *PodClient) WaitForErrorEventOrSuccess(pod *v1.Pod) (*v1.Event, error) {
var ev *v1.Event var ev *v1.Event
err := wait.Poll(Poll, PodStartTimeout, func() (bool, error) { err := wait.Poll(Poll, framework.PodStartTimeout, func() (bool, error) {
evnts, err := c.f.ClientSet.CoreV1().Events(pod.Namespace).Search(scheme.Scheme, pod) evnts, err := c.f.ClientSet.CoreV1().Events(pod.Namespace).Search(scheme.Scheme, pod)
if err != nil { if err != nil {
return false, fmt.Errorf("error in listing events: %s", err) return false, fmt.Errorf("error in listing events: %s", err)
@ -301,6 +301,6 @@ func (c *PodClient) MatchContainerOutput(name string, containerName string, expe
// PodIsReady returns true if the specified pod is ready. Otherwise false. // PodIsReady returns true if the specified pod is ready. Otherwise false.
func (c *PodClient) PodIsReady(name string) bool { func (c *PodClient) PodIsReady(name string) bool {
pod, err := c.Get(context.TODO(), name, metav1.GetOptions{}) pod, err := c.Get(context.TODO(), name, metav1.GetOptions{})
ExpectNoError(err) framework.ExpectNoError(err)
return podutils.IsPodReady(pod) return podutils.IsPodReady(pod)
} }

View File

@ -551,7 +551,7 @@ func testVolumeClient(f *framework.Framework, config TestConfig, fsGroup *int64,
} }
ec.Resources = v1.ResourceRequirements{} ec.Resources = v1.ResourceRequirements{}
ec.Name = "volume-ephemeral-container" ec.Name = "volume-ephemeral-container"
err = f.PodClient().AddEphemeralContainerSync(clientPod, ec, timeouts.PodStart) err = e2etodopod.NewPodClient(f).AddEphemeralContainerSync(clientPod, ec, timeouts.PodStart)
// The API server will return NotFound for the subresource when the feature is disabled // The API server will return NotFound for the subresource when the feature is disabled
framework.ExpectNoError(err, "failed to add ephemeral container for re-test") framework.ExpectNoError(err, "failed to add ephemeral container for re-test")
testVolumeContent(f, clientPod, ec.Name, fsGroup, fsType, tests) testVolumeContent(f, clientPod, ec.Name, fsGroup, fsType, tests)
@ -650,7 +650,7 @@ func CheckVolumeModeOfPath(f *framework.Framework, pod *v1.Pod, volMode v1.Persi
// TODO: put this under e2epod once https://github.com/kubernetes/kubernetes/issues/81245 // TODO: put this under e2epod once https://github.com/kubernetes/kubernetes/issues/81245
// is resolved. Otherwise there will be dependency issue. // is resolved. Otherwise there will be dependency issue.
func PodExec(f *framework.Framework, pod *v1.Pod, shExec string) (string, string, error) { func PodExec(f *framework.Framework, pod *v1.Pod, shExec string) (string, string, error) {
return f.ExecCommandInContainerWithFullOutput(pod.Name, pod.Spec.Containers[0].Name, "/bin/sh", "-c", shExec) return e2etodopod.ExecCommandInContainerWithFullOutput(f, pod.Name, pod.Spec.Containers[0].Name, "/bin/sh", "-c", shExec)
} }
// VerifyExecInPodSucceed verifies shell cmd in target pod succeed // VerifyExecInPodSucceed verifies shell cmd in target pod succeed

View File

@ -25,6 +25,7 @@ import (
"k8s.io/client-go/util/exec" "k8s.io/client-go/util/exec"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2epod "k8s.io/kubernetes/test/e2e/framework/pod" e2epod "k8s.io/kubernetes/test/e2e/framework/pod"
e2etodopod "k8s.io/kubernetes/test/e2e/framework/todo/pod"
) )
// Result holds the execution result of remote execution command. // Result holds the execution result of remote execution command.
@ -149,7 +150,7 @@ func (h *hostExecutor) exec(cmd string, node *v1.Node) (Result, error) {
} }
containerName := pod.Spec.Containers[0].Name containerName := pod.Spec.Containers[0].Name
var err error var err error
result.Stdout, result.Stderr, err = h.Framework.ExecWithOptions(framework.ExecOptions{ result.Stdout, result.Stderr, err = e2etodopod.ExecWithOptions(h.Framework, e2etodopod.ExecOptions{
Command: args, Command: args,
Namespace: pod.Namespace, Namespace: pod.Namespace,
PodName: pod.Name, PodName: pod.Name,