mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-27 21:47:07 +00:00
Merge pull request #81291 from danwinship/service-test-cleanup-1
Inline/simplify two used-only-once service test helper functions
This commit is contained in:
commit
61af419d38
@ -879,34 +879,6 @@ func (j *TestJig) CheckServiceReachability(namespace string, svc *v1.Service, po
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// LaunchNetexecPodOnNode launches a netexec pod on the given node.
|
|
||||||
func (j *TestJig) LaunchNetexecPodOnNode(f *framework.Framework, nodeName, podName string, httpPort, udpPort int32, hostNetwork bool) {
|
|
||||||
e2elog.Logf("Creating netexec pod %q on node %v in namespace %q", podName, nodeName, f.Namespace.Name)
|
|
||||||
pod := newNetexecPodSpec(podName, httpPort, udpPort, hostNetwork)
|
|
||||||
pod.Spec.NodeName = nodeName
|
|
||||||
pod.ObjectMeta.Labels = j.Labels
|
|
||||||
podClient := f.ClientSet.CoreV1().Pods(f.Namespace.Name)
|
|
||||||
_, err := podClient.Create(pod)
|
|
||||||
framework.ExpectNoError(err)
|
|
||||||
framework.ExpectNoError(f.WaitForPodRunning(podName))
|
|
||||||
e2elog.Logf("Netexec pod %q in namespace %q running", pod.Name, f.Namespace.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// LaunchEchoserverPodOnNode launches a pod serving http on port 8080 to act
|
|
||||||
// as the target for source IP preservation test. The client's source ip would
|
|
||||||
// be echoed back by the web server.
|
|
||||||
func (j *TestJig) LaunchEchoserverPodOnNode(f *framework.Framework, nodeName, podName string) {
|
|
||||||
e2elog.Logf("Creating echo server pod %q in namespace %q", podName, f.Namespace.Name)
|
|
||||||
pod := newEchoServerPodSpec(podName)
|
|
||||||
pod.Spec.NodeName = nodeName
|
|
||||||
pod.ObjectMeta.Labels = j.Labels
|
|
||||||
podClient := f.ClientSet.CoreV1().Pods(f.Namespace.Name)
|
|
||||||
_, err := podClient.Create(pod)
|
|
||||||
framework.ExpectNoError(err)
|
|
||||||
framework.ExpectNoError(f.WaitForPodRunning(podName))
|
|
||||||
e2elog.Logf("Echo server pod %q in namespace %q running", pod.Name, f.Namespace.Name)
|
|
||||||
}
|
|
||||||
|
|
||||||
// TestReachableHTTP tests that the given host serves HTTP on the given port.
|
// TestReachableHTTP tests that the given host serves HTTP on the given port.
|
||||||
func (j *TestJig) TestReachableHTTP(host string, port int, timeout time.Duration) {
|
func (j *TestJig) TestReachableHTTP(host string, port int, timeout time.Duration) {
|
||||||
j.TestReachableHTTPWithRetriableErrorCodes(host, port, []int{}, timeout)
|
j.TestReachableHTTPWithRetriableErrorCodes(host, port, []int{}, timeout)
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
restclient "k8s.io/client-go/rest"
|
restclient "k8s.io/client-go/rest"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
e2elog "k8s.io/kubernetes/test/e2e/framework/log"
|
||||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// GetServicesProxyRequest returns a request for a service proxy.
|
// GetServicesProxyRequest returns a request for a service proxy.
|
||||||
@ -110,62 +109,6 @@ func DescribeSvc(ns string) {
|
|||||||
e2elog.Logf(desc)
|
e2elog.Logf(desc)
|
||||||
}
|
}
|
||||||
|
|
||||||
// newNetexecPodSpec returns the pod spec of netexec pod
|
|
||||||
func newNetexecPodSpec(podName string, httpPort, udpPort int32, hostNetwork bool) *v1.Pod {
|
|
||||||
pod := &v1.Pod{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: podName,
|
|
||||||
},
|
|
||||||
Spec: v1.PodSpec{
|
|
||||||
Containers: []v1.Container{
|
|
||||||
{
|
|
||||||
Name: "netexec",
|
|
||||||
Image: framework.NetexecImageName,
|
|
||||||
Args: []string{
|
|
||||||
"netexec",
|
|
||||||
fmt.Sprintf("--http-port=%d", httpPort),
|
|
||||||
fmt.Sprintf("--udp-port=%d", udpPort),
|
|
||||||
},
|
|
||||||
Ports: []v1.ContainerPort{
|
|
||||||
{
|
|
||||||
Name: "http",
|
|
||||||
ContainerPort: httpPort,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
Name: "udp",
|
|
||||||
ContainerPort: udpPort,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
HostNetwork: hostNetwork,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return pod
|
|
||||||
}
|
|
||||||
|
|
||||||
// newEchoServerPodSpec returns the pod spec of echo server pod
|
|
||||||
func newEchoServerPodSpec(podName string) *v1.Pod {
|
|
||||||
port := 8080
|
|
||||||
pod := &v1.Pod{
|
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
|
||||||
Name: podName,
|
|
||||||
},
|
|
||||||
Spec: v1.PodSpec{
|
|
||||||
Containers: []v1.Container{
|
|
||||||
{
|
|
||||||
Name: "echoserver",
|
|
||||||
Image: imageutils.GetE2EImage(imageutils.Agnhost),
|
|
||||||
Args: []string{"netexec", fmt.Sprintf("--http-port=%d", port)},
|
|
||||||
Ports: []v1.ContainerPort{{ContainerPort: int32(port)}},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
RestartPolicy: v1.RestartPolicyNever,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
return pod
|
|
||||||
}
|
|
||||||
|
|
||||||
// GetServiceLoadBalancerCreationTimeout returns a timeout value for creating a load balancer of a service.
|
// GetServiceLoadBalancerCreationTimeout returns a timeout value for creating a load balancer of a service.
|
||||||
func GetServiceLoadBalancerCreationTimeout(cs clientset.Interface) time.Duration {
|
func GetServiceLoadBalancerCreationTimeout(cs clientset.Interface) time.Duration {
|
||||||
if nodes := framework.GetReadySchedulableNodesOrDie(cs); len(nodes.Items) > LargeClusterMinNodesNumber {
|
if nodes := framework.GetReadySchedulableNodesOrDie(cs); len(nodes.Items) > LargeClusterMinNodesNumber {
|
||||||
|
@ -135,7 +135,20 @@ var _ = SIGDescribe("Firewall rule", func() {
|
|||||||
ginkgo.By(fmt.Sprintf("Creating netexec pods on at most %v nodes", e2eservice.MaxNodesForEndpointsTests))
|
ginkgo.By(fmt.Sprintf("Creating netexec pods on at most %v nodes", e2eservice.MaxNodesForEndpointsTests))
|
||||||
for i, nodeName := range nodesNames {
|
for i, nodeName := range nodesNames {
|
||||||
podName := fmt.Sprintf("netexec%v", i)
|
podName := fmt.Sprintf("netexec%v", i)
|
||||||
jig.LaunchNetexecPodOnNode(f, nodeName, podName, firewallTestHTTPPort, firewallTestUDPPort, true)
|
|
||||||
|
e2elog.Logf("Creating netexec pod %q on node %v in namespace %q", podName, nodeName, ns)
|
||||||
|
pod := f.NewAgnhostPod(podName,
|
||||||
|
"netexec",
|
||||||
|
fmt.Sprintf("--http-port=%d", firewallTestHTTPPort),
|
||||||
|
fmt.Sprintf("--udp-port=%d", firewallTestUDPPort))
|
||||||
|
pod.ObjectMeta.Labels = jig.Labels
|
||||||
|
pod.Spec.NodeName = nodeName
|
||||||
|
pod.Spec.HostNetwork = true
|
||||||
|
_, err := cs.CoreV1().Pods(ns).Create(pod)
|
||||||
|
framework.ExpectNoError(err)
|
||||||
|
framework.ExpectNoError(f.WaitForPodRunning(podName))
|
||||||
|
e2elog.Logf("Netexec pod %q in namespace %q running", podName, ns)
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
e2elog.Logf("Cleaning up the netexec pod: %v", podName)
|
e2elog.Logf("Cleaning up the netexec pod: %v", podName)
|
||||||
err = cs.CoreV1().Pods(ns).Delete(podName, nil)
|
err = cs.CoreV1().Pods(ns).Delete(podName, nil)
|
||||||
|
@ -300,9 +300,13 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
framework.Skipf("The test requires at least two ready nodes on %s, but found %v", framework.TestContext.Provider, nodeCounts)
|
framework.Skipf("The test requires at least two ready nodes on %s, but found %v", framework.TestContext.Provider, nodeCounts)
|
||||||
}
|
}
|
||||||
|
|
||||||
ginkgo.By("Creating a webserver pod 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 := "echoserver-sourceip"
|
serverPodName := "echo-sourceip"
|
||||||
jig.LaunchEchoserverPodOnNode(f, "", serverPodName)
|
pod := f.NewAgnhostPod(serverPodName, "netexec", "--http-port", strconv.Itoa(servicePort))
|
||||||
|
pod.Labels = jig.Labels
|
||||||
|
_, err := cs.CoreV1().Pods(ns).Create(pod)
|
||||||
|
framework.ExpectNoError(err)
|
||||||
|
framework.ExpectNoError(f.WaitForPodRunning(pod.Name))
|
||||||
defer func() {
|
defer func() {
|
||||||
e2elog.Logf("Cleaning up the echo server pod")
|
e2elog.Logf("Cleaning up the echo server pod")
|
||||||
err := cs.CoreV1().Pods(ns).Delete(serverPodName, nil)
|
err := cs.CoreV1().Pods(ns).Delete(serverPodName, nil)
|
||||||
@ -310,7 +314,7 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
}()
|
}()
|
||||||
|
|
||||||
// Waiting for service to expose endpoint.
|
// Waiting for service to expose endpoint.
|
||||||
err := e2eendpoints.ValidateEndpointsPorts(cs, ns, serviceName, e2eendpoints.PortsByPodName{serverPodName: {servicePort}})
|
err = e2eendpoints.ValidateEndpointsPorts(cs, ns, serviceName, e2eendpoints.PortsByPodName{serverPodName: {servicePort}})
|
||||||
framework.ExpectNoError(err, "failed to validate endpoints for service %s in namespace: %s", serviceName, ns)
|
framework.ExpectNoError(err, "failed to validate endpoints for service %s in namespace: %s", serviceName, ns)
|
||||||
|
|
||||||
ginkgo.By("Creating pause pod deployment")
|
ginkgo.By("Creating pause pod deployment")
|
||||||
|
Loading…
Reference in New Issue
Block a user