Modify e2e tests for service type update.

This commit is contained in:
xiangpengzhao
2017-06-15 11:48:26 +08:00
parent 4e9abca6d0
commit 415f13ea4e
2 changed files with 55 additions and 15 deletions

View File

@@ -407,6 +407,10 @@ func (j *ServiceTestJig) SanityCheckService(svc *v1.Service, svcType v1.ServiceT
if svc.Spec.ClusterIP != api.ClusterIPNone && svc.Spec.ClusterIP == "" { if svc.Spec.ClusterIP != api.ClusterIPNone && svc.Spec.ClusterIP == "" {
Failf("didn't get ClusterIP for non-ExternamName service") 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 expectNodePorts := false

View File

@@ -796,6 +796,11 @@ var _ = framework.KubeDescribe("Services", func() {
By("creating a service " + serviceName + " with the type=ExternalName in namespace " + ns) By("creating a service " + serviceName + " with the type=ExternalName in namespace " + ns)
externalNameService := jig.CreateExternalNameServiceOrFail(ns, nil) 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) jig.SanityCheckService(externalNameService, v1.ServiceTypeExternalName)
By("changing the ExternalName service to type=ClusterIP") By("changing the ExternalName service to type=ClusterIP")
clusterIPService := jig.UpdateServiceOrFail(ns, externalNameService.Name, func(s *v1.Service) { 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) By("creating a service " + serviceName + " with the type=ExternalName in namespace " + ns)
externalNameService := jig.CreateExternalNameServiceOrFail(ns, nil) 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) jig.SanityCheckService(externalNameService, v1.ServiceTypeExternalName)
By("changing the ExternalName service to type=NodePort") By("changing the ExternalName service to type=NodePort")
nodePortService := jig.UpdateServiceOrFail(ns, externalNameService.Name, func(s *v1.Service) { nodePortService := jig.UpdateServiceOrFail(ns, externalNameService.Name, func(s *v1.Service) {
@@ -827,25 +837,51 @@ var _ = framework.KubeDescribe("Services", func() {
jig.SanityCheckService(nodePortService, v1.ServiceTypeNodePort) jig.SanityCheckService(nodePortService, v1.ServiceTypeNodePort)
}) })
It("should be able to change the type from ExternalName to LoadBalancer", func() { It("should be able to change the type from ClusterIP to ExternalName", func() {
serviceName := "externalname-service" serviceName := "clusterip-service"
ns := f.Namespace.Name ns := f.Namespace.Name
loadBalancerCreateTimeout := framework.LoadBalancerCreateTimeoutDefault
jig := framework.NewServiceTestJig(cs, serviceName) jig := framework.NewServiceTestJig(cs, serviceName)
By("creating a service " + serviceName + " with the type=ExternalName in namespace " + ns) By("creating a service " + serviceName + " with the type=ClusterIP in namespace " + ns)
externalNameService := jig.CreateExternalNameServiceOrFail(ns, nil) clusterIPService := jig.CreateTCPServiceOrFail(ns, nil)
jig.SanityCheckService(externalNameService, v1.ServiceTypeExternalName) defer func() {
By("changing the ExternalName service to type=LoadBalancer") framework.Logf("Cleaning up the ClusterIP to ExternalName test service")
loadBalancerIPService := jig.UpdateServiceOrFail(ns, externalNameService.Name, func(s *v1.Service) { err := cs.Core().Services(ns).Delete(serviceName, nil)
s.Spec.Type = v1.ServiceTypeLoadBalancer Expect(err).NotTo(HaveOccurred())
s.Spec.ExternalName = "" }()
s.Spec.Ports = []v1.ServicePort{ jig.SanityCheckService(clusterIPService, v1.ServiceTypeClusterIP)
{Port: 80, Name: "http", Protocol: "TCP"}, 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(externalNameService, v1.ServiceTypeExternalName)
jig.SanityCheckService(loadBalancerIPService, v1.ServiceTypeLoadBalancer) })
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() { It("should use same NodePort with same port but different protocols", func() {