Merge pull request #106034 from ii/delete-service-collection

Create e2e delete service collection test - +1 endpoint
This commit is contained in:
Kubernetes Prow Robot 2021-11-03 15:24:39 -07:00 committed by GitHub
commit 6717bdbcd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2730,6 +2730,81 @@ var _ = common.SIGDescribe("Services", func() {
framework.ExpectNoError(err, "failed to delete Service %v in namespace %v", testService.ObjectMeta.Name, ns) framework.ExpectNoError(err, "failed to delete Service %v in namespace %v", testService.ObjectMeta.Name, ns)
framework.Logf("Service %s deleted", testSvcName) framework.Logf("Service %s deleted", testSvcName)
}) })
ginkgo.It("should delete a collection of services", func() {
ns := f.Namespace.Name
svcClient := f.ClientSet.CoreV1().Services(ns)
svcResource := schema.GroupVersionResource{Group: "", Version: "v1", Resource: "services"}
svcDynamicClient := f.DynamicClient.Resource(svcResource).Namespace(ns)
svcLabel := map[string]string{"e2e-test-service": "delete"}
deleteLabel := labels.SelectorFromSet(svcLabel).String()
ginkgo.By("creating a collection of services")
testServices := []struct {
name string
label map[string]string
port int
}{
{
name: "e2e-svc-a-" + utilrand.String(5),
label: map[string]string{"e2e-test-service": "delete"},
port: 8001,
},
{
name: "e2e-svc-b-" + utilrand.String(5),
label: map[string]string{"e2e-test-service": "delete"},
port: 8002,
},
{
name: "e2e-svc-c-" + utilrand.String(5),
label: map[string]string{"e2e-test-service": "keep"},
port: 8003,
},
}
for _, testService := range testServices {
func() {
framework.Logf("Creating %s", testService.name)
svc := v1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: testService.name,
Labels: testService.label,
},
Spec: v1.ServiceSpec{
Type: "ClusterIP",
Ports: []v1.ServicePort{{
Name: "http",
Protocol: v1.ProtocolTCP,
Port: int32(testService.port),
TargetPort: intstr.FromInt(testService.port),
}},
},
}
_, err := svcClient.Create(context.TODO(), &svc, metav1.CreateOptions{})
framework.ExpectNoError(err, "failed to create Service")
}()
}
svcList, err := cs.CoreV1().Services(ns).List(context.TODO(), metav1.ListOptions{})
framework.ExpectNoError(err, "failed to list Services")
framework.ExpectEqual(len(svcList.Items), 3, "Required count of services out of sync")
ginkgo.By("deleting service collection")
err = svcDynamicClient.DeleteCollection(context.TODO(), metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: deleteLabel})
framework.ExpectNoError(err, "failed to delete service collection. %v", err)
svcList, err = cs.CoreV1().Services(ns).List(context.TODO(), metav1.ListOptions{})
framework.ExpectNoError(err, "failed to list Services")
framework.ExpectEqual(len(svcList.Items), 1, "Required count of services out of sync")
framework.Logf("Collection of services has been deleted")
})
}) })
// execAffinityTestForSessionAffinityTimeout is a helper function that wrap the logic of // execAffinityTestForSessionAffinityTimeout is a helper function that wrap the logic of