Cleanup mirroring test (#7387)

* Cleanup mirroring test

* sleep

* fix mtls-migr cleanup

* debug

* debug2

* debug3

* debug4
This commit is contained in:
Frank Budinsky 2020-05-24 17:35:09 -04:00 committed by GitHub
parent 6581b52325
commit 4e0103110d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 81 additions and 243 deletions

View File

@ -176,17 +176,19 @@ 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 "${SLEEP_POD}" -c sleep -- curl -s http://httpbin:8000/headers
{
"headers": {
"Accept": "*/*",
"Content-Length": "0",
"Host": "httpbin:8000",
"User-Agent": "curl/7.35.0",
"X-B3-Parentspanid": "57784f8bff90ae0b",
"X-B3-Sampled": "1",
"X-B3-Spanid": "eca3d7ed8f2e6a0a",
"X-B3-Traceid": "eca3d7ed8f2e6a0a",
"X-Ot-Span-Context": "eca3d7ed8f2e6a0a;eca3d7ed8f2e6a0a;0000000000000000"
"X-B3-Spanid": "3289ae7257c3f159",
"X-B3-Traceid": "b56eebd279a76f0b57784f8bff90ae0b",
"X-Envoy-Attempt-Count": "1",
"X-Forwarded-Client-Cert": "By=spiffe://cluster.local/ns/default/sa/default;Hash=20afebed6da091c850264cc751b8c9306abac02993f80bdb76282237422bd098;Subject=\"\";URI=spiffe://cluster.local/ns/default/sa/default"
}
}
{{< /text >}}
@ -246,7 +248,7 @@ 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 "${SLEEP_POD}" -c sleep -- curl -s http://httpbin:8000/headers
{{< /text >}}
Now, you should see access logging for both `v1` and `v2`. The access logs

View File

@ -152,7 +152,7 @@ EOF
snip_creating_a_default_routing_policy_2() {
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 "${SLEEP_POD}" -c sleep -- curl -s http://httpbin:8000/headers
}
! read -r -d '' snip_creating_a_default_routing_policy_2_out <<\ENDSNIP
@ -162,10 +162,12 @@ kubectl exec -it "$SLEEP_POD" -c sleep -- sh -c 'curl http://httpbin:8000/heade
"Content-Length": "0",
"Host": "httpbin:8000",
"User-Agent": "curl/7.35.0",
"X-B3-Parentspanid": "57784f8bff90ae0b",
"X-B3-Sampled": "1",
"X-B3-Spanid": "eca3d7ed8f2e6a0a",
"X-B3-Traceid": "eca3d7ed8f2e6a0a",
"X-Ot-Span-Context": "eca3d7ed8f2e6a0a;eca3d7ed8f2e6a0a;0000000000000000"
"X-B3-Spanid": "3289ae7257c3f159",
"X-B3-Traceid": "b56eebd279a76f0b57784f8bff90ae0b",
"X-Envoy-Attempt-Count": "1",
"X-Forwarded-Client-Cert": "By=spiffe://cluster.local/ns/default/sa/default;Hash=20afebed6da091c850264cc751b8c9306abac02993f80bdb76282237422bd098;Subject=\"\";URI=spiffe://cluster.local/ns/default/sa/default"
}
}
ENDSNIP
@ -211,7 +213,7 @@ EOF
}
snip_mirroring_traffic_to_v2_2() {
kubectl exec -it "$SLEEP_POD" -c sleep -- sh -c 'curl http://httpbin:8000/headers' | python -m json.tool
kubectl exec "${SLEEP_POD}" -c sleep -- curl -s http://httpbin:8000/headers
}
snip_mirroring_traffic_to_v2_3() {

View File

@ -56,6 +56,7 @@ snip_set_up_the_cluster_2`,
FileName: "cleanup.sh",
Value: `
source ${REPO_ROOT}/content/en/docs/tasks/security/authentication/mtls-migration/snips.sh
snip_clean_up_the_example_1
snip_clean_up_the_example_2`,
},
}).

View File

@ -22,17 +22,12 @@ import (
"istio.io/istio.io/pkg/test/istioio"
)
// https://preliminary.istio.io/docs/tasks/traffic-management/mirroring/
func TestMirror(t *testing.T) {
func TestMirroring(t *testing.T) {
framework.
NewTest(t).
Run(istioio.NewBuilder("tasks__traffic_management__mirroring").
Add(istioio.Script{
Input: istioio.Path("scripts/mirror_deploy.txt"),
}).
Add(istioio.MultiPodWait("istio-io-mirror")).
Add(istioio.Script{
Input: istioio.Path("scripts/mirror_traffic.txt"),
Input: istioio.Path("scripts/mirroring.sh"),
}).
Defer(istioio.Script{
Input: istioio.Inline{
@ -41,7 +36,6 @@ func TestMirror(t *testing.T) {
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
`,
},
}).

