From 1fe7056ffaf636d9d596cd32ba129774dcd9ed74 Mon Sep 17 00:00:00 2001 From: Frank Budinsky Date: Sat, 25 Apr 2020 12:34:24 -0400 Subject: [PATCH] Partial convert mirror test to new model (#7153) Reverted the actual mirror test script, because mirror test seems to have some subtle failure when running with what seems to be the exact same commands via snips. Will investigate further in followup PR. Merging this one to get the generator changes. --- content/en/docs/examples/bookinfo/snips.sh | 3 +- .../mesh/app-health-check/snips.sh | 3 +- .../authentication/mtls-migration/snips.sh | 3 +- .../en/docs/tasks/security/dns-cert/snips.sh | 3 +- .../tasks/security/plugin-ca-cert/snips.sh | 3 +- .../traffic-management/mirroring/index.md | 13 +- .../traffic-management/mirroring/snips.sh | 242 ++++++++++++++++++ .../request-timeouts/snips.sh | 3 +- .../tcp-traffic-shifting/index.md | 3 +- .../tcp-traffic-shifting/snips.sh | 6 +- .../traffic-shifting/snips.sh | 3 +- scripts/snip.py | 3 +- tests/trafficmanagement/mirror_test.go | 15 +- 13 files changed, 264 insertions(+), 39 deletions(-) create mode 100644 content/en/docs/tasks/traffic-management/mirroring/snips.sh diff --git a/content/en/docs/examples/bookinfo/snips.sh b/content/en/docs/examples/bookinfo/snips.sh index 6be931905c..236671ff25 100644 --- a/content/en/docs/examples/bookinfo/snips.sh +++ b/content/en/docs/examples/bookinfo/snips.sh @@ -1,6 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2153 -# shellcheck disable=SC2034 +# shellcheck disable=SC2034,SC2153,SC2155 # Copyright Istio Authors. All Rights Reserved. # diff --git a/content/en/docs/ops/configuration/mesh/app-health-check/snips.sh b/content/en/docs/ops/configuration/mesh/app-health-check/snips.sh index 14ba540ec3..776168a450 100644 --- a/content/en/docs/ops/configuration/mesh/app-health-check/snips.sh +++ b/content/en/docs/ops/configuration/mesh/app-health-check/snips.sh @@ -1,6 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2153 -# shellcheck disable=SC2034 +# shellcheck disable=SC2034,SC2153,SC2155 # Copyright Istio Authors. All Rights Reserved. # diff --git a/content/en/docs/tasks/security/authentication/mtls-migration/snips.sh b/content/en/docs/tasks/security/authentication/mtls-migration/snips.sh index 3a907d1522..81954cc80a 100644 --- a/content/en/docs/tasks/security/authentication/mtls-migration/snips.sh +++ b/content/en/docs/tasks/security/authentication/mtls-migration/snips.sh @@ -1,6 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2153 -# shellcheck disable=SC2034 +# shellcheck disable=SC2034,SC2153,SC2155 # Copyright Istio Authors. All Rights Reserved. # diff --git a/content/en/docs/tasks/security/dns-cert/snips.sh b/content/en/docs/tasks/security/dns-cert/snips.sh index 9df3d0cdfd..e40b6afcc6 100644 --- a/content/en/docs/tasks/security/dns-cert/snips.sh +++ b/content/en/docs/tasks/security/dns-cert/snips.sh @@ -1,6 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2153 -# shellcheck disable=SC2034 +# shellcheck disable=SC2034,SC2153,SC2155 # Copyright Istio Authors. All Rights Reserved. # diff --git a/content/en/docs/tasks/security/plugin-ca-cert/snips.sh b/content/en/docs/tasks/security/plugin-ca-cert/snips.sh index 48b9d751f7..d9852a5d5a 100644 --- a/content/en/docs/tasks/security/plugin-ca-cert/snips.sh +++ b/content/en/docs/tasks/security/plugin-ca-cert/snips.sh @@ -1,6 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2153 -# shellcheck disable=SC2034 +# shellcheck disable=SC2034,SC2153,SC2155 # Copyright Istio Authors. All Rights Reserved. # diff --git a/content/en/docs/tasks/traffic-management/mirroring/index.md b/content/en/docs/tasks/traffic-management/mirroring/index.md index 1b6174ae33..919cb48483 100644 --- a/content/en/docs/tasks/traffic-management/mirroring/index.md +++ b/content/en/docs/tasks/traffic-management/mirroring/index.md @@ -3,6 +3,7 @@ title: Mirroring description: This task demonstrates the traffic mirroring/shadowing capabilities of Istio. weight: 60 keywords: [traffic-management,mirroring] +test: true --- This task demonstrates the traffic mirroring capabilities of Istio. @@ -175,7 +176,7 @@ In this step, you will change that behavior so that all traffic goes to `v1`. {{< text bash json >}} $ export SLEEP_POD=$(kubectl get pod -l app=sleep -o jsonpath={.items..metadata.name}) - $ kubectl exec -it $SLEEP_POD -c sleep -- sh -c 'curl http://httpbin:8000/headers' | python -m json.tool + $ kubectl exec -it "$SLEEP_POD" -c sleep -- sh -c 'curl http://httpbin:8000/headers' | python -m json.tool { "headers": { "Accept": "*/*", @@ -195,13 +196,13 @@ log entries for `v1` and none for `v2`: {{< text bash >}} $ export V1_POD=$(kubectl get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name}) - $ kubectl logs -f $V1_POD -c httpbin + $ kubectl logs -f "$V1_POD" -c httpbin 127.0.0.1 - - [07/Mar/2018:19:02:43 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" {{< /text >}} {{< text bash >}} $ export V2_POD=$(kubectl get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name}) - $ kubectl logs -f $V2_POD -c httpbin + $ kubectl logs -f "$V2_POD" -c httpbin {{< /text >}} @@ -245,20 +246,20 @@ log entries for `v1` and none for `v2`: 1. Send in traffic: {{< text bash >}} - $ kubectl exec -it $SLEEP_POD -c sleep -- sh -c 'curl http://httpbin:8000/headers' | python -m json.tool + $ kubectl exec -it "$SLEEP_POD" -c sleep -- sh -c 'curl http://httpbin:8000/headers' | python -m json.tool {{< /text >}} Now, you should see access logging for both `v1` and `v2`. The access logs created in `v2` are the mirrored requests that are actually going to `v1`. {{< text bash >}} - $ kubectl logs -f $V1_POD -c httpbin + $ kubectl logs -f "$V1_POD" -c httpbin 127.0.0.1 - - [07/Mar/2018:19:02:43 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" 127.0.0.1 - - [07/Mar/2018:19:26:44 +0000] "GET /headers HTTP/1.1" 200 321 "-" "curl/7.35.0" {{< /text >}} {{< text bash >}} - $ kubectl logs -f $V2_POD -c httpbin + $ kubectl logs -f "$V2_POD" -c httpbin 127.0.0.1 - - [07/Mar/2018:19:26:44 +0000] "GET /headers HTTP/1.1" 200 361 "-" "curl/7.35.0" {{< /text >}} diff --git a/content/en/docs/tasks/traffic-management/mirroring/snips.sh b/content/en/docs/tasks/traffic-management/mirroring/snips.sh new file mode 100644 index 0000000000..0aec2671fd --- /dev/null +++ b/content/en/docs/tasks/traffic-management/mirroring/snips.sh @@ -0,0 +1,242 @@ +#!/bin/bash +# shellcheck disable=SC2034,SC2153,SC2155 + +# Copyright Istio Authors. All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#################################################################################################### +# WARNING: THIS IS AN AUTO-GENERATED FILE, DO NOT EDIT. PLEASE MODIFY THE ORIGINAL MARKDOWN FILE: +# docs/tasks/traffic-management/mirroring/index.md +#################################################################################################### + +snip_before_you_begin_1() { +cat < +ENDSNIP + +snip_mirroring_traffic_to_v2_1() { +kubectl apply -f - <}} - $ INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="tcp")].port}') - $ export INGRESS_PORT + $ export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="tcp")].port}') {{< /text >}} Send some TCP traffic to the `tcp-echo` microservice. diff --git a/content/en/docs/tasks/traffic-management/tcp-traffic-shifting/snips.sh b/content/en/docs/tasks/traffic-management/tcp-traffic-shifting/snips.sh index ec21ec571a..fcb74051a2 100644 --- a/content/en/docs/tasks/traffic-management/tcp-traffic-shifting/snips.sh +++ b/content/en/docs/tasks/traffic-management/tcp-traffic-shifting/snips.sh @@ -1,6 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2153 -# shellcheck disable=SC2034 +# shellcheck disable=SC2034,SC2153,SC2155 # Copyright Istio Authors. All Rights Reserved. # @@ -42,8 +41,7 @@ kubectl apply -f samples/tcp-echo/tcp-echo-all-v1.yaml -n istio-io-tcp-traffic-s } snip_apply_weightbased_tcp_routing_6() { -INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="tcp")].port}') -export INGRESS_PORT +export INGRESS_PORT=$(kubectl -n istio-system get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="tcp")].port}') } snip_apply_weightbased_tcp_routing_7() { diff --git a/content/en/docs/tasks/traffic-management/traffic-shifting/snips.sh b/content/en/docs/tasks/traffic-management/traffic-shifting/snips.sh index 01074211aa..c840c23370 100644 --- a/content/en/docs/tasks/traffic-management/traffic-shifting/snips.sh +++ b/content/en/docs/tasks/traffic-management/traffic-shifting/snips.sh @@ -1,6 +1,5 @@ #!/bin/bash -# shellcheck disable=SC2153 -# shellcheck disable=SC2034 +# shellcheck disable=SC2034,SC2153,SC2155 # Copyright Istio Authors. All Rights Reserved. # diff --git a/scripts/snip.py b/scripts/snip.py index da3921fda0..6c518caa0d 100644 --- a/scripts/snip.py +++ b/scripts/snip.py @@ -28,8 +28,7 @@ output_started = False snippets = [] HEADER = """#!/bin/bash -# shellcheck disable=SC2153 -# shellcheck disable=SC2034 +# shellcheck disable=SC2034,SC2153,SC2155 # Copyright Istio Authors. All Rights Reserved. # diff --git a/tests/trafficmanagement/mirror_test.go b/tests/trafficmanagement/mirror_test.go index 268ea518ba..42595df3fd 100644 --- a/tests/trafficmanagement/mirror_test.go +++ b/tests/trafficmanagement/mirror_test.go @@ -38,17 +38,10 @@ func TestMirror(t *testing.T) { Input: istioio.Inline{ FileName: "cleanup.sh", Value: ` -# $snippet remove_rules.sh syntax="bash" -$ kubectl delete virtualservice httpbin -$ kubectl delete destinationrule httpbin -# $endsnippet - -# $snippet remove_httpbin.sh syntax="bash" -$ kubectl delete deploy httpbin-v1 httpbin-v2 sleep -$ kubectl delete svc httpbin -# $endsnippet - -$ kubectl delete ns istio-io-mirror +source ${REPO_ROOT}/content/en/docs/tasks/traffic-management/mirroring/snips.sh +snip_cleaning_up_1 +snip_cleaning_up_2 +kubectl delete ns istio-io-mirror `, }, }).