mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Update test to create endpoint, patch addresses and ports for endpoint, ensure watch for DELETED
This commit is contained in:
parent
de5859f7ce
commit
be382a812c
@ -2684,52 +2684,49 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
|
|
||||||
ginkgo.It("should test the lifecycle of an Endpoint", func() {
|
ginkgo.It("should test the lifecycle of an Endpoint", func() {
|
||||||
ns := f.Namespace.Name
|
ns := f.Namespace.Name
|
||||||
testServiceName := "testservice"
|
testEndpointName := "testservice"
|
||||||
|
|
||||||
ginkgo.By("creating a service")
|
ginkgo.By("creating an Endpoint")
|
||||||
_, err := f.ClientSet.CoreV1().Services(ns).Create(context.TODO(), &v1.Service{
|
_, err := f.ClientSet.CoreV1().Endpoints(ns).Create(context.TODO(), &v1.Endpoints{
|
||||||
ObjectMeta: metav1.ObjectMeta{
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
Name: testServiceName,
|
Name: testEndpointName,
|
||||||
Namespace: ns,
|
Namespace: ns,
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"testservice-static": "true",
|
"testendpoint-static": "true",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Spec: v1.ServiceSpec{
|
Subsets: []v1.EndpointSubset{{
|
||||||
Type: "ClusterIP",
|
Addresses: []v1.EndpointAddress{{
|
||||||
Ports: []v1.ServicePort{{
|
IP: "10.0.0.24",
|
||||||
Port: 80,
|
|
||||||
TargetPort: intstr.FromInt(80),
|
|
||||||
Protocol: v1.ProtocolTCP,
|
|
||||||
}},
|
}},
|
||||||
Selector: map[string]string{
|
Ports: []v1.EndpointPort{{
|
||||||
"testservice-static": "true",
|
Name: "http",
|
||||||
},
|
Port: 80,
|
||||||
},
|
Protocol: v1.ProtocolTCP,
|
||||||
|
}},
|
||||||
|
}},
|
||||||
}, metav1.CreateOptions{})
|
}, metav1.CreateOptions{})
|
||||||
framework.ExpectNoError(err, "failed to create service")
|
framework.ExpectNoError(err, "failed to create Endpoint")
|
||||||
|
|
||||||
// setup a watch for the Service
|
// setup a watch for the Endpoint
|
||||||
serviceWatchTimeoutSeconds := int64(60)
|
endpointWatchTimeoutSeconds := int64(60)
|
||||||
serviceWatch, err := f.ClientSet.CoreV1().Services(ns).Watch(context.TODO(), metav1.ListOptions{LabelSelector: "testservice-static=true", TimeoutSeconds: &serviceWatchTimeoutSeconds})
|
endpointWatch, err := f.ClientSet.CoreV1().Endpoints(ns).Watch(context.TODO(), metav1.ListOptions{LabelSelector: "testendpoint-static=true", TimeoutSeconds: &endpointWatchTimeoutSeconds})
|
||||||
framework.ExpectNoError(err, "Failed to setup watch on newly created Service")
|
framework.ExpectNoError(err, "failed to setup watch on newly created Endpoint")
|
||||||
serviceWatchChan := serviceWatch.ResultChan()
|
endpointWatchChan := endpointWatch.ResultChan()
|
||||||
ginkgo.By("waiting for available Service")
|
ginkgo.By("waiting for available Endpoint")
|
||||||
for event := range serviceWatchChan {
|
for event := range endpointWatchChan {
|
||||||
svc, ok := event.Object.(*v1.Service)
|
if event.Type == "ADDED" {
|
||||||
framework.ExpectEqual(ok, true, "Unable to convert type of Service watch event")
|
|
||||||
if svc.Spec.ClusterIP != "" {
|
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ginkgo.By("listing all Endpoints")
|
ginkgo.By("listing all Endpoints")
|
||||||
endpointsList, err := f.ClientSet.CoreV1().Endpoints("").List(context.TODO(), metav1.ListOptions{LabelSelector: "testservice-static=true"})
|
endpointsList, err := f.ClientSet.CoreV1().Endpoints("").List(context.TODO(), metav1.ListOptions{LabelSelector: "testendpoint-static=true"})
|
||||||
framework.ExpectNoError(err, "failed to list Endpoints")
|
framework.ExpectNoError(err, "failed to list Endpoints")
|
||||||
foundEndpointService := false
|
foundEndpointService := false
|
||||||
var foundEndpoint v1.Endpoints
|
var foundEndpoint v1.Endpoints
|
||||||
for _, endpoint := range endpointsList.Items {
|
for _, endpoint := range endpointsList.Items {
|
||||||
if endpoint.ObjectMeta.Name == testServiceName && endpoint.ObjectMeta.Namespace == ns {
|
if endpoint.ObjectMeta.Name == testEndpointName && endpoint.ObjectMeta.Namespace == ns {
|
||||||
foundEndpointService = true
|
foundEndpointService = true
|
||||||
foundEndpoint = endpoint
|
foundEndpoint = endpoint
|
||||||
break
|
break
|
||||||
@ -2743,7 +2740,7 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
framework.ExpectNoError(err, "failed to update Endpoint with new label")
|
framework.ExpectNoError(err, "failed to update Endpoint with new label")
|
||||||
|
|
||||||
ginkgo.By("fetching the Endpoint")
|
ginkgo.By("fetching the Endpoint")
|
||||||
_, err = f.ClientSet.CoreV1().Endpoints(ns).Get(context.TODO(), testServiceName, metav1.GetOptions{})
|
_, err = f.ClientSet.CoreV1().Endpoints(ns).Get(context.TODO(), testEndpointName, metav1.GetOptions{})
|
||||||
framework.ExpectNoError(err, "failed to fetch Endpoint")
|
framework.ExpectNoError(err, "failed to fetch Endpoint")
|
||||||
framework.ExpectEqual(foundEndpoint.ObjectMeta.Labels["testservice"], "first-modification", "label not patched")
|
framework.ExpectEqual(foundEndpoint.ObjectMeta.Labels["testservice"], "first-modification", "label not patched")
|
||||||
|
|
||||||
@ -2753,24 +2750,48 @@ var _ = SIGDescribe("Services", func() {
|
|||||||
"testservice": "second-modification",
|
"testservice": "second-modification",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
"subsets": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"addresses": []map[string]string{
|
||||||
|
{
|
||||||
|
"ip": "10.0.0.25",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"ports": []map[string]interface{}{
|
||||||
|
{
|
||||||
|
"name": "http-test",
|
||||||
|
"port": int32(8080),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
framework.ExpectNoError(err, "failed to marshal JSON for Event patch")
|
framework.ExpectNoError(err, "failed to marshal JSON for Event patch")
|
||||||
ginkgo.By("patching the Endpoint")
|
ginkgo.By("patching the Endpoint")
|
||||||
_, err = f.ClientSet.CoreV1().Endpoints(ns).Patch(context.TODO(), testServiceName, types.StrategicMergePatchType, []byte(endpointPatch), metav1.PatchOptions{})
|
_, err = f.ClientSet.CoreV1().Endpoints(ns).Patch(context.TODO(), testEndpointName, types.StrategicMergePatchType, []byte(endpointPatch), metav1.PatchOptions{})
|
||||||
framework.ExpectNoError(err, "failed to patch Endpoint")
|
framework.ExpectNoError(err, "failed to patch Endpoint")
|
||||||
|
|
||||||
ginkgo.By("fetching the Endpoint")
|
ginkgo.By("fetching the Endpoint")
|
||||||
_, err = f.ClientSet.CoreV1().Endpoints(ns).Get(context.TODO(), testServiceName, metav1.GetOptions{})
|
endpoint, err := f.ClientSet.CoreV1().Endpoints(ns).Get(context.TODO(), testEndpointName, metav1.GetOptions{})
|
||||||
framework.ExpectNoError(err, "failed to fetch Endpoint")
|
framework.ExpectNoError(err, "failed to fetch Endpoint")
|
||||||
framework.ExpectEqual(foundEndpoint.ObjectMeta.Labels["testservice"], "first-modification", "failed to patch Endpoint with Label")
|
framework.ExpectEqual(endpoint.ObjectMeta.Labels["testservice"], "second-modification", "failed to patch Endpoint with Label")
|
||||||
|
endpointSubsetOne := endpoint.Subsets[0]
|
||||||
|
endpointSubsetOneAddresses := endpointSubsetOne.Addresses[0]
|
||||||
|
endpointSubsetOnePorts := endpointSubsetOne.Ports[0]
|
||||||
|
framework.ExpectEqual(endpointSubsetOneAddresses.IP, "10.0.0.25", "failed to patch Endpoint")
|
||||||
|
framework.ExpectEqual(endpointSubsetOnePorts.Name, "http-test", "failed to patch Endpoint")
|
||||||
|
framework.ExpectEqual(endpointSubsetOnePorts.Port, int32(8080), "failed to patch Endpoint")
|
||||||
|
|
||||||
ginkgo.By("deleting the Endpoint by Collection")
|
ginkgo.By("deleting the Endpoint by Collection")
|
||||||
err = f.ClientSet.CoreV1().Endpoints(ns).DeleteCollection(context.TODO(), &metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "testservice-static=true"})
|
err = f.ClientSet.CoreV1().Endpoints(ns).DeleteCollection(context.TODO(), &metav1.DeleteOptions{}, metav1.ListOptions{LabelSelector: "testendpoint-static=true"})
|
||||||
framework.ExpectNoError(err, "failed to delete Endpoint by Collection")
|
framework.ExpectNoError(err, "failed to delete Endpoint by Collection")
|
||||||
|
|
||||||
ginkgo.By("deleting the Service")
|
ginkgo.By("waiting for Endpoint deletion")
|
||||||
err = f.ClientSet.CoreV1().Services(ns).Delete(context.TODO(), testServiceName, &metav1.DeleteOptions{})
|
for event := range endpointWatchChan {
|
||||||
framework.ExpectNoError(err, "failed to delete Service")
|
if event.Type == "DELETED" {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user