Skip to content

Commit 8f7bb96

Browse files
committed
TrafficDistribution e2e cleanups
Remove endpointSlicesHaveSameZoneHints check. We are testing that connections end up at the right endpoints. We don't need to validate _why_ they go to the right endpoints, which is already tested by other tests anyway. (Also, validating the hints becomes more complicated in the same-node case, where there may or may not also be same-zone hints depending on cluster configuration.) Remove DeferCleanup calls; we don't need to delete anything manually because namespaced resources will automatically be deleted when the test case's namespace is deleted. Remove a setting of pod.NodeName that was redundant with e2epod.SetNodeSelection().
1 parent 2670462 commit 8f7bb96

File tree

1 file changed

+5
-31
lines changed

1 file changed

+5
-31
lines changed

Diff for: test/e2e/network/traffic_distribution.go

+5-31
Original file line numberDiff line numberDiff line change
@@ -77,31 +77,6 @@ var _ = common.SIGDescribe("Traffic Distribution", func() {
7777
}
7878
}
7979

80-
// endpointSlicesHaveSameZoneHints returns a matcher function to be used with
81-
// gomega.Eventually().Should(...). It checks that the passed EndpointSlices
82-
// have zone-hints which match the endpoint's zone.
83-
endpointSlicesHaveSameZoneHints := framework.MakeMatcher(func(slices []discoveryv1.EndpointSlice) (func() string, error) {
84-
if len(slices) == 0 {
85-
return nil, fmt.Errorf("no endpointslices found")
86-
}
87-
for _, slice := range slices {
88-
for _, endpoint := range slice.Endpoints {
89-
var ip string
90-
if len(endpoint.Addresses) > 0 {
91-
ip = endpoint.Addresses[0]
92-
}
93-
var zone string
94-
if endpoint.Zone != nil {
95-
zone = *endpoint.Zone
96-
}
97-
if endpoint.Hints == nil || len(endpoint.Hints.ForZones) != 1 || endpoint.Hints.ForZones[0].Name != zone {
98-
return gomegaCustomError("endpoint with ip %v does not have the correct hint, want hint for zone %q\nEndpointSlices=\n%v", ip, zone, format.Object(slices, 1 /* indent one level */)), nil
99-
}
100-
}
101-
}
102-
return nil, nil
103-
})
104-
10580
// requestsFromClient returns a helper function to be used with
10681
// gomega.Eventually(...). It fetches the logs from the clientPod and returns
10782
// them in reverse-chronological order.
@@ -161,7 +136,6 @@ var _ = common.SIGDescribe("Traffic Distribution", func() {
161136

162137
servingPods = append(servingPods, pod)
163138
zoneForServingPod[pod.Name] = zone
164-
ginkgo.DeferCleanup(framework.IgnoreNotFound(c.CoreV1().Pods(f.Namespace.Name).Delete), pod.GetName(), metav1.DeleteOptions{})
165139
}
166140
e2epod.NewPodClient(f).CreateBatch(ctx, servingPods)
167141

@@ -181,23 +155,23 @@ var _ = common.SIGDescribe("Traffic Distribution", func() {
181155
},
182156
})
183157
ginkgo.By(fmt.Sprintf("creating a service=%q with trafficDistribution=%v", svc.GetName(), *svc.Spec.TrafficDistribution))
184-
ginkgo.DeferCleanup(framework.IgnoreNotFound(c.CoreV1().Services(f.Namespace.Name).Delete), svc.GetName(), metav1.DeleteOptions{})
185158

186-
ginkgo.By("ensuring EndpointSlice for service have correct same-zone hints")
187-
gomega.Eventually(ctx, endpointSlicesForService(svc.GetName())).WithPolling(5 * time.Second).WithTimeout(e2eservice.ServiceEndpointsTimeout).Should(endpointSlicesHaveSameZoneHints)
159+
ginkgo.By("waiting for EndpointSlices to be created")
160+
err = framework.WaitForServiceEndpointsNum(ctx, c, svc.Namespace, svc.Name, len(servingPods), 1*time.Second, e2eservice.ServiceEndpointsTimeout)
161+
framework.ExpectNoError(err)
162+
slices := endpointSlicesForService(svc.Name)
163+
framework.Logf("got slices:\n%v", format.Object(slices, 1))
188164

189165
ginkgo.By("keeping traffic within the same zone as the client, when serving pods exist in the same zone")
190166

191167
createClientPod := func(ctx context.Context, zone string) *v1.Pod {
192168
pod := e2epod.NewAgnhostPod(f.Namespace.Name, "client-pod-in-"+zone, nil, nil, nil)
193-
pod.Spec.NodeName = nodeForZone[zone]
194169
nodeSelection := e2epod.NodeSelection{Name: nodeForZone[zone]}
195170
e2epod.SetNodeSelection(&pod.Spec, nodeSelection)
196171
cmd := fmt.Sprintf(`date; for i in $(seq 1 3000); do sleep 1; echo "Date: $(date) Try: ${i}"; curl -q -s --connect-timeout 2 http://%s:80/ ; echo; done`, svc.Name)
197172
pod.Spec.Containers[0].Command = []string{"/bin/sh", "-c", cmd}
198173
pod.Spec.Containers[0].Name = pod.Name
199174

200-
ginkgo.DeferCleanup(framework.IgnoreNotFound(c.CoreV1().Pods(f.Namespace.Name).Delete), pod.GetName(), metav1.DeleteOptions{})
201175
return e2epod.NewPodClient(f).CreateSync(ctx, pod)
202176
}
203177

0 commit comments

Comments
 (0)