Skip to content

Commit

Permalink
Evaluate all services targeted by a TrafficTarget even if one of them…
Browse files Browse the repository at this point in the history
… already has a TrafficSplit
  • Loading branch information
jspdown authored Jul 16, 2020
1 parent e7ab8e5 commit 61da9e9
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pkg/topology/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (b *Builder) evaluateTrafficTarget(res *resources, topology *Topology, tt *
if ok && len(svc.TrafficSplits) > 0 {
b.logger.Warnf("Service %q already has a TrafficSplit attached, TrafficTarget %q will not be evaluated on this service", svcKey, svcTTKey.TrafficTarget)

return
continue
}

topology.ServiceTrafficTargets[svcTTKey] = stt
Expand Down
20 changes: 12 additions & 8 deletions pkg/topology/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,8 @@ func TestTopologyBuilder_BuildWithTrafficTarget(t *testing.T) {
// a service if there is already a TrafficSplit applied to it.
func TestTopologyBuilder_BuildWithTrafficTargetAndTrafficSplitOnSameService(t *testing.T) {
selectorAppA := map[string]string{"app": "app-a"}
selectorAppB := map[string]string{"app": "app-b"}
selectorAppB1 := map[string]string{"app": "app-b1"}
selectorAppB2 := map[string]string{"app": "app-b2"}
selectorAppC := map[string]string{"app": "app-c"}
selectorAppD := map[string]string{"app": "app-d"}
annotations := map[string]string{
Expand All @@ -350,8 +351,10 @@ func TestTopologyBuilder_BuildWithTrafficTargetAndTrafficSplitOnSameService(t *t
podA := createPod("my-ns", "app-a", saA, selectorAppA, "10.10.1.1")

saB := createServiceAccount("my-ns", "service-account-b")
svcB := createService("my-ns", "svc-b", annotations, svcPorts, selectorAppB, "10.10.1.16")
podB := createPod("my-ns", "app-b", saB, svcB.Spec.Selector, "10.10.2.1")
svcB1 := createService("my-ns", "svc-b1", annotations, svcPorts, selectorAppB1, "10.10.1.16")
podB1 := createPod("my-ns", "app-b1", saB, svcB1.Spec.Selector, "10.10.2.1")
svcB2 := createService("my-ns", "svc-b2", annotations, svcPorts, selectorAppB2, "10.10.3.16")
podB2 := createPod("my-ns", "app-b2", saB, svcB2.Spec.Selector, "10.10.3.1")

saC := createServiceAccount("my-ns", "service-account-c")
svcC := createService("my-ns", "svc-c", annotations, svcPorts, selectorAppC, "10.10.1.17")
Expand All @@ -361,7 +364,8 @@ func TestTopologyBuilder_BuildWithTrafficTargetAndTrafficSplitOnSameService(t *t
svcD := createService("my-ns", "svc-d", annotations, svcPorts, selectorAppD, "10.10.1.18")
podD := createPod("my-ns", "app-d", saD, svcD.Spec.Selector, "10.10.2.3")

epB := createEndpoints(svcB, createEndpointSubset(svcPorts, podB))
epB1 := createEndpoints(svcB1, createEndpointSubset(svcPorts, podB1))
epB2 := createEndpoints(svcB2, createEndpointSubset(svcPorts, podB2))
epC := createEndpoints(svcC, createEndpointSubset(svcPorts, podC))
epD := createEndpoints(svcD, createEndpointSubset(svcPorts, podD))

Expand All @@ -371,12 +375,12 @@ func TestTopologyBuilder_BuildWithTrafficTargetAndTrafficSplitOnSameService(t *t

ttMatch := []string{apiMatch.Name}
tt := createTrafficTarget("my-ns", "tt", saB, "8080", []*corev1.ServiceAccount{saA}, rtGrp, ttMatch)
ts := createTrafficSplit("my-ns", "ts", svcB, svcC, svcD)
ts := createTrafficSplit("my-ns", "ts", svcB1, svcC, svcD)

k8sClient := fake.NewSimpleClientset(saA, saB, saC, saD,
podA, podB, podC, podD,
svcB, svcC, svcD,
epB, epC, epD)
podA, podB1, podB2, podC, podD,
svcB1, svcB2, svcC, svcD,
epB1, epB2, epC, epD)
smiAccessClient := accessfake.NewSimpleClientset(tt)
smiSplitClient := splitfake.NewSimpleClientset(ts)
smiSpecClient := specfake.NewSimpleClientset(rtGrp)
Expand Down
128 changes: 119 additions & 9 deletions pkg/topology/testdata/topology-traffic-split-traffic-target.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"services": {
"svc-b@my-ns": {
"name": "svc-b",
"svc-b1@my-ns": {
"name": "svc-b1",
"namespace": "my-ns",
"selector": {
"app": "app-b"
"app": "app-b1"
},
"annotations": {
"maesh.containo.us/ratelimit-average": "100",
Expand All @@ -21,12 +21,39 @@
],
"clusterIp": "10.10.1.16",
"pods": [
"app-b@my-ns"
"app-b1@my-ns"
],
"trafficSplits": [
"ts@my-ns"
]
},
"svc-b2@my-ns": {
"name": "svc-b2",
"namespace": "my-ns",
"selector": {
"app": "app-b2"
},
"annotations": {
"maesh.containo.us/ratelimit-average": "100",
"maesh.containo.us/ratelimit-burst": "200",
"maesh.containo.us/traffic-type": "http"
},
"ports": [
{
"name": "port-8080",
"protocol": "TCP",
"port": 8080,
"targetPort": 8080
}
],
"clusterIp": "10.10.3.16",
"pods": [
"app-b2@my-ns"
],
"trafficTargets": [
"svc-b2@my-ns:tt@my-ns"
]
},
"svc-c@my-ns": {
"name": "svc-c",
"namespace": "my-ns",
Expand Down Expand Up @@ -87,14 +114,26 @@
"name": "app-a",
"namespace": "my-ns",
"serviceAccount": "service-account-a",
"ip": "10.10.1.1"
"ip": "10.10.1.1",
"sourceOf": [
"svc-b2@my-ns:tt@my-ns"
]
},
"app-b@my-ns": {
"name": "app-b",
"app-b1@my-ns": {
"name": "app-b1",
"namespace": "my-ns",
"serviceAccount": "service-account-b",
"ip": "10.10.2.1"
},
"app-b2@my-ns": {
"name": "app-b2",
"namespace": "my-ns",
"serviceAccount": "service-account-b",
"ip": "10.10.3.1",
"destinationOf": [
"svc-b2@my-ns:tt@my-ns"
]
},
"app-c@my-ns": {
"name": "app-c",
"namespace": "my-ns",
Expand All @@ -108,12 +147,83 @@
"ip": "10.10.2.3"
}
},
"serviceTrafficTargets": {},
"serviceTrafficTargets": {
"svc-b2@my-ns:tt@my-ns": {
"service": "svc-b2@my-ns",
"name": "tt",
"namespace": "my-ns",
"sources": [
{
"serviceAccount": "service-account-a",
"namespace": "my-ns",
"pods": [
"app-a@my-ns"
]
}
],
"destination": {
"serviceAccount": "service-account-b",
"namespace": "my-ns",
"ports": [
{
"name": "port-8080",
"protocol": "TCP",
"port": 8080,
"targetPort": 8080
}
],
"pods": [
"app-b2@my-ns"
]
},
"specs": [
{
"httpRouteGroup": {
"kind": "HTTPRouteGroup",
"apiVersion": "specs.smi-spec.io/v1alpha1",
"metadata": {
"name": "http-rt-grp",
"namespace": "my-ns",
"creationTimestamp": null
},
"matches": [
{
"name": "api",
"methods": [
"GET",
"POST"
],
"pathRegex": "/api"
},
{
"name": "metric",
"methods": [
"GET"
],
"pathRegex": "/metric"
}
]
},
"httpMatches": [
{
"name": "api",
"methods": [
"GET",
"POST"
],
"pathRegex": "/api"
}
]
}
],
"errors": null
}
},
"trafficSplits": {
"ts@my-ns": {
"name": "ts",
"namespace": "my-ns",
"service": "svc-b@my-ns",
"service": "svc-b1@my-ns",
"backends": [
{
"weight": 80,
Expand Down

0 comments on commit 61da9e9

Please sign in to comment.