Skip to content

Commit 701b0c2

Browse files
committed
Port applicable ESIPP tests from core
Although OCI LBaaS is not a pass-through load balancer (and thus does not support ESIPP) this ports the tests covering support for node-local vs cluster-wide routing (i.e. the avoidance of a second hop in the node-local case at the risk of potentially imbalanced traffic spreading.
1 parent a8af622 commit 701b0c2

File tree

4,312 files changed

+649277
-5
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

4,312 files changed

+649277
-5
lines changed

Gopkg.lock

+149-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/e2e/framework/framework.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131
wait "k8s.io/apimachinery/pkg/util/wait"
3232
clientset "k8s.io/client-go/kubernetes"
3333
clientcmd "k8s.io/client-go/tools/clientcmd"
34+
"k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
3435
)
3536

3637
const (
@@ -53,7 +54,8 @@ func init() {
5354
type Framework struct {
5455
BaseName string
5556

56-
ClientSet clientset.Interface
57+
ClientSet clientset.Interface
58+
InternalClientset internalclientset.Interface
5759

5860
// Namespace in which test resources are created.
5961
Namespace *v1.Namespace
@@ -159,6 +161,8 @@ func (f *Framework) BeforeEach() {
159161
Expect(err).NotTo(HaveOccurred())
160162
f.ClientSet, err = clientset.NewForConfig(config)
161163
Expect(err).NotTo(HaveOccurred())
164+
f.InternalClientset, err = internalclientset.NewForConfig(config)
165+
Expect(err).NotTo(HaveOccurred())
162166
}
163167

164168
By("Building a namespace api object")

test/e2e/framework/service_util.go

+67
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ import (
3333
"k8s.io/apimachinery/pkg/types"
3434
"k8s.io/apimachinery/pkg/util/intstr"
3535
utilnet "k8s.io/apimachinery/pkg/util/net"
36+
"k8s.io/apimachinery/pkg/util/sets"
3637
"k8s.io/apimachinery/pkg/util/uuid"
3738
"k8s.io/apimachinery/pkg/util/wait"
3839
clientset "k8s.io/client-go/kubernetes"
@@ -328,6 +329,72 @@ func PickNodeIP(c clientset.Interface) string {
328329
return ip
329330
}
330331

332+
// GetEndpointNodes returns a map of nodenames:external-ip on which the
333+
// endpoints of the given Service are running.
334+
func (j *ServiceTestJig) GetEndpointNodes(svc *v1.Service) map[string][]string {
335+
nodes := j.GetNodes(MaxNodesForEndpointsTests)
336+
endpoints, err := j.Client.CoreV1().Endpoints(svc.Namespace).Get(svc.Name, metav1.GetOptions{})
337+
if err != nil {
338+
Failf("Get endpoints for service %s/%s failed (%s)", svc.Namespace, svc.Name, err)
339+
}
340+
if len(endpoints.Subsets) == 0 {
341+
Failf("Endpoint has no subsets, cannot determine node addresses.")
342+
}
343+
epNodes := sets.NewString()
344+
for _, ss := range endpoints.Subsets {
345+
for _, e := range ss.Addresses {
346+
if e.NodeName != nil {
347+
epNodes.Insert(*e.NodeName)
348+
}
349+
}
350+
}
351+
nodeMap := map[string][]string{}
352+
for _, n := range nodes.Items {
353+
if epNodes.Has(n.Name) {
354+
nodeMap[n.Name] = GetNodeAddresses(&n, v1.NodeExternalIP)
355+
}
356+
}
357+
return nodeMap
358+
}
359+
360+
// GetNodes returns the first maxNodesForTest nodes. Useful in large clusters
361+
// where we don't eg: want to create an endpoint per node.
362+
func (j *ServiceTestJig) GetNodes(maxNodesForTest int) (nodes *v1.NodeList) {
363+
nodes = GetReadySchedulableNodesOrDie(j.Client)
364+
if len(nodes.Items) <= maxNodesForTest {
365+
maxNodesForTest = len(nodes.Items)
366+
}
367+
nodes.Items = nodes.Items[:maxNodesForTest]
368+
return nodes
369+
}
370+
371+
func (j *ServiceTestJig) WaitForEndpointOnNode(namespace, serviceName, nodeName string) {
372+
err := wait.PollImmediate(Poll, LoadBalancerCreateTimeoutDefault, func() (bool, error) {
373+
endpoints, err := j.Client.CoreV1().Endpoints(namespace).Get(serviceName, metav1.GetOptions{})
374+
if err != nil {
375+
Logf("Get endpoints for service %s/%s failed (%s)", namespace, serviceName, err)
376+
return false, nil
377+
}
378+
if len(endpoints.Subsets) == 0 {
379+
Logf("Expect endpoints with subsets, got none.")
380+
return false, nil
381+
}
382+
// TODO: Handle multiple endpoints
383+
if len(endpoints.Subsets[0].Addresses) == 0 {
384+
Logf("Expected Ready endpoints - found none")
385+
return false, nil
386+
}
387+
epHostName := *endpoints.Subsets[0].Addresses[0].NodeName
388+
Logf("Pod for service %s/%s is on node %s", namespace, serviceName, epHostName)
389+
if epHostName != nodeName {
390+
Logf("Found endpoint on wrong node, expected %v, got %v", nodeName, epHostName)
391+
return false, nil
392+
}
393+
return true, nil
394+
})
395+
ExpectNoError(err)
396+
}
397+
331398
func (j *ServiceTestJig) SanityCheckService(svc *v1.Service, svcType v1.ServiceType) {
332399
if svc.Spec.Type != svcType {
333400
Failf("unexpected Spec.Type (%s) for service, expected %s", svc.Spec.Type, svcType)

0 commit comments

Comments
 (0)