mirror of https://github.com/istio/istio.io.git
Add ingress-gateway reachability to bookinfo test (#6627)
This commit is contained in:
parent
943c45663f
commit
b1a3e86a7b
|
@ -17,9 +17,20 @@ package security
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"istio.io/istio.io/pkg/test/istioio"
|
||||
|
||||
"istio.io/istio/pkg/test/framework"
|
||||
"istio.io/istio/pkg/test/framework/components/environment/kube"
|
||||
"istio.io/istio/pkg/test/istioio"
|
||||
)
|
||||
|
||||
const (
|
||||
ingressPortCommand = `$(kubectl -n istio-system \
|
||||
get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].port}')`
|
||||
ingressHostCommand = `$(kubectl -n istio-system \
|
||||
get service istio-ingressgateway -o jsonpath='{.status.loadBalancer.ingress[0].ip}')`
|
||||
minikubeIngressPortCommand = `$(kubectl -n istio-system \
|
||||
get service istio-ingressgateway -o jsonpath='{.spec.ports[?(@.name=="http2")].nodePort}')`
|
||||
minikubeIngressHostCommand = `$(kubectl -n istio-system \
|
||||
get pod -l istio=ingressgateway -o jsonpath='{.items[0].status.hostIP}')`
|
||||
)
|
||||
|
||||
//https://istio.io/docs/examples/bookinfo/
|
||||
|
@ -29,13 +40,29 @@ func TestBookinfo(t *testing.T) {
|
|||
NewTest(t).
|
||||
Run(istioio.NewBuilder("examples__bookinfo").
|
||||
Add(istioio.Script{
|
||||
Input: istioio.Path("scripts/bookinfo.txt"),
|
||||
Input: istioio.InputSelectorFunc(func(ctx istioio.Context) istioio.Input {
|
||||
e := ctx.Environment().(*kube.Environment)
|
||||
portCommand := ingressPortCommand
|
||||
hostCommand := ingressHostCommand
|
||||
if e.Settings().Minikube {
|
||||
portCommand = minikubeIngressPortCommand
|
||||
hostCommand = minikubeIngressHostCommand
|
||||
}
|
||||
return istioio.Evaluate(
|
||||
istioio.Path("scripts/bookinfo.txt"),
|
||||
map[string]interface{}{
|
||||
"ingressPortCommand": portCommand,
|
||||
"ingressHostCommand": hostCommand,
|
||||
},
|
||||
).SelectInput(ctx)
|
||||
}),
|
||||
}).
|
||||
Defer(istioio.Script{
|
||||
Input: istioio.Inline{
|
||||
FileName: "cleanup.sh",
|
||||
Value: `
|
||||
kubectl delete -n default -f samples/bookinfo/platform/kube/bookinfo.yaml || true`,
|
||||
kubectl delete -n default -f samples/bookinfo/platform/kube/bookinfo.yaml || true
|
||||
kubectl delete -n default -f samples/bookinfo/networking/bookinfo-gateway.yaml || true`,
|
||||
},
|
||||
}).
|
||||
Build())
|
||||
|
|
|
@ -54,3 +54,36 @@ reviews-v1-[0-9a-z]*-[0-9a-z]* *2/2 *Running *0
|
|||
reviews-v2-[0-9a-z]*-[0-9a-z]* *2/2 *Running *0
|
||||
reviews-v3-[0-9a-z]*-[0-9a-z]* *2/2 *Running *0
|
||||
# $endsnippet
|
||||
|
||||
# $snippet verify_reachable syntax="bash" outputis="text" outputsnippet="true"
|
||||
$ kubectl exec $(kubectl get pod -l app=ratings -o jsonpath='{.items[0].metadata.name}') -c ratings -- curl productpage:9080/productpage | grep -o "<title>.*</title>"
|
||||
# $verify verifier="contains"
|
||||
<title>Simple Bookstore App</title>
|
||||
# $endsnippet
|
||||
|
||||
# $snippet deploy_bookinfo_gateway syntax="bash"
|
||||
$ kubectl apply -f @samples/bookinfo/networking/bookinfo-gateway.yaml@
|
||||
# $endsnippet
|
||||
|
||||
# $snippet verify_gateway syntax="bash" outputis="text" outputsnippet="true"
|
||||
$ kubectl get gateway
|
||||
# $verify verifier="lineRegex"
|
||||
NAME *AGE
|
||||
bookinfo-gateway *[0-9]*s
|
||||
# $endsnippet
|
||||
|
||||
# give it some time to propagate
|
||||
sleep 5
|
||||
|
||||
export INGRESS_HOST={{ .ingressHostCommand }}
|
||||
export INGRESS_PORT={{ .ingressPortCommand }}
|
||||
|
||||
# $snippet export_gateway_url syntax="bash"
|
||||
$ export GATEWAY_URL=$INGRESS_HOST:$INGRESS_PORT
|
||||
# $endsnippet
|
||||
|
||||
# $snippet verify_reachable_ingress syntax="bash" outputis="text" outputsnippet="true"
|
||||
$ curl -s http://${GATEWAY_URL}/productpage | grep -o "<title>.*</title>"
|
||||
# $verify verifier="contains"
|
||||
<title>Simple Bookstore App</title>
|
||||
# $endsnippet
|
||||
|
|
Loading…
Reference in New Issue