Add Ingress host, path and annotations support (#1325)

For each ingress controller, the format of ingress host,
path and annotations are different. To support different
kinds of controller, this PR adds new ingress config field
to http trigger spec. A user can set annotations, host and
path based on the type of underlying ingress controller
with CLI.

Command example:

fission route create --name foo \
    --url /foo/{bar} --function foofn --createingress \
    --ingressannotation "nginx.ingress.kubernetes.io/ssl-redirect=false" \
    --ingressannotation "nginx.ingress.kubernetes.io/use-regex=true" \
    --ingressrule "*=/foo/*"
This commit is contained in:
Ta-Ching Chen
2019-09-26 16:54:16 +08:00
committed by GitHub
parent 82a7acf408
commit 49d60b19f3
14 changed files with 1421 additions and 138 deletions
+79 -24
View File
@@ -7,50 +7,105 @@ echo "TEST_ID = $TEST_ID"
ROOT=$(dirname $0)/../..
env=nodejs-$TEST_ID
relativeUrl="/itest-$TEST_ID"
functionName="hellotest-$TEST_ID"
hostName="test-$TEST_ID.com"
routeName="ingress-$TEST_ID"
cleanup() {
clean_resource_by_id $TEST_ID
}
checkIngress() {
local route=$1
local host=$2
local path=$3
local annotations=$4
log "Ingresses matching this trigger:"
kubectl get ing -l 'functionName='$functionName',triggerName='$route --all-namespaces -o=json
log "Verifying to route value in ingress"
actual_path=$(kubectl get ing -l "functionName=$functionName,triggerName=$route" --all-namespaces -o=jsonpath='{.items[0].spec.rules[0].http.paths[0].path}')
if [ "$path" != "$actual_path" ]
then
log "Provided route ($path) and route ($actual_path) in ingress don't match"
exit 1
fi
actual_host=$(kubectl get ing -l "functionName=$functionName,triggerName=$route" --all-namespaces -o=jsonpath='{.items[0].spec.rules[0].host}')
if [ "$host" != "$actual_host" ]
then
log "Provided host ($host) and host ($actual_host) in ingress don't match"
exit 1
fi
actual_ann=$(kubectl get ing -l "functionName=$functionName,triggerName=$route" --all-namespaces -o jsonpath="{.items[0].metadata.annotations}")
if [ "$annotations" != "$actual_ann" ]
then
log "Provided annotations ($annotations) and annotations ($actual_ann) in ingress don't match"
exit 1
fi
}
createFn() {
# Create a hello world function in nodejs, test it with an http trigger
log "Creating nodejs env"
fission env create --name $env --image $NODE_RUNTIME_IMAGE
log "Creating function"
fission fn create --name $functionName --env $env --code $ROOT/examples/nodejs/hello.js
log "Doing an HTTP GET on the function's route"
response=$(fission fn test --name $functionName)
log "Checking for valid response"
echo $response | grep -i hello
}
if [ -z "${TEST_NOCLEANUP:-}" ]; then
trap cleanup EXIT
else
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
fi
createFn
log "Creating route for URL $relativeUrl"
route_name=$(fission route create --url $relativeUrl --function $functionName --createingress| grep trigger| cut -d" " -f 2|cut -d"'" -f 2)
fission route create --name $routeName --url $relativeUrl --function $functionName --createingress
log "Route $route_name created"
sleep 5
log "Ingresses matching this trigger:"
kubectl get ing -l 'functionName='$functionName',triggerName='$route_name --all-namespaces -o=json
log "Verifying to route value in ingress"
actual_route=$(kubectl -n fission get ing -l 'functionName='$functionName',triggerName='$route_name --all-namespaces -o=jsonpath='{.items[0].spec.rules[0].http.paths[0].path}')
if [ $actual_route != $relativeUrl ]
then
log "Provided route and route in ingress don't match"
exit 1
fi
sleep 3
checkIngress $routeName "" $relativeUrl ""
log "Modifying the route by adding host"
fission route update --name $route_name --host $hostName --function $functionName
fission route update --name $routeName --function $functionName --ingressannotation "foo=bar" --ingressrule "$hostName=/foo/bar"
sleep 2
sleep 3
checkIngress $routeName $hostName "/foo/bar" "map[foo:bar]"
actual_host=$(kubectl get ing -l 'functionName='$functionName',triggerName='$route_name --all-namespaces -o=jsonpath='{.items[0].spec.rules[0].host}')
log "Remove ingress annotations, host and rule"
fission route update --name $routeName --function $functionName --ingressannotation "-" --ingressrule "-"
if [ $hostName != $actual_host ]
then
log "Provided host and host in ingress don't match"
exit 1
fi
sleep 3
checkIngress $routeName "" $relativeUrl ""
fission route delete --name $routeName
relativeUrl="/itest-$TEST_ID/{url}"
wildcardPath="/itest-$TEST_ID/*"
realPath="itest-$TEST_ID/test"
log "Creating route for wildcard URL $relativeUrl"
fission route create --name $routeName --url $relativeUrl --function $functionName --createingress \
--ingressannotation "nginx.ingress.kubernetes.io/ssl-redirect=false" \
--ingressannotation "nginx.ingress.kubernetes.io/use-regex=true" \
--ingressrule "*=$wildcardPath"
sleep 3
checkIngress $routeName "" $wildcardPath "map[nginx.ingress.kubernetes.io/ssl-redirect:false nginx.ingress.kubernetes.io/use-regex:true]"
timeout 10 bash -c "test_ingress $realPath 'hello, world!'"
log "Test PASSED"