View File

@ -1,152 +0,0 @@
#!/usr/bin/env bash
# Copyright Istio Authors
#
# 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.
set -e
set -u
set -o pipefail
# TODO: This test is currently not using the snips because they use the default namespace and for some TBD reason
# the test fails to complete when running these exact same commands in default, instead of istio-io-mirror.
kubectl create ns istio-io-mirror
# snip_before_you_begin_1
cat <<EOF | istioctl kube-inject -f - | kubectl -n istio-io-mirror create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpbin-v1
spec:
replicas: 1
selector:
matchLabels:
app: httpbin
version: v1
template:
metadata:
labels:
app: httpbin
version: v1
spec:
containers:
- image: docker.io/kennethreitz/httpbin
imagePullPolicy: IfNotPresent
name: httpbin
command: ["gunicorn", "--access-logfile", "-", "-b", "0.0.0.0:80", "httpbin:app"]
ports:
- containerPort: 80
EOF
# snip_before_you_begin_2
cat <<EOF | istioctl kube-inject -f - | kubectl -n istio-io-mirror create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: httpbin-v2
spec:
replicas: 1
selector:
matchLabels:
app: httpbin
version: v2
template:
metadata:
labels:
app: httpbin
version: v2
spec:
containers:
- image: docker.io/kennethreitz/httpbin
imagePullPolicy: IfNotPresent
name: httpbin
command: ["gunicorn", "--access-logfile", "-", "-b", "0.0.0.0:80", "httpbin:app"]
ports:
- containerPort: 80
EOF
# snip_before_you_begin_3
kubectl -n istio-io-mirror create -f - <<EOF
apiVersion: v1
kind: Service
metadata:
name: httpbin
labels:
app: httpbin
spec:
ports:
- name: http
port: 8000
targetPort: 80
selector:
app: httpbin
EOF
# snip_before_you_begin_4
cat <<EOF | istioctl kube-inject -f - | kubectl -n istio-io-mirror create -f -
apiVersion: apps/v1
kind: Deployment
metadata:
name: sleep
spec:
replicas: 1
selector:
matchLabels:
app: sleep
template:
metadata:
labels:
app: sleep
spec:
containers:
- name: sleep
image: tutum/curl
command: ["/bin/sleep","infinity"]
imagePullPolicy: IfNotPresent
EOF
# snip_creating_a_default_routing_policy_1
kubectl -n istio-io-mirror apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: httpbin
spec:
hosts:
- httpbin
http:
- route:
- destination:
host: httpbin
subset: v1
weight: 100
---
apiVersion: networking.istio.io/v1alpha3
kind: DestinationRule
metadata:
name: httpbin
spec:
host: httpbin
subsets:
- name: v1
labels:
version: v1
- name: v2
labels:
version: v2
EOF

View File

