From 7c7be149d95d806dc4ef03aa52223575af5e4784 Mon Sep 17 00:00:00 2001 From: hangaoshuai Date: Sat, 3 Feb 2018 12:06:52 +0800 Subject: [PATCH] fix todo: use the ServiceTestJig replace of service --- test/e2e/framework/service_util.go | 14 +++++++++ test/e2e/network/service.go | 50 ++++++++++-------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/test/e2e/framework/service_util.go b/test/e2e/framework/service_util.go index ae9edb92d93..1110d13308a 100644 --- a/test/e2e/framework/service_util.go +++ b/test/e2e/framework/service_util.go @@ -211,6 +211,20 @@ func (j *ServiceTestJig) CreateExternalNameServiceOrFail(namespace string, tweak return result } +// CreateServiceWithServicePort creates a new Service with ServicePort. +func (j *ServiceTestJig) CreateServiceWithServicePort(labels map[string]string, namespace string, ports []v1.ServicePort) (*v1.Service, error) { + service := &v1.Service{ + ObjectMeta: metav1.ObjectMeta{ + Name: j.Name, + }, + Spec: v1.ServiceSpec{ + Selector: labels, + Ports: ports, + }, + } + return j.Client.CoreV1().Services(namespace).Create(service) +} + func (j *ServiceTestJig) ChangeServiceType(namespace, name string, newType v1.ServiceType, timeout time.Duration) { ingressIP := "" svc := j.UpdateServiceOrFail(namespace, name, func(s *v1.Service) { diff --git a/test/e2e/network/service.go b/test/e2e/network/service.go index b7009ec92ce..81bd2c92838 100644 --- a/test/e2e/network/service.go +++ b/test/e2e/network/service.go @@ -84,9 +84,9 @@ var _ = SIGDescribe("Services", func() { valid/accessible endpoints (same port number for service and pods). */ framework.ConformanceIt("should serve a basic endpoint from pods ", func() { - // TODO: use the ServiceTestJig here serviceName := "endpoint-test2" ns := f.Namespace.Name + jig := framework.NewServiceTestJig(cs, serviceName) labels := map[string]string{ "foo": "bar", "baz": "blah", @@ -97,20 +97,12 @@ var _ = SIGDescribe("Services", func() { err := cs.CoreV1().Services(ns).Delete(serviceName, nil) Expect(err).NotTo(HaveOccurred()) }() + ports := []v1.ServicePort{{ + Port: 80, + TargetPort: intstr.FromInt(80), + }} + _, err := jig.CreateServiceWithServicePort(labels, ns, ports) - service := &v1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: serviceName, - }, - Spec: v1.ServiceSpec{ - Selector: labels, - Ports: []v1.ServicePort{{ - Port: 80, - TargetPort: intstr.FromInt(80), - }}, - }, - } - _, err := cs.CoreV1().Services(ns).Create(service) Expect(err).NotTo(HaveOccurred()) framework.ValidateEndpointsOrFail(cs, ns, serviceName, framework.PortsByPodName{}) @@ -149,10 +141,10 @@ var _ = SIGDescribe("Services", func() { valid/accessible endpoints (different port number for pods). */ framework.ConformanceIt("should serve multiport endpoints from pods ", func() { - // TODO: use the ServiceTestJig here // repacking functionality is intentionally not tested here - it's better to test it in an integration test. serviceName := "multi-endpoint-test" ns := f.Namespace.Name + jig := framework.NewServiceTestJig(cs, serviceName) defer func() { err := cs.CoreV1().Services(ns).Delete(serviceName, nil) @@ -165,27 +157,19 @@ var _ = SIGDescribe("Services", func() { svc2port := "svc2" By("creating service " + serviceName + " in namespace " + ns) - service := &v1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: serviceName, + ports := []v1.ServicePort{ + { + Name: "portname1", + Port: 80, + TargetPort: intstr.FromString(svc1port), }, - Spec: v1.ServiceSpec{ - Selector: labels, - Ports: []v1.ServicePort{ - { - Name: "portname1", - Port: 80, - TargetPort: intstr.FromString(svc1port), - }, - { - Name: "portname2", - Port: 81, - TargetPort: intstr.FromString(svc2port), - }, - }, + { + Name: "portname2", + Port: 81, + TargetPort: intstr.FromString(svc2port), }, } - _, err := cs.CoreV1().Services(ns).Create(service) + _, err := jig.CreateServiceWithServicePort(labels, ns, ports) Expect(err).NotTo(HaveOccurred()) port1 := 100 port2 := 101