Skip to content

Commit 78940cd

Browse files
authored
Merge pull request kubernetes#81419 from mgdevstack/checkServiceReachability
Update e2e testing nodePort service listening on same port but different protocols
2 parents 6610260 + 99475f9 commit 78940cd

File tree

2 files changed

+57
-78
lines changed

2 files changed

+57
-78
lines changed

test/e2e/framework/service/jig.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ func (j *TestJig) CheckServiceReachability(namespace string, svc *v1.Service, po
859859
}
860860
}
861861

862-
// CreateServicePods creates a replication controller with the label same as service
862+
// CreateServicePods creates a replication controller with the label same as service. Service listens to HTTP.
863863
func (j *TestJig) CreateServicePods(c clientset.Interface, ns string, replica int) {
864864
config := testutils.RCConfig{
865865
Client: c,
@@ -875,3 +875,20 @@ func (j *TestJig) CreateServicePods(c clientset.Interface, ns string, replica in
875875
err := framework.RunRC(config)
876876
framework.ExpectNoError(err, "Replica must be created")
877877
}
878+
879+
// CreateTCPUDPServicePods creates a replication controller with the label same as service. Service listens to TCP and UDP.
880+
func (j *TestJig) CreateTCPUDPServicePods(c clientset.Interface, ns string, replica int) {
881+
config := testutils.RCConfig{
882+
Client: c,
883+
Name: j.Name,
884+
Image: framework.ServeHostnameImage,
885+
Command: []string{"/agnhost", "serve-hostname", "--http=false", "--tcp", "--udp"},
886+
Namespace: ns,
887+
Labels: j.Labels,
888+
PollInterval: 3 * time.Second,
889+
Timeout: framework.PodReadyBeforeTimeout,
890+
Replicas: replica,
891+
}
892+
err := framework.RunRC(config)
893+
framework.ExpectNoError(err, "Replica must be created")
894+
}

test/e2e/network/service.go

Lines changed: 39 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -932,11 +932,12 @@ var _ = SIGDescribe("Services", func() {
932932

933933
/*
934934
Testname: Service, update NodePort, same port different protocol
935-
Description: Create a service of type ClusterIP to accept TCP requests. Service creation MUST be successful by assigning ClusterIP to the service.
936-
When service type is updated to NodePort to support two protocols i.e. TCP and UDP for same assigned service port 80, service update MUST be successful by allocating two NodePorts to the service.
937-
TODO: Test Service reachability, good to include this check in Conformance perspective.
935+
Description: Create a service to accept TCP requests. By default, created service MUST be of type ClusterIP and an ClusterIP MUST be assigned to the service.
936+
When service type is updated to NodePort supporting TCP protocol, it MUST be reachable on nodeIP over allocated NodePort to serve TCP requests.
937+
When this NodePort service is updated to use two protocols i.e. TCP and UDP for same assigned service port 80, service update MUST be successful by allocating two NodePorts to the service and
938+
service MUST be able to serve both TCP and UDP requests over same service port 80.
938939
*/
939-
ginkgo.It("should be able to update NodePorts with two same port numbers but different protocols", func() {
940+
ginkgo.It("should be able to update service type to NodePort listening on same port number but different protocols", func() {
940941
serviceName := "nodeport-update-service"
941942
ns := f.Namespace.Name
942943
jig := e2eservice.NewTestJig(cs, serviceName)
@@ -949,36 +950,50 @@ var _ = SIGDescribe("Services", func() {
949950
framework.ExpectNoError(err, "failed to delete service: %s in namespace: %s", serviceName, ns)
950951
}()
951952
jig.SanityCheckService(tcpService, v1.ServiceTypeClusterIP)
952-
svcPort := int(tcpService.Spec.Ports[0].Port)
953-
framework.Logf("service port TCP: %d", svcPort)
953+
framework.Logf("Service Port TCP: %v", tcpService.Spec.Ports[0].Port)
954+
955+
ginkgo.By("changing the TCP service to type=NodePort")
956+
nodePortService := jig.UpdateServiceOrFail(ns, tcpService.Name, func(s *v1.Service) {
957+
s.Spec.Type = v1.ServiceTypeNodePort
958+
s.Spec.Ports = []v1.ServicePort{
959+
{
960+
Name: "tcp-port",
961+
Port: 80,
962+
Protocol: v1.ProtocolTCP,
963+
TargetPort: intstr.FromInt(9376),
964+
},
965+
}
966+
})
967+
968+
jig.CreateTCPUDPServicePods(cs, ns, 2)
969+
execPod := e2epod.CreateExecPodOrFail(cs, ns, "execpod", nil)
970+
jig.CheckServiceReachability(ns, nodePortService, execPod)
954971

955-
// Change the services to NodePort and add a UDP port.
956-
ginkgo.By("changing the TCP service to type=NodePort and add a UDP port")
957-
newService := jig.UpdateServiceOrFail(ns, tcpService.Name, func(s *v1.Service) {
972+
ginkgo.By("Updating NodePort service to listen TCP and UDP based requests over same Port")
973+
nodePortService = jig.UpdateServiceOrFail(ns, tcpService.Name, func(s *v1.Service) {
958974
s.Spec.Type = v1.ServiceTypeNodePort
959975
s.Spec.Ports = []v1.ServicePort{
960976
{
961-
Name: "tcp-port",
962-
Port: 80,
963-
Protocol: v1.ProtocolTCP,
977+
Name: "tcp-port",
978+
Port: 80,
979+
Protocol: v1.ProtocolTCP,
980+
TargetPort: intstr.FromInt(9376),
964981
},
965982
{
966-
Name: "udp-port",
967-
Port: 80,
968-
Protocol: v1.ProtocolUDP,
983+
Name: "udp-port",
984+
Port: 80,
985+
Protocol: v1.ProtocolUDP,
986+
TargetPort: intstr.FromInt(9376),
969987
},
970988
}
971989
})
972-
jig.SanityCheckService(newService, v1.ServiceTypeNodePort)
973-
if len(newService.Spec.Ports) != 2 {
974-
framework.Failf("new service should have two Ports")
975-
}
976-
for _, port := range newService.Spec.Ports {
977-
if port.NodePort == 0 {
978-
framework.Failf("new service failed to allocate NodePort for Port %s", port.Name)
979-
}
990+
jig.CheckServiceReachability(ns, nodePortService, execPod)
991+
nodePortCounts := len(nodePortService.Spec.Ports)
992+
framework.ExpectEqual(nodePortCounts, 2, "updated service should have two Ports but found %d Ports", nodePortCounts)
980993

981-
framework.Logf("new service allocates NodePort %d for Port %s", port.NodePort, port.Name)
994+
for _, port := range nodePortService.Spec.Ports {
995+
framework.ExpectNotEqual(port.NodePort, 0, "NodePort service failed to allocate NodePort for Port %s", port.Name)
996+
framework.Logf("NodePort service allocates NodePort: %d for Port: %s over Protocol: %s", port.NodePort, port.Name, port.Protocol)
982997
}
983998
})
984999

@@ -1133,59 +1148,6 @@ var _ = SIGDescribe("Services", func() {
11331148

11341149
})
11351150

1136-
/*
1137-
Testname: Service, NodePort, same port different protocols
1138-
Description: Create a service of type NodePort listening on port 53 for two protocols TCP and UDP.
1139-
Service creation MUST be successful by assigning a ClusterIP and two unique nodePorts for each protocol, making service reachable on every node's IP and nodePort.
1140-
TODO: Test Service reachability, good to include this check in Conformance perspective.
1141-
*/
1142-
ginkgo.It("should use same NodePort with same port but different protocols", func() {
1143-
serviceName := "nodeports"
1144-
ns := f.Namespace.Name
1145-
1146-
t := e2eservice.NewServerTest(cs, ns, serviceName)
1147-
defer func() {
1148-
defer ginkgo.GinkgoRecover()
1149-
errs := t.Cleanup()
1150-
if len(errs) != 0 {
1151-
framework.Failf("errors in cleanup: %v", errs)
1152-
}
1153-
}()
1154-
1155-
ginkgo.By("creating service " + serviceName + " with same NodePort but different protocols in namespace " + ns)
1156-
service := &v1.Service{
1157-
ObjectMeta: metav1.ObjectMeta{
1158-
Name: t.ServiceName,
1159-
Namespace: t.Namespace,
1160-
},
1161-
Spec: v1.ServiceSpec{
1162-
Selector: t.Labels,
1163-
Type: v1.ServiceTypeNodePort,
1164-
Ports: []v1.ServicePort{
1165-
{
1166-
Name: "tcp-port",
1167-
Port: 53,
1168-
Protocol: v1.ProtocolTCP,
1169-
},
1170-
{
1171-
Name: "udp-port",
1172-
Port: 53,
1173-
Protocol: v1.ProtocolUDP,
1174-
},
1175-
},
1176-
},
1177-
}
1178-
result, err := t.CreateService(service)
1179-
framework.ExpectNoError(err, "failed to create service: %s in namespace: %s", serviceName, ns)
1180-
1181-
if len(result.Spec.Ports) != 2 {
1182-
framework.Failf("got unexpected len(Spec.Ports) for new service: %v", result)
1183-
}
1184-
if result.Spec.Ports[0].NodePort != result.Spec.Ports[1].NodePort {
1185-
framework.Failf("should use same NodePort for new service: %v", result)
1186-
}
1187-
})
1188-
11891151
ginkgo.It("should prevent NodePort collisions", func() {
11901152
// TODO: use the ServiceTestJig here
11911153
baseName := "nodeport-collision-"

0 commit comments

Comments
 (0)