From 415f13ea4e49bc58d9ae06420aa62dc69442b15b Mon Sep 17 00:00:00 2001 From: xiangpengzhao Date: Thu, 15 Jun 2017 11:48:26 +0800 Subject: [PATCH] Modify e2e tests for service type update. --- test/e2e/framework/service_util.go | 4 ++ test/e2e/service.go | 66 +++++++++++++++++++++++------- 2 files changed, 55 insertions(+), 15 deletions(-) diff --git a/test/e2e/framework/service_util.go b/test/e2e/framework/service_util.go index d123803db80..9d1d18b9f01 100644 --- a/test/e2e/framework/service_util.go +++ b/test/e2e/framework/service_util.go @@ -407,6 +407,10 @@ func (j *ServiceTestJig) SanityCheckService(svc *v1.Service, svcType v1.ServiceT if svc.Spec.ClusterIP != api.ClusterIPNone && svc.Spec.ClusterIP == "" { Failf("didn't get ClusterIP for non-ExternamName service") } + } else { + if svc.Spec.ClusterIP != "" { + Failf("unexpected Spec.ClusterIP (%s) for ExternamName service, expected empty", svc.Spec.ClusterIP) + } } expectNodePorts := false diff --git a/test/e2e/service.go b/test/e2e/service.go index 60e8bb11406..78291b12a82 100644 --- a/test/e2e/service.go +++ b/test/e2e/service.go @@ -796,6 +796,11 @@ var _ = framework.KubeDescribe("Services", func() { By("creating a service " + serviceName + " with the type=ExternalName in namespace " + ns) externalNameService := jig.CreateExternalNameServiceOrFail(ns, nil) + defer func() { + framework.Logf("Cleaning up the ExternalName to ClusterIP test service") + err := cs.Core().Services(ns).Delete(serviceName, nil) + Expect(err).NotTo(HaveOccurred()) + }() jig.SanityCheckService(externalNameService, v1.ServiceTypeExternalName) By("changing the ExternalName service to type=ClusterIP") clusterIPService := jig.UpdateServiceOrFail(ns, externalNameService.Name, func(s *v1.Service) { @@ -815,6 +820,11 @@ var _ = framework.KubeDescribe("Services", func() { By("creating a service " + serviceName + " with the type=ExternalName in namespace " + ns) externalNameService := jig.CreateExternalNameServiceOrFail(ns, nil) + defer func() { + framework.Logf("Cleaning up the ExternalName to NodePort test service") + err := cs.Core().Services(ns).Delete(serviceName, nil) + Expect(err).NotTo(HaveOccurred()) + }() jig.SanityCheckService(externalNameService, v1.ServiceTypeExternalName) By("changing the ExternalName service to type=NodePort") nodePortService := jig.UpdateServiceOrFail(ns, externalNameService.Name, func(s *v1.Service) { @@ -827,25 +837,51 @@ var _ = framework.KubeDescribe("Services", func() { jig.SanityCheckService(nodePortService, v1.ServiceTypeNodePort) }) - It("should be able to change the type from ExternalName to LoadBalancer", func() { - serviceName := "externalname-service" + It("should be able to change the type from ClusterIP to ExternalName", func() { + serviceName := "clusterip-service" ns := f.Namespace.Name - loadBalancerCreateTimeout := framework.LoadBalancerCreateTimeoutDefault jig := framework.NewServiceTestJig(cs, serviceName) - By("creating a service " + serviceName + " with the type=ExternalName in namespace " + ns) - externalNameService := jig.CreateExternalNameServiceOrFail(ns, nil) - jig.SanityCheckService(externalNameService, v1.ServiceTypeExternalName) - By("changing the ExternalName service to type=LoadBalancer") - loadBalancerIPService := jig.UpdateServiceOrFail(ns, externalNameService.Name, func(s *v1.Service) { - s.Spec.Type = v1.ServiceTypeLoadBalancer - s.Spec.ExternalName = "" - s.Spec.Ports = []v1.ServicePort{ - {Port: 80, Name: "http", Protocol: "TCP"}, - } + By("creating a service " + serviceName + " with the type=ClusterIP in namespace " + ns) + clusterIPService := jig.CreateTCPServiceOrFail(ns, nil) + defer func() { + framework.Logf("Cleaning up the ClusterIP to ExternalName test service") + err := cs.Core().Services(ns).Delete(serviceName, nil) + Expect(err).NotTo(HaveOccurred()) + }() + jig.SanityCheckService(clusterIPService, v1.ServiceTypeClusterIP) + By("changing the ClusterIP service to type=ExternalName") + externalNameService := jig.UpdateServiceOrFail(ns, clusterIPService.Name, func(s *v1.Service) { + s.Spec.Type = v1.ServiceTypeExternalName + s.Spec.ExternalName = "foo.example.com" + s.Spec.ClusterIP = "" }) - loadBalancerIPService = jig.WaitForLoadBalancerOrFail(ns, loadBalancerIPService.Name, loadBalancerCreateTimeout) - jig.SanityCheckService(loadBalancerIPService, v1.ServiceTypeLoadBalancer) + jig.SanityCheckService(externalNameService, v1.ServiceTypeExternalName) + }) + + It("should be able to change the type from NodePort to ExternalName", func() { + serviceName := "nodeport-service" + ns := f.Namespace.Name + jig := framework.NewServiceTestJig(cs, serviceName) + + By("creating a service " + serviceName + " with the type=NodePort in namespace " + ns) + nodePortService := jig.CreateTCPServiceOrFail(ns, func(svc *v1.Service) { + svc.Spec.Type = v1.ServiceTypeNodePort + }) + defer func() { + framework.Logf("Cleaning up the NodePort to ExternalName test service") + err := cs.Core().Services(ns).Delete(serviceName, nil) + Expect(err).NotTo(HaveOccurred()) + }() + jig.SanityCheckService(nodePortService, v1.ServiceTypeNodePort) + By("changing the NodePort service to type=ExternalName") + externalNameService := jig.UpdateServiceOrFail(ns, nodePortService.Name, func(s *v1.Service) { + s.Spec.Type = v1.ServiceTypeExternalName + s.Spec.ExternalName = "foo.example.com" + s.Spec.ClusterIP = "" + s.Spec.Ports[0].NodePort = 0 + }) + jig.SanityCheckService(externalNameService, v1.ServiceTypeExternalName) }) It("should use same NodePort with same port but different protocols", func() {