Move NewAgnhostPod() to e2e/network

because the function is called in e2e/network tests only.
This commit is contained in:
Kenichi Omichi 2020-03-23 23:42:58 +00:00
parent 07a7c4902e
commit 5c77461733
6 changed files with 33 additions and 28 deletions

View File

@ -155,9 +155,6 @@ var (
// BusyBoxImage is the image URI of BusyBox. // BusyBoxImage is the image URI of BusyBox.
BusyBoxImage = imageutils.GetE2EImage(imageutils.BusyBox) BusyBoxImage = imageutils.GetE2EImage(imageutils.BusyBox)
// AgnHostImage is the image URI of AgnHost
AgnHostImage = imageutils.GetE2EImage(imageutils.Agnhost)
// ProvidersWithSSH are those providers where each node is accessible with SSH // ProvidersWithSSH are those providers where each node is accessible with SSH
ProvidersWithSSH = []string{"gce", "gke", "aws", "local"} ProvidersWithSSH = []string{"gce", "gke", "aws", "local"}
@ -1583,25 +1580,6 @@ func DescribeIng(ns string) {
Logf(desc) Logf(desc)
} }
// NewAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands
// that behave the same, no matter the underlying OS.
func (f *Framework) NewAgnhostPod(name string, args ...string) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "agnhost",
Image: AgnHostImage,
Args: args,
},
},
},
}
}
// CreateEmptyFileOnPod creates empty file at given path on the pod. // CreateEmptyFileOnPod creates empty file at given path on the pod.
// TODO(alejandrox1): move to subpkg pod once kubectl methods have been refactored. // TODO(alejandrox1): move to subpkg pod once kubectl methods have been refactored.
func CreateEmptyFileOnPod(namespace string, podName string, filePath string) error { func CreateEmptyFileOnPod(namespace string, podName string, filePath string) error {

View File

@ -409,7 +409,7 @@ var _ = SIGDescribe("DNS", func() {
ginkgo.By("Creating a pod with dnsPolicy=None and customized dnsConfig...") ginkgo.By("Creating a pod with dnsPolicy=None and customized dnsConfig...")
testServerIP := "1.1.1.1" testServerIP := "1.1.1.1"
testSearchPath := "resolv.conf.local" testSearchPath := "resolv.conf.local"
testAgnhostPod := f.NewAgnhostPod(f.Namespace.Name, "pause") testAgnhostPod := newAgnhostPod(f.Namespace.Name, "pause")
testAgnhostPod.Spec.DNSPolicy = v1.DNSNone testAgnhostPod.Spec.DNSPolicy = v1.DNSNone
testAgnhostPod.Spec.DNSConfig = &v1.PodDNSConfig{ testAgnhostPod.Spec.DNSConfig = &v1.PodDNSConfig{
Nameservers: []string{testServerIP}, Nameservers: []string{testServerIP},

View File

@ -146,7 +146,7 @@ var _ = SIGDescribe("Firewall rule", func() {
podName := fmt.Sprintf("netexec%v", i) podName := fmt.Sprintf("netexec%v", i)
framework.Logf("Creating netexec pod %q on node %v in namespace %q", podName, nodeName, ns) framework.Logf("Creating netexec pod %q on node %v in namespace %q", podName, nodeName, ns)
pod := f.NewAgnhostPod(podName, pod := newAgnhostPod(podName,
"netexec", "netexec",
fmt.Sprintf("--http-port=%d", firewallTestHTTPPort), fmt.Sprintf("--http-port=%d", firewallTestHTTPPort),
fmt.Sprintf("--udp-port=%d", firewallTestUDPPort)) fmt.Sprintf("--udp-port=%d", firewallTestUDPPort))

View File

@ -60,7 +60,7 @@ func checkConnectivityToHost(f *framework.Framework, nodeName, podName, host str
Containers: []v1.Container{ Containers: []v1.Container{
{ {
Name: contName, Name: contName,
Image: framework.AgnHostImage, Image: agnHostImage,
Command: command, Command: command,
}, },
}, },

View File

@ -902,7 +902,7 @@ var _ = SIGDescribe("Services", func() {
ginkgo.By("Creating a webserver pod to be part of the TCP service which echoes back source ip") ginkgo.By("Creating a webserver pod to be part of the TCP service which echoes back source ip")
serverPodName := "echo-sourceip" serverPodName := "echo-sourceip"
pod := f.NewAgnhostPod(serverPodName, "netexec", "--http-port", strconv.Itoa(servicePort)) pod := newAgnhostPod(serverPodName, "netexec", "--http-port", strconv.Itoa(servicePort))
pod.Labels = jig.Labels pod.Labels = jig.Labels
_, err = cs.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{}) _, err = cs.CoreV1().Pods(ns).Create(context.TODO(), pod, metav1.CreateOptions{})
framework.ExpectNoError(err) framework.ExpectNoError(err)
@ -960,7 +960,7 @@ var _ = SIGDescribe("Services", func() {
ginkgo.By("creating a client/server pod") ginkgo.By("creating a client/server pod")
serverPodName := "hairpin" serverPodName := "hairpin"
podTemplate := f.NewAgnhostPod(serverPodName, "netexec", "--http-port", strconv.Itoa(servicePort)) podTemplate := newAgnhostPod(serverPodName, "netexec", "--http-port", strconv.Itoa(servicePort))
podTemplate.Labels = jig.Labels podTemplate.Labels = jig.Labels
pod, err := cs.CoreV1().Pods(ns).Create(context.TODO(), podTemplate, metav1.CreateOptions{}) pod, err := cs.CoreV1().Pods(ns).Create(context.TODO(), podTemplate, metav1.CreateOptions{})
framework.ExpectNoError(err) framework.ExpectNoError(err)
@ -3334,7 +3334,7 @@ func proxyMode(f *framework.Framework) (string, error) {
Containers: []v1.Container{ Containers: []v1.Container{
{ {
Name: "detector", Name: "detector",
Image: framework.AgnHostImage, Image: agnHostImage,
Args: []string{"pause"}, Args: []string{"pause"},
}, },
}, },

View File

@ -21,9 +21,17 @@ import (
"fmt" "fmt"
"time" "time"
"k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/util/wait" "k8s.io/apimachinery/pkg/util/wait"
"k8s.io/kubernetes/test/e2e/framework" "k8s.io/kubernetes/test/e2e/framework"
e2enetwork "k8s.io/kubernetes/test/e2e/framework/network" e2enetwork "k8s.io/kubernetes/test/e2e/framework/network"
imageutils "k8s.io/kubernetes/test/utils/image"
)
var (
// agnHostImage is the image URI of AgnHost
agnHostImage = imageutils.GetE2EImage(imageutils.Agnhost)
) )
// GetHTTPContent returns the content of the given url by HTTP. // GetHTTPContent returns the content of the given url by HTTP.
@ -49,3 +57,22 @@ func DescribeSvc(ns string) {
ns, "describe", "svc", fmt.Sprintf("--namespace=%v", ns)) ns, "describe", "svc", fmt.Sprintf("--namespace=%v", ns))
framework.Logf(desc) framework.Logf(desc)
} }
// newAgnhostPod returns a pod that uses the agnhost image. The image's binary supports various subcommands
// that behave the same, no matter the underlying OS.
func newAgnhostPod(name string, args ...string) *v1.Pod {
return &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Spec: v1.PodSpec{
Containers: []v1.Container{
{
Name: "agnhost",
Image: agnHostImage,
Args: args,
},
},
},
}
}