conformance test for Services should validate behavior

Current test for service with endpoints only validate the API objects,
however, doesn't validate that the implementation of Services works.

This mean that a cluster without any component implementing Services,
can pass Conformance.
This commit is contained in:
Antonio Ojea 2021-05-03 15:50:57 +02:00
parent dfc91819b7
commit 2dc4dba562

View File

@ -786,7 +786,7 @@ var _ = common.SIGDescribe("Services", func() {
err := cs.CoreV1().Services(ns).Delete(context.TODO(), serviceName, metav1.DeleteOptions{})
framework.ExpectNoError(err, "failed to delete service: %s in namespace: %s", serviceName, ns)
}()
_, err := jig.CreateTCPServiceWithPort(nil, 80)
svc, err := jig.CreateTCPServiceWithPort(nil, 80)
framework.ExpectNoError(err)
validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{})
@ -802,18 +802,31 @@ var _ = common.SIGDescribe("Services", func() {
name1 := "pod1"
name2 := "pod2"
createPodOrFail(f, ns, name1, jig.Labels, []v1.ContainerPort{{ContainerPort: 80}})
createPodOrFail(f, ns, name1, jig.Labels, []v1.ContainerPort{{ContainerPort: 80}}, "netexec", "--http-port", "80")
names[name1] = true
validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{name1: {80}})
createPodOrFail(f, ns, name2, jig.Labels, []v1.ContainerPort{{ContainerPort: 80}})
ginkgo.By("Checking if the Service forwards traffic to pod1")
execPod := e2epod.CreateExecPodOrFail(cs, ns, "execpod", nil)
err = jig.CheckServiceReachability(svc, execPod)
framework.ExpectNoError(err)
createPodOrFail(f, ns, name2, jig.Labels, []v1.ContainerPort{{ContainerPort: 80}}, "netexec", "--http-port", "80")
names[name2] = true
validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{name1: {80}, name2: {80}})
ginkgo.By("Checking if the Service forwards traffic to pod1 and pod2")
err = jig.CheckServiceReachability(svc, execPod)
framework.ExpectNoError(err)
e2epod.DeletePodOrFail(cs, ns, name1)
delete(names, name1)
validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{name2: {80}})
ginkgo.By("Checking if the Service forwards traffic to pod2")
err = jig.CheckServiceReachability(svc, execPod)
framework.ExpectNoError(err)
e2epod.DeletePodOrFail(cs, ns, name2)
delete(names, name2)
validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{})
@ -839,7 +852,7 @@ var _ = common.SIGDescribe("Services", func() {
svc2port := "svc2"
ginkgo.By("creating service " + serviceName + " in namespace " + ns)
_, err := jig.CreateTCPService(func(service *v1.Service) {
svc, err := jig.CreateTCPService(func(service *v1.Service) {
service.Spec.Ports = []v1.ServicePort{
{
Name: "portname1",
@ -883,14 +896,19 @@ var _ = common.SIGDescribe("Services", func() {
podname1 := "pod1"
podname2 := "pod2"
createPodOrFail(f, ns, podname1, jig.Labels, containerPorts1)
createPodOrFail(f, ns, podname1, jig.Labels, containerPorts1, "netexec", "--http-port", strconv.Itoa(port1))
names[podname1] = true
validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{podname1: {port1}})
createPodOrFail(f, ns, podname2, jig.Labels, containerPorts2)
createPodOrFail(f, ns, podname2, jig.Labels, containerPorts2, "netexec", "--http-port", strconv.Itoa(port2))
names[podname2] = true
validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{podname1: {port1}, podname2: {port2}})
ginkgo.By("Checking if the Service forwards traffic to pods")
execPod := e2epod.CreateExecPodOrFail(cs, ns, "execpod", nil)
err = jig.CheckServiceReachability(svc, execPod)
framework.ExpectNoError(err)
e2epod.DeletePodOrFail(cs, ns, podname1)
delete(names, podname1)
validateEndpointsPortsOrFail(cs, ns, serviceName, portsByPodName{podname2: {port2}})
@ -2668,9 +2686,9 @@ func createPausePodDeployment(cs clientset.Interface, name, ns string, replicas
}
// createPodOrFail creates a pod with the specified containerPorts.
func createPodOrFail(f *framework.Framework, ns, name string, labels map[string]string, containerPorts []v1.ContainerPort) {
func createPodOrFail(f *framework.Framework, ns, name string, labels map[string]string, containerPorts []v1.ContainerPort, args ...string) {
ginkgo.By(fmt.Sprintf("Creating pod %s in namespace %s", name, ns))
pod := e2epod.NewAgnhostPod(ns, name, nil, nil, containerPorts)
pod := e2epod.NewAgnhostPod(ns, name, nil, nil, containerPorts, args...)
pod.ObjectMeta.Labels = labels
// Add a dummy environment variable to work around a docker issue.
// https://github.com/docker/docker/issues/14203