@ -1,73 +0,0 @@
#!/usr/bin/env bash
# Copyright Istio Authors
#
# 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.
set -e
set -u
set -o pipefail
export SLEEP_POD=$(kubectl -n istio-io-mirror get pod -l app=sleep -o jsonpath={.items..metadata.name})
# snip_creating_a_default_routing_policy_2 # Problem, snip uses -it options.
kubectl -n istio-io-mirror exec ${SLEEP_POD} -c sleep -- curl -o /dev/null -s -w "%{http_code}\n" http://httpbin:8000/ISTIO_IO_MIRROR_TEST_1
# snip_creating_a_default_routing_policy_3
export V1_POD=$(kubectl -n istio-io-mirror get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name})
out=$(kubectl -n istio-io-mirror logs ${V1_POD} -c httpbin 2>&1)
_verify_contains "$out" "ISTIO_IO_MIRROR_TEST_1" "snip_creating_a_default_routing_policy_3"
# snip_creating_a_default_routing_policy_4
export V2_POD=$(kubectl -n istio-io-mirror get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name})
out=$(kubectl -n istio-io-mirror logs ${V2_POD} -c httpbin 2>&1)
_verify_not_contains "$out" "ISTIO_IO_MIRROR_TEST_1" "snip_creating_a_default_routing_policy_4"
# snip_mirroring_traffic_to_v2_1
kubectl -n istio-io-mirror apply -f - <<EOF
apiVersion: networking.istio.io/v1alpha3
kind: VirtualService
metadata:
name: httpbin
spec:
hosts:
- httpbin
http:
- route:
- destination:
host: httpbin
subset: v1
weight: 100
mirror:
host: httpbin
subset: v2
mirror_percent: 100
EOF
# Wait a bit
sleep 10
export SLEEP_POD=$(kubectl -n istio-io-mirror get pod -l app=sleep -o jsonpath={.items..metadata.name})
# snip_mirroring_traffic_to_v2_2 # Problem, snip uses -it options.
kubectl -n istio-io-mirror exec ${SLEEP_POD} -c sleep -- curl --retry 3 -o /dev/null -s -w "%{http_code}\n" http://httpbin:8000/ISTIO_IO_MIRROR_TEST_2
# snip_mirroring_traffic_to_v2_3
export V1_POD=$(kubectl -n istio-io-mirror get pod -l app=httpbin,version=v1 -o jsonpath={.items..metadata.name})
out=$(kubectl -n istio-io-mirror logs ${V1_POD} -c httpbin 2>&1)
_verify_contains "$out" "ISTIO_IO_MIRROR_TEST_2" "snip_mirroring_traffic_to_v2_3"
# snip_mirroring_traffic_to_v2_4
export V2_POD=$(kubectl -n istio-io-mirror get pod -l app=httpbin,version=v2 -o jsonpath={.items..metadata.name})
out=$(kubectl -n istio-io-mirror logs ${V2_POD} -c httpbin 2>&1)
_verify_contains "$out" "ISTIO_IO_MIRROR_TEST_2" "snip_mirroring_traffic_to_v2_4"

View File

@ -0,0 +1,64 @@
#!/usr/bin/env bash
# shellcheck disable=SC1090,SC2154
# Copyright Istio Authors
#
# 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.
set -e
set -u
set -o pipefail
source "${REPO_ROOT}/content/en/docs/tasks/traffic-management/mirroring/snips.sh"
source "${REPO_ROOT}/tests/util/samples.sh"
kubectl label namespace default istio-injection=enabled --overwrite
snip_before_you_begin_1
snip_before_you_begin_2
snip_before_you_begin_3
snip_before_you_begin_4
# wait for deployments
#sample_wait_for_deployment default httpbin-v1
#sample_wait_for_deployment default httpbin-v2
#sample_wait_for_deployment default sleep
snip_creating_a_default_routing_policy_1
# wait for virtual service
#istioctl experimental wait --for=distribution VirtualService httpbin.default
#sleep 5s
kubectl get all --all-namespaces
#_run_and_verify_contains snip_creating_a_default_routing_policy_2 "headers"
#_run_and_verify_contains snip_creating_a_default_routing_policy_3 "GET /headers HTTP/1.1"
#_run_and_verify_not_contains snip_creating_a_default_routing_policy_4 "GET /headers HTTP/1.1"
#snip_mirroring_traffic_to_v2_1
# wait for virtual service
#istioctl experimental wait --for=distribution VirtualService httpbin.default
#sleep 5s
#snip_mirroring_traffic_to_v2_2
#_run_and_verify_contains snip_mirroring_traffic_to_v2_3 "GET /headers HTTP/1.1"
#_run_and_verify_contains snip_mirroring_traffic_to_v2_3 "GET /headers HTTP/1.1"