From 591afce365c43cd6ca1f829ea72f03848c29a4ad Mon Sep 17 00:00:00 2001 From: Naveen Jain Date: Tue, 9 Jun 2020 16:07:20 +0530 Subject: [PATCH 1/2] Added support to check for CRDs Signed-off-by: Naveen Jain --- README.md | 8 +++++++ smi-test/trafficAccess/00-assert.yaml | 14 ++++++++++++ smi-test/trafficSpecs/00-assert.yaml | 32 +++++++++++++++++++++++++++ smi-test/trafficSplit/00-assert.yaml | 15 +++++++++++++ 4 files changed, 69 insertions(+) create mode 100644 smi-test/trafficAccess/00-assert.yaml create mode 100644 smi-test/trafficSpecs/00-assert.yaml create mode 100644 smi-test/trafficSplit/00-assert.yaml diff --git a/README.md b/README.md index bf8ee81..a28e5b9 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,13 @@ # learn-layer5 +# To check for smi conformance of a deployed service mesh +We use kuttl to check for SMI conformance. All the tests are writtten in smi-test directory of this repository. +Execute the following command to run the smi-conformace tests:- + +```shell +kubectl kuttl test --skip-cluster-delete=true --start-kind=false ./smi-test +``` + ## Service The following are the routes defined by the `service` app and their functionality. diff --git a/smi-test/trafficAccess/00-assert.yaml b/smi-test/trafficAccess/00-assert.yaml new file mode 100644 index 0000000..30e87f7 --- /dev/null +++ b/smi-test/trafficAccess/00-assert.yaml @@ -0,0 +1,14 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: traffictargets.access.smi-spec.io +spec: + group: access.smi-spec.io +status: + acceptedNames: + kind: TrafficTarget + shortNames: + - tt + plural: traffictargets + singular: traffictarget + diff --git a/smi-test/trafficSpecs/00-assert.yaml b/smi-test/trafficSpecs/00-assert.yaml new file mode 100644 index 0000000..dce1376 --- /dev/null +++ b/smi-test/trafficSpecs/00-assert.yaml @@ -0,0 +1,32 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: httproutegroups.specs.smi-spec.io +spec: + group: specs.smi-spec.io + scope: Namespaced +status: + acceptedNames: + kind: HTTPRouteGroup + shortNames: + - htr + plural: httproutegroups + singular: httproutegroup + +--- + +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: tcproutes.specs.smi-spec.io +spec: + group: specs.smi-spec.io + scope: Namespaced +status: + acceptedNames: + kind: TCPRoute + shortNames: + - tr + plural: tcproutes + singular: tcproute + diff --git a/smi-test/trafficSplit/00-assert.yaml b/smi-test/trafficSplit/00-assert.yaml new file mode 100644 index 0000000..cdb1401 --- /dev/null +++ b/smi-test/trafficSplit/00-assert.yaml @@ -0,0 +1,15 @@ +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: trafficsplits.split.smi-spec.io +spec: + group: split.smi-spec.io + scope: Namespaced +status: + acceptedNames: + kind: TrafficSplit + listKind: TrafficSplitList + plural: trafficsplits + singular: trafficsplit + shortNames: + - ts From 76ab46ea267fdf94e7ebb89e714fba218dbe2fc6 Mon Sep 17 00:00:00 2001 From: Naveen Jain Date: Tue, 9 Jun 2020 18:46:51 +0530 Subject: [PATCH 2/2] Traffic access v0 Signed-off-by: Naveen Jain --- deploy/k8s.yaml | 3 - smi-test/trafficAccess/01-assert.yaml | 125 +++++++++++++++++++++++++ smi-test/trafficAccess/01-install.yaml | 110 ++++++++++++++++++++++ smi-test/trafficAccess/02-traffic.yaml | 9 ++ smi-test/trafficAccess/execThis.sh | 7 ++ 5 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 smi-test/trafficAccess/01-assert.yaml create mode 100644 smi-test/trafficAccess/01-install.yaml create mode 100644 smi-test/trafficAccess/02-traffic.yaml create mode 100755 smi-test/trafficAccess/execThis.sh diff --git a/deploy/k8s.yaml b/deploy/k8s.yaml index 32084db..0ef75ed 100644 --- a/deploy/k8s.yaml +++ b/deploy/k8s.yaml @@ -13,7 +13,6 @@ spec: metadata: labels: app: app-a - annotations: spec: containers: - name: app-a @@ -37,7 +36,6 @@ spec: metadata: labels: app: app-b - annotations: spec: containers: - name: app-b @@ -61,7 +59,6 @@ spec: metadata: labels: app: app-c - annotations: spec: containers: - name: app-c diff --git a/smi-test/trafficAccess/01-assert.yaml b/smi-test/trafficAccess/01-assert.yaml new file mode 100644 index 0000000..ca3552d --- /dev/null +++ b/smi-test/trafficAccess/01-assert.yaml @@ -0,0 +1,125 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-a + labels: + app: app-a +spec: + replicas: 1 + selector: + matchLabels: + app: app-a + template: + metadata: + labels: + app: app-a + spec: + containers: + - name: app-a + image: layer5/sample-app-service:dev + imagePullPolicy: Never + ports: + - containerPort: 9091 +status: + availableReplicas: 1 + readyReplicas: 1 + replicas: 1 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-b + labels: + app: app-b +spec: + replicas: 1 + selector: + matchLabels: + app: app-b + template: + metadata: + labels: + app: app-b + spec: + containers: + - name: app-b + image: layer5/sample-app-service:dev + imagePullPolicy: Never + ports: + - containerPort: 9091 +status: + availableReplicas: 1 + readyReplicas: 1 + replicas: 1 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-c + labels: + app: app-c +spec: + replicas: 1 + selector: + matchLabels: + app: app-c + template: + metadata: + labels: + app: app-c + spec: + containers: + - name: app-c + image: layer5/sample-app-service:dev + imagePullPolicy: Never + ports: + - containerPort: 9091 +status: + availableReplicas: 1 + readyReplicas: 1 + replicas: 1 + +--- +apiVersion: v1 +kind: Service +metadata: + name: service-a +spec: + type: NodePort + selector: + app: app-a + ports: + - name: http + protocol: TCP + port: 9091 + targetPort: 9091 +--- +apiVersion: v1 +kind: Service +metadata: + name: service-b +spec: + type: ClusterIP + selector: + app: app-b + ports: + - name: http + protocol: TCP + port: 9091 + targetPort: 9091 +--- +apiVersion: v1 +kind: Service +metadata: + name: service-c +spec: + type: ClusterIP + selector: + app: app-c + ports: + - name: http + protocol: TCP + port: 9091 + targetPort: 9091 diff --git a/smi-test/trafficAccess/01-install.yaml b/smi-test/trafficAccess/01-install.yaml new file mode 100644 index 0000000..0ef75ed --- /dev/null +++ b/smi-test/trafficAccess/01-install.yaml @@ -0,0 +1,110 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-a + labels: + app: app-a +spec: + replicas: 1 + selector: + matchLabels: + app: app-a + template: + metadata: + labels: + app: app-a + spec: + containers: + - name: app-a + image: layer5/sample-app-service:dev + imagePullPolicy: Never + ports: + - containerPort: 9091 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-b + labels: + app: app-b +spec: + replicas: 1 + selector: + matchLabels: + app: app-b + template: + metadata: + labels: + app: app-b + spec: + containers: + - name: app-b + image: layer5/sample-app-service:dev + imagePullPolicy: Never + ports: + - containerPort: 9091 +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: app-c + labels: + app: app-c +spec: + replicas: 1 + selector: + matchLabels: + app: app-c + template: + metadata: + labels: + app: app-c + spec: + containers: + - name: app-c + image: layer5/sample-app-service:dev + imagePullPolicy: Never + ports: + - containerPort: 9091 +--- +apiVersion: v1 +kind: Service +metadata: + name: service-a +spec: + type: NodePort + selector: + app: app-a + ports: + - name: http + protocol: TCP + port: 9091 + targetPort: 9091 +--- +apiVersion: v1 +kind: Service +metadata: + name: service-b +spec: + type: ClusterIP + selector: + app: app-b + ports: + - name: http + protocol: TCP + port: 9091 + targetPort: 9091 +--- +apiVersion: v1 +kind: Service +metadata: + name: service-c +spec: + type: ClusterIP + selector: + app: app-c + ports: + - name: http + protocol: TCP + port: 9091 + targetPort: 9091 diff --git a/smi-test/trafficAccess/02-traffic.yaml b/smi-test/trafficAccess/02-traffic.yaml new file mode 100644 index 0000000..d0a9078 --- /dev/null +++ b/smi-test/trafficAccess/02-traffic.yaml @@ -0,0 +1,9 @@ +apiVersion: kudo.dev/v1alpha1 +kind: TestStep +delete: +- apiVersion: v1 + kind: Pod + name: my-pod +commands: +- command: chmod +x ./execThis.sh +- command: sh ./execThis.sh \ No newline at end of file diff --git a/smi-test/trafficAccess/execThis.sh b/smi-test/trafficAccess/execThis.sh new file mode 100755 index 0000000..db67625 --- /dev/null +++ b/smi-test/trafficAccess/execThis.sh @@ -0,0 +1,7 @@ + +echo $(kubectl get service service-a --namespace=$NAMESPACE -o jsonpath="{.spec.ports[0].nodePort}") +kubectl describe pods --namespace=$NAMESPACE +curl --location --request POST 'http://localhost:'$(echo $(kubectl get service service-a --namespace=$NAMESPACE -o jsonpath="{.spec.ports[0].nodePort}"))'/call' -w "%{http_code}" --data-raw '{"host": "http://service-b/post",}' + + +curl --location --request GET 'localhost:'$(echo $(kubectl get service service-a --namespace=$NAMESPACE -o jsonpath="{.spec.ports[0].nodePort}"))'/metrics' --header 'Content-Type: application/json' --data-raw '{"hello": "bye"}' \ No newline at end of file