Merge pull request #46197 from xiangpengzhao/fix-allocate-clusterip
Automatic merge from submit-queue (batch tested with PRs 47850, 47835, 46197, 47250, 48284) Allocate clusterIP when change service type from ExternalName to ClusterIP **What this PR does / why we need it**: **Which issue this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close that issue when PR gets merged)*: fixes #35354 #46190 **Special notes for your reviewer**: /cc @smarterclayton @thockin **Release note**: ```release-note NONE ```
This commit is contained in:
@@ -789,6 +789,101 @@ var _ = framework.KubeDescribe("Services", func() {
|
||||
}
|
||||
})
|
||||
|
||||
It("should be able to change the type from ExternalName to ClusterIP", func() {
|
||||
serviceName := "externalname-service"
|
||||
ns := f.Namespace.Name
|
||||
jig := framework.NewServiceTestJig(cs, serviceName)
|
||||
|
||||
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) {
|
||||
s.Spec.Type = v1.ServiceTypeClusterIP
|
||||
s.Spec.ExternalName = ""
|
||||
s.Spec.Ports = []v1.ServicePort{
|
||||
{Port: 80, Name: "http", Protocol: "TCP"},
|
||||
}
|
||||
})
|
||||
jig.SanityCheckService(clusterIPService, v1.ServiceTypeClusterIP)
|
||||
})
|
||||
|
||||
It("should be able to change the type from ExternalName to NodePort", func() {
|
||||
serviceName := "externalname-service"
|
||||
ns := f.Namespace.Name
|
||||
jig := framework.NewServiceTestJig(cs, serviceName)
|
||||
|
||||
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) {
|
||||
s.Spec.Type = v1.ServiceTypeNodePort
|
||||
s.Spec.ExternalName = ""
|
||||
s.Spec.Ports = []v1.ServicePort{
|
||||
{Port: 80, Name: "http", Protocol: "TCP"},
|
||||
}
|
||||
})
|
||||
jig.SanityCheckService(nodePortService, v1.ServiceTypeNodePort)
|
||||
})
|
||||
|
||||
It("should be able to change the type from ClusterIP to ExternalName", func() {
|
||||
serviceName := "clusterip-service"
|
||||
ns := f.Namespace.Name
|
||||
jig := framework.NewServiceTestJig(cs, serviceName)
|
||||
|
||||
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 = ""
|
||||
})
|
||||
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() {
|
||||
serviceName := "nodeports"
|
||||
ns := f.Namespace.Name
|
||||
@@ -866,7 +961,7 @@ var _ = framework.KubeDescribe("Services", func() {
|
||||
}
|
||||
port := result.Spec.Ports[0]
|
||||
if port.NodePort == 0 {
|
||||
framework.Failf("got unexpected Spec.Ports[0].nodePort for new service: %v", result)
|
||||
framework.Failf("got unexpected Spec.Ports[0].NodePort for new service: %v", result)
|
||||
}
|
||||
|
||||
By("creating service " + serviceName2 + " with conflicting NodePort")
|
||||
|
||||
Reference in New Issue
Block a user