Skip to content

Commit f31839a

Browse files
author
Antonio Ojea
committed
e2e services wait for endpoint and endpoint slices
Since 1.19 endpoint slices is enabled by default, so all the e2e tests should consider them. The e2e networking tests for services use the jig object for all the tests, but was not taking into account endpoint slices. This considers endpoints slices for the method waitForAvailableEndpoint() Date: Sun Aug 9 12:34:06 2020 +0200
1 parent 92e51c1 commit f31839a

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

test/e2e/framework/service/BUILD

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ go_library(
1313
visibility = ["//visibility:public"],
1414
deps = [
1515
"//staging/src/k8s.io/api/core/v1:go_default_library",
16+
"//staging/src/k8s.io/api/discovery/v1beta1:go_default_library",
1617
"//staging/src/k8s.io/api/policy/v1beta1:go_default_library",
1718
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
1819
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",

test/e2e/framework/service/jig.go

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828

2929
"github.com/onsi/ginkgo"
3030
v1 "k8s.io/api/core/v1"
31+
discoveryv1beta1 "k8s.io/api/discovery/v1beta1"
3132
policyv1beta1 "k8s.io/api/policy/v1beta1"
3233
apierrors "k8s.io/apimachinery/pkg/api/errors"
3334
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -352,6 +353,8 @@ func (j *TestJig) waitForAvailableEndpoint(timeout time.Duration) error {
352353
endpointSelector := fields.OneTermEqualSelector("metadata.name", j.Name)
353354
stopCh := make(chan struct{})
354355
endpointAvailable := false
356+
endpointSliceAvailable := false
357+
355358
var controller cache.Controller
356359
_, controller = cache.NewInformer(
357360
&cache.ListWatch{
@@ -390,8 +393,54 @@ func (j *TestJig) waitForAvailableEndpoint(timeout time.Duration) error {
390393

391394
go controller.Run(stopCh)
392395

396+
// If EndpointSlice API is enabled, then validate if appropriate EndpointSlice objects were also create/updated/deleted.
397+
if _, err := j.Client.Discovery().ServerResourcesForGroupVersion(discoveryv1beta1.SchemeGroupVersion.String()); err == nil {
398+
var esController cache.Controller
399+
_, esController = cache.NewInformer(
400+
&cache.ListWatch{
401+
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
402+
options.LabelSelector = "kubernetes.io/service-name=" + j.Name
403+
obj, err := j.Client.DiscoveryV1beta1().EndpointSlices(j.Namespace).List(context.TODO(), options)
404+
return runtime.Object(obj), err
405+
},
406+
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
407+
options.LabelSelector = "kubernetes.io/service-name=" + j.Name
408+
return j.Client.DiscoveryV1beta1().EndpointSlices(j.Namespace).Watch(context.TODO(), options)
409+
},
410+
},
411+
&discoveryv1beta1.EndpointSlice{},
412+
0,
413+
cache.ResourceEventHandlerFuncs{
414+
AddFunc: func(obj interface{}) {
415+
if es, ok := obj.(*discoveryv1beta1.EndpointSlice); ok {
416+
// TODO: currently we only consider addreses in 1 slice, but services with
417+
// a large number of endpoints (>1000) may have multiple slices. Some slices
418+
// with only a few addresses. We should check the addresses in all slices.
419+
if len(es.Endpoints) > 0 && len(es.Endpoints[0].Addresses) > 0 {
420+
endpointSliceAvailable = true
421+
}
422+
}
423+
},
424+
UpdateFunc: func(old, cur interface{}) {
425+
if es, ok := cur.(*discoveryv1beta1.EndpointSlice); ok {
426+
// TODO: currently we only consider addreses in 1 slice, but services with
427+
// a large number of endpoints (>1000) may have multiple slices. Some slices
428+
// with only a few addresses. We should check the addresses in all slices.
429+
if len(es.Endpoints) > 0 && len(es.Endpoints[0].Addresses) > 0 {
430+
endpointSliceAvailable = true
431+
}
432+
}
433+
},
434+
},
435+
)
436+
437+
go esController.Run(stopCh)
438+
439+
} else {
440+
endpointSliceAvailable = true
441+
}
393442
err := wait.Poll(1*time.Second, timeout, func() (bool, error) {
394-
return endpointAvailable, nil
443+
return endpointAvailable && endpointSliceAvailable, nil
395444
})
396445
if err != nil {
397446
return fmt.Errorf("no subset of available IP address found for the endpoint %s within timeout %v", j.Name, timeout)

0 commit comments

Comments
 (0)