Skip to content

Commit eceef89

Browse files
committed
Refactor and test description
Signed-off-by: kanishkarj <kanishkarj@hotmail.com>
1 parent 67b6dc8 commit eceef89

10 files changed

Lines changed: 91 additions & 37 deletions

File tree

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ module github.com/layer5/learn-layer5
22

33
go 1.13
44

5-
replace github.com/kudobuilder/kuttl => /home/kanishkarj/Work/layer5io/kuttl
5+
replace github.com/kudobuilder/kuttl => github.com/layer5/kuttl
66

77
require (
88
github.com/kudobuilder/kuttl v0.0.0-00010101000000-000000000000

smi-conformance/test-gen/service-mesh.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@ package test_gen
22

33
import "fmt"
44

5+
// SMIConformance holds the SMI conformance tests
56
type SMIConformance struct {
67
SMObj ServiceMesh
78
}
89

10+
// ServiceMesh provides an abstract interface for different service meshes.
11+
// This is required as each service mesh has different ways to expose their internals.
912
type ServiceMesh interface {
1013
SvcAGetInternalName(string) string
1114
SvcBGetInternalName(string) string
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Traffic Access
2+
3+
Note that the following tests are executed sequentially in an temporarily spawned namespace.
4+
5+
* *01* : Asserts if the TrafficTarget CRD exists.
6+
* *02* : Deploys the app and asserts if the app has been deployed
7+
* *03* : Custom test is run where we verify if by default all traffic is blocked.
8+
* *04* : Create and assert a TrafficTarget which allows traffic from `service-a` to `service-b`.
9+
* *05* : Custom test is run where we verify if traffic from `service-a` to `service-b` succeeds.
10+
* *06* : Deletes the CRDs created in step *04* and asserts its deletion.
11+
* *07* : Custom test to verify if the traffic from `service-a` to `service-b` fails as the CRD has been deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Traffic Spec
2+
3+
Note that the following tests are executed sequentially in an temporarily spawned namespace.
4+
5+
* *01* : Asserts if the HttpRoute group CRD exists.
6+
* *02* : Deploys the app and asserts if the app has been deployed
7+
* *03* : Configures HTTPRouteGroup such that traffic from `service-a` to only `service-b:PORT/metrics` (all HTTP methods) is allowed and the rest is blocked.
8+
* *04* : Custom test which verifies if the above configuration works as intended.
9+
* *05* : Configures the above created HTTPRouteGroup such that traffic from `service-a` to `service-b:PORT/*` (only GET HTTP Method) is allowed and the rest is blocked.
10+
* *06* : Custom test which verifies if the above configuration works as intended.
11+
12+
> We aren't validating TCPRouteGroup CRD here as it has been used in the traffic access tests, so if it is not conformant even TrafficAccess will not be.
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
# TODO fill in the correct spec
2-
# apiVersion: apiextensions.k8s.io/v1
3-
# kind: CustomResourceDefinition
4-
# metadata:
5-
# name: trafficsplit.split.smi-spec.io
6-
# spec:
7-
# group: split.smi-spec.io
8-
# status:
9-
# acceptedNames:
10-
# kind: TrafficSplit
11-
# shortNames:
12-
# - ts
13-
# plural: trafficsplits
14-
# singular: trafficsplit
1+
apiVersion: apiextensions.k8s.io/v1beta1
2+
kind: CustomResourceDefinition
3+
metadata:
4+
name: trafficsplits.split.smi-spec.io
5+
spec:
6+
group: split.smi-spec.io
7+
status:
8+
acceptedNames:
9+
kind: TrafficSplit
10+
shortNames:
11+
- ts
12+
plural: trafficsplits
13+
singular: trafficsplit
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Traffic Access
2+
3+
Note that the following tests are executed sequentially in an temporarily spawned namespace.
4+
5+
* *01* : Asserts if the TrafficSplit CRD exists.
6+
* *02* : Deploys the app and asserts that it is deployed.
7+
* *03* : Custom test which verifies that if in default scenario the traffic to `app-svc` is split randomly between `app-b` and `app-c`.
8+
* *04* : Configure a TrafficSplit CRD such that all traffic to `app-svc` is sent to only `app-b` and none to `app-c`.
9+
* *05* : Custom test which verifies the above scenario.
10+
* *06* : Configure a TrafficSplit CRD such that all traffic to `app-svc` is sent to only `app-c` and none to `app-b`.
11+
* *07* : Custom test which verifies the above scenario.
12+
* *08* : Configure a TrafficSplit CRD such that all traffic to `app-svc` is split between the two such that `app-b` gets more traffic (75%) than `app-c` (25%).
13+
* *09* : Custom test which verifies the above scenario.
14+
* *10* : Configure a TrafficSplit CRD such that all traffic to `app-svc` is split between the two such that `app-b` gets more traffic (25%) than `app-c` (75%).
15+
* *11* : Custom test which verifies the above scenario.

smi-conformance/test-gen/traffic-access.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ import (
1515
func (smi *SMIConformance) TrafficAccessGetTests() map[string]test.CustomTest {
1616
testHandlers := make(map[string]test.CustomTest)
1717

18-
testHandlers["trafficDefault"] = smi.traffic
19-
testHandlers["trafficAllowed"] = smi.allow
20-
testHandlers["trafficBlocked"] = smi.traffic
18+
testHandlers["trafficDefault"] = smi.trafficBlocked
19+
testHandlers["trafficAllowed"] = smi.trafficAllow
20+
testHandlers["trafficBlocked"] = smi.trafficBlocked
2121

2222
return testHandlers
2323
}
2424

25-
func (smi *SMIConformance) traffic(
25+
func (smi *SMIConformance) trafficBlocked(
2626
t *testing.T,
2727
namespace string,
2828
clientFn func(forceNew bool) (client.Client, error),
@@ -41,6 +41,7 @@ func (smi *SMIConformance) traffic(
4141

4242
ClearAllMetrics(clusterIPs, smi.SMObj)
4343

44+
// This test will make SERVICE A make a request to SERVICE B
4445
svcBTestURL := fmt.Sprintf("%s/%s", smi.SMObj.SvcBGetInternalName(namespace), ECHO)
4546
var jsonStr = []byte(`{"url":"` + svcBTestURL + `", "body":"", "method": "GET", "headers": {}}`)
4647

@@ -64,8 +65,9 @@ func (smi *SMIConformance) traffic(
6465

6566
Logger.Log("Service A : Response Failed", metricsSvcA.RespFailed)
6667
Logger.Log("Service A : Response Succeeded", metricsSvcA.RespSucceeded)
67-
Logger.Log("Service A : Requests Recieved", metricsSvcA.ReqReceived)
68+
Logger.Log("Service A : Requests Received", metricsSvcA.ReqReceived)
6869

70+
// Validates if the request failed
6971
if !(len(metricsSvcA.RespFailed) == 1 && len(metricsSvcA.RespSucceeded) == 0) {
7072
t.Fail()
7173
return nil
@@ -81,7 +83,7 @@ func (smi *SMIConformance) traffic(
8183
return nil
8284
}
8385

84-
func (smi *SMIConformance) allow(
86+
func (smi *SMIConformance) trafficAllow(
8587
t *testing.T,
8688
namespace string,
8789
clientFn func(forceNew bool) (client.Client, error),
@@ -101,6 +103,7 @@ func (smi *SMIConformance) allow(
101103

102104
ClearAllMetrics(clusterIPs, smi.SMObj)
103105

106+
// This test will make SERVICE A make a request to SERVICE B
104107
svcBTestURL := fmt.Sprintf("%s/%s", smi.SMObj.SvcBGetInternalName(namespace), ECHO)
105108
var jsonStr = []byte(`{"url":"` + svcBTestURL + `", "body":"", "method": "GET", "headers": {}}`)
106109

@@ -125,8 +128,9 @@ func (smi *SMIConformance) allow(
125128

126129
Logger.Log("Service A : Response Failed", metricsSvcA.RespFailed)
127130
Logger.Log("Service A : Response Succeeded", metricsSvcA.RespSucceeded)
128-
Logger.Log("Service A : Requests Recieved", metricsSvcA.ReqReceived)
131+
Logger.Log("Service A : Requests Received", metricsSvcA.ReqReceived)
129132

133+
// Validates if the request succeeded
130134
if !(len(metricsSvcA.RespFailed) == 0 && len(metricsSvcA.RespSucceeded) == 1) {
131135
t.Fail()
132136
return nil
@@ -148,7 +152,7 @@ func (smi *SMIConformance) allow(
148152

149153
Logger.Log("Service B : Response Failed", metricsSvcB.RespFailed)
150154
Logger.Log("Service B : Response Succeeded", metricsSvcB.RespSucceeded)
151-
Logger.Log("Service B : Requests Recieved", metricsSvcB.ReqReceived)
155+
Logger.Log("Service B : Requests Received", metricsSvcB.ReqReceived)
152156

153157
if !(len(metricsSvcB.ReqReceived) == 1) {
154158
t.Fail()

smi-conformance/test-gen/traffic-spec.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (smi *SMIConformance) trafficPath(
4141

4242
ClearAllMetrics(clusterIPs, smi.SMObj)
4343

44-
// call to metrics (allowed)
44+
// call to SERVICE B metrics (allowed)
4545
svcBTestURLMetrics := fmt.Sprintf("%s/%s", smi.SMObj.SvcBGetInternalName(namespace), METRICS)
4646
jsonStr := []byte(`{"url":"` + svcBTestURLMetrics + `", "body":"", "method": "GET", "headers": {}}`)
4747

@@ -56,7 +56,7 @@ func (smi *SMIConformance) trafficPath(
5656
return []error{err}
5757
}
5858

59-
// call to echo (blocked)
59+
// call to SERVICE B echo (blocked)
6060
svcBTestURLEcho := fmt.Sprintf("%s/%s", smi.SMObj.SvcBGetInternalName(namespace), ECHO)
6161
jsonStr = []byte(`{"url":"` + svcBTestURLEcho + `", "body":"", "method": "GET", "headers": {}}`)
6262

@@ -79,6 +79,7 @@ func (smi *SMIConformance) trafficPath(
7979
Logger.Log("Service A : Response Succeeded", metricsSvcA.RespSucceeded)
8080
Logger.Log("Service A : Requests Received", metricsSvcA.ReqReceived)
8181

82+
// validates the requests that failed and the ones that succeeded
8283
if !(len(metricsSvcA.RespFailed) == 1 && len(metricsSvcA.RespSucceeded) == 1) {
8384
t.Fail()
8485
return nil
@@ -156,8 +157,9 @@ func (smi *SMIConformance) trafficMethod(
156157

157158
Logger.Log("Service A : Response Failed", metricsSvcA.RespFailed)
158159
Logger.Log("Service A : Response Succeeded", metricsSvcA.RespSucceeded)
159-
Logger.Log("Service A : Requests Recieved", metricsSvcA.ReqReceived)
160+
Logger.Log("Service A : Requests Received", metricsSvcA.ReqReceived)
160161

162+
// validates the requests that failed and the ones that succeeded
161163
if !(len(metricsSvcA.RespFailed) == 1 && len(metricsSvcA.RespSucceeded) == 1) {
162164
t.Fail()
163165
return nil

smi-conformance/test-gen/traffic-split.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"sigs.k8s.io/controller-runtime/pkg/client"
1212
)
1313

14-
const reqNo = 20
14+
const reqNo = 50
1515

1616
func (smi *SMIConformance) TrafficSplitGetTests() map[string]test.CustomTest {
1717
testHandlers := make(map[string]test.CustomTest)
@@ -25,6 +25,7 @@ func (smi *SMIConformance) TrafficSplitGetTests() map[string]test.CustomTest {
2525
return testHandlers
2626
}
2727

28+
// Executes a Test Scenario where SERVICE A makes a request to the service named `app-svc`
2829
func trafficSplitTestScenario(clusterIPs map[string]string, namespace string, smObj ServiceMesh) error {
2930
svcTrafficSplit := fmt.Sprintf("http://app-svc.%s.svc.cluster.local.:9091/%s", namespace, ECHO)
3031
jsonStr := []byte(`{"url":"` + svcTrafficSplit + `", "body":"", "method": "GET", "headers": {}}`)
@@ -62,14 +63,14 @@ func (smi *SMIConformance) trafficSplitDefault(
6263
t.Fail()
6364
return []error{err}
6465
}
65-
Logger.Log("Service B : Requests Recieved", metricsSvcB.ReqReceived)
66+
Logger.Log("Service B : Requests Received", metricsSvcB.ReqReceived)
6667

6768
metricsSvcC, err := GetMetrics(clusterIPs[SERVICE_C_NAME], "9091")
6869
if err != nil {
6970
t.Fail()
7071
return []error{err}
7172
}
72-
Logger.Log("Service C : Requests Recieved", metricsSvcC.ReqReceived)
73+
Logger.Log("Service C : Requests Received", metricsSvcC.ReqReceived)
7374

7475
if len(metricsSvcB.ReqReceived) == 0 || len(metricsSvcC.ReqReceived) == 0 {
7576
t.Fail()
@@ -109,14 +110,14 @@ func (smi *SMIConformance) trafficSplitOnlyB(
109110
t.Fail()
110111
return []error{err}
111112
}
112-
Logger.Log("Service B : Requests Recieved", metricsSvcB.ReqReceived)
113+
Logger.Log("Service B : Requests Received", metricsSvcB.ReqReceived)
113114

114115
metricsSvcC, err := GetMetrics(clusterIPs[SERVICE_C_NAME], "9091")
115116
if err != nil {
116117
t.Fail()
117118
return []error{err}
118119
}
119-
Logger.Log("Service C : Requests Recieved", metricsSvcC.ReqReceived)
120+
Logger.Log("Service C : Requests Received", metricsSvcC.ReqReceived)
120121

121122
if !(len(metricsSvcB.ReqReceived) == reqNo && len(metricsSvcC.ReqReceived) == 0) {
122123
t.Fail()
@@ -156,14 +157,14 @@ func (smi *SMIConformance) trafficSplitOnlyC(
156157
t.Fail()
157158
return []error{err}
158159
}
159-
Logger.Log("Service B : Requests Recieved", metricsSvcB.ReqReceived)
160+
Logger.Log("Service B : Requests Received", metricsSvcB.ReqReceived)
160161

161162
metricsSvcC, err := GetMetrics(clusterIPs[SERVICE_C_NAME], "9091")
162163
if err != nil {
163164
t.Fail()
164165
return []error{err}
165166
}
166-
Logger.Log("Service C : Requests Recieved", metricsSvcC.ReqReceived)
167+
Logger.Log("Service C : Requests Received", metricsSvcC.ReqReceived)
167168

168169
if !(len(metricsSvcB.ReqReceived) == 0 && len(metricsSvcC.ReqReceived) == reqNo) {
169170
t.Fail()
@@ -203,14 +204,14 @@ func (smi *SMIConformance) trafficSplitBGrtC(
203204
t.Fail()
204205
return []error{err}
205206
}
206-
Logger.Log("Service B : Requests Recieved", metricsSvcB.ReqReceived)
207+
Logger.Log("Service B : Requests Received", metricsSvcB.ReqReceived)
207208

208209
metricsSvcC, err := GetMetrics(clusterIPs[SERVICE_C_NAME], "9091")
209210
if err != nil {
210211
t.Fail()
211212
return []error{err}
212213
}
213-
Logger.Log("Service C : Requests Recieved", metricsSvcC.ReqReceived)
214+
Logger.Log("Service C : Requests Received", metricsSvcC.ReqReceived)
214215

215216
if !(len(metricsSvcB.ReqReceived) > len(metricsSvcC.ReqReceived)) {
216217
t.Fail()
@@ -250,14 +251,14 @@ func (smi *SMIConformance) trafficSplitCGrtB(
250251
t.Fail()
251252
return []error{err}
252253
}
253-
Logger.Log("Service B : Requests Recieved", metricsSvcB.ReqReceived)
254+
Logger.Log("Service B : Requests Received", metricsSvcB.ReqReceived)
254255

255256
metricsSvcC, err := GetMetrics(clusterIPs[SERVICE_C_NAME], "9091")
256257
if err != nil {
257258
t.Fail()
258259
return []error{err}
259260
}
260-
Logger.Log("Service C : Requests Recieved", metricsSvcC.ReqReceived)
261+
Logger.Log("Service C : Requests Received", metricsSvcC.ReqReceived)
261262

262263
if !(len(metricsSvcB.ReqReceived) < len(metricsSvcC.ReqReceived)) {
263264
t.Fail()

smi-conformance/test-gen/utils.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,35 @@ import (
1414
"sigs.k8s.io/controller-runtime/pkg/client"
1515
)
1616

17+
// App service names
1718
const (
1819
SERVICE_A_NAME = "app-a"
1920
SERVICE_B_NAME = "app-b"
2021
SERVICE_C_NAME = "app-c"
2122
)
2223

24+
// App API endpoints
2325
const (
2426
METRICS = "metrics"
2527
CALL = "call"
2628
ECHO = "echo"
2729
)
2830

31+
// URLstruct is a part of the metrics exposed by the app
2932
type URLstruct struct {
3033
URL string
3134
Method string
3235
Headers map[string]string
3336
}
37+
38+
// MetricResponse is a part of the metrics exposed by the app
3439
type MetricResponse struct {
3540
ReqReceived []string
3641
RespSucceeded []URLstruct
3742
RespFailed []URLstruct
3843
}
3944

45+
// GetClusterIPs returns the ClusterIPs of various services exposed in the namespace
4046
func GetClusterIPs(kubeClient client.Client, namespace string) (map[string]string, error) {
4147
deps := &v1.ServiceList{}
4248
err := kubeClient.List(context.TODO(), deps, client.InNamespace(namespace))
@@ -50,6 +56,7 @@ func GetClusterIPs(kubeClient client.Client, namespace string) (map[string]strin
5056
return ipMap, nil
5157
}
5258

59+
// GetHTTPClient returns a configured HTTP client
5360
func GetHTTPClient() http.Client {
5461
return http.Client{
5562
Timeout: 30 * time.Second,

0 commit comments

Comments
 (0)