add namespace param for fn and env (#2556)
This PR moves fission CLI as closer as possible to kubectl command behaviour. We have improved namespace handling behaviour across CLI. * add namespace param for fn and env * use common fn for ns check * update validation * default namespace for httpTrigger, env and package, config and triggers * use default ns * add namespace filter to spec * add forceNamespace flag * set current namespace * add default namespace in config * add namespace specific destroy * add all namespace in the list of resources * add namespace as global tag * use %s instead of %v * add test cases for namespace * use ns in get all functions
This commit is contained in:
@@ -101,6 +101,10 @@ main() {
|
||||
$ROOT/test/tests/test_fn_update/test_secret_update.sh \
|
||||
$ROOT/test/tests/test_fn_update/test_nd_pkg_update.sh \
|
||||
$ROOT/test/tests/test_fn_update/test_poolmgr_nd.sh
|
||||
$ROOT/test/tests/test_namespace/test_ns_current_context.sh
|
||||
$ROOT/test/tests/test_namespace/test_ns_flag.sh
|
||||
$ROOT/test/tests/test_namespace/test_ns_env.sh
|
||||
$ROOT/test/tests/test_namespace/test_ns_deprecated_flag.sh
|
||||
|
||||
set -e
|
||||
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
source $(dirname $0)/../../utils.sh
|
||||
|
||||
TEST_ID=$(generate_test_id)
|
||||
echo "TEST_ID = $TEST_ID"
|
||||
|
||||
tmp_dir="/tmp/test-$TEST_ID"
|
||||
mkdir -p $tmp_dir
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
cleanup() {
|
||||
echo "previous response" $?
|
||||
log "Cleaning up..."
|
||||
clean_resource_by_id $TEST_ID
|
||||
rm -rf $tmp_dir
|
||||
}
|
||||
|
||||
if [ -z "${TEST_NOCLEANUP:-}" ]; then
|
||||
trap cleanup EXIT
|
||||
else
|
||||
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
|
||||
fi
|
||||
|
||||
httptrigger=http-$TEST_ID
|
||||
httptriggerurl=/url-$TEST_ID
|
||||
fn_n=nbuilderhello-$TEST_ID
|
||||
|
||||
cd $ROOT/examples/go/hello-world
|
||||
|
||||
log "Creating httptrigger using default namespace"
|
||||
fission httptrigger create --function $fn_n --url /$httptriggerurl --name $httptrigger
|
||||
|
||||
log "verify trigger exists"
|
||||
fission httptrigger list --namespace default | grep $httptrigger
|
||||
|
||||
log "Test PASSED"
|
||||
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
source $(dirname $0)/../../utils.sh
|
||||
|
||||
TEST_ID=$(generate_test_id)
|
||||
echo "TEST_ID = $TEST_ID"
|
||||
|
||||
tmp_dir="/tmp/test-$TEST_ID"
|
||||
mkdir -p $tmp_dir
|
||||
|
||||
TEST_NS=ns-$TEST_ID
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
cleanup() {
|
||||
echo "previous response" $?
|
||||
log "Cleaning up..."
|
||||
clean_resource_by_id_for_namespace $TEST_ID $TEST_NS
|
||||
rm -rf $tmp_dir
|
||||
}
|
||||
|
||||
if [ -z "${TEST_NOCLEANUP:-}" ]; then
|
||||
trap cleanup EXIT
|
||||
else
|
||||
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
|
||||
fi
|
||||
|
||||
httptrigger=http-$TEST_ID
|
||||
httptriggerurl=/url-$TEST_ID
|
||||
fn_n=nbuilderhello-$TEST_ID
|
||||
|
||||
cd $ROOT/examples/go/hello-world
|
||||
|
||||
kubectl create namespace $TEST_NS
|
||||
|
||||
log "Creating httptrigger using deprecating flag"
|
||||
fission httptrigger create --function $fn_n --url /$httptriggerurl --name $httptrigger --fnNamespace $TEST_NS
|
||||
|
||||
log "verify trigger exists"
|
||||
fission httptrigger list --namespace $TEST_NS | grep $httptrigger
|
||||
|
||||
log "Test PASSED"
|
||||
Executable
+45
@@ -0,0 +1,45 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
source $(dirname $0)/../../utils.sh
|
||||
|
||||
TEST_ID=$(generate_test_id)
|
||||
echo "TEST_ID = $TEST_ID"
|
||||
|
||||
tmp_dir="/tmp/test-$TEST_ID"
|
||||
mkdir -p $tmp_dir
|
||||
|
||||
TEST_NS=ns-$TEST_ID
|
||||
|
||||
export FISSION_DEFAULT_NAMESPACE=$TEST_NS
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
cleanup() {
|
||||
echo "previous response" $?
|
||||
log "Cleaning up..."
|
||||
clean_resource_by_id_for_namespace $TEST_ID $TEST_NS
|
||||
rm -rf $tmp_dir
|
||||
}
|
||||
|
||||
if [ -z "${TEST_NOCLEANUP:-}" ]; then
|
||||
trap cleanup EXIT
|
||||
else
|
||||
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
|
||||
fi
|
||||
|
||||
httptrigger=http-$TEST_ID
|
||||
httptriggerurl=/url-$TEST_ID
|
||||
fn_n=nbuilderhello-$TEST_ID
|
||||
|
||||
cd $ROOT/examples/go/hello-world
|
||||
|
||||
kubectl create namespace $TEST_NS
|
||||
|
||||
log "Creating httptrigger in namespace using env var"
|
||||
fission httptrigger create --function $fn_n --url /$httptriggerurl --name $httptrigger
|
||||
|
||||
log "verify trigger exists"
|
||||
fission httptrigger list --namespace $TEST_NS | grep $httptrigger
|
||||
|
||||
log "Test PASSED"
|
||||
Executable
+43
@@ -0,0 +1,43 @@
|
||||
#!/bin/bash
|
||||
|
||||
set -euo pipefail
|
||||
source $(dirname $0)/../../utils.sh
|
||||
|
||||
TEST_ID=$(generate_test_id)
|
||||
echo "TEST_ID = $TEST_ID"
|
||||
|
||||
tmp_dir="/tmp/test-$TEST_ID"
|
||||
mkdir -p $tmp_dir
|
||||
|
||||
TEST_NS=ns-$TEST_ID
|
||||
|
||||
ROOT=$(dirname $0)/../../..
|
||||
|
||||
cleanup() {
|
||||
echo "previous response" $?
|
||||
log "Cleaning up..."
|
||||
clean_resource_by_id_for_namespace $TEST_ID $TEST_NS
|
||||
rm -rf $tmp_dir
|
||||
}
|
||||
|
||||
if [ -z "${TEST_NOCLEANUP:-}" ]; then
|
||||
trap cleanup EXIT
|
||||
else
|
||||
log "TEST_NOCLEANUP is set; not cleaning up test artifacts afterwards."
|
||||
fi
|
||||
|
||||
httptrigger=http-$TEST_ID
|
||||
httptriggerurl=/url-$TEST_ID
|
||||
fn_n=nbuilderhello-$TEST_ID
|
||||
|
||||
cd $ROOT/examples/go/hello-world
|
||||
|
||||
kubectl create namespace $TEST_NS
|
||||
|
||||
log "Creating httptrigger in namespace provided by flag"
|
||||
fission httptrigger create --function $fn_n --url /$httptriggerurl --name $httptrigger --namespace $TEST_NS
|
||||
|
||||
log "verify trigger exists"
|
||||
fission httptrigger list --namespace $TEST_NS | grep $httptrigger
|
||||
|
||||
log "Test PASSED"
|
||||
@@ -43,6 +43,38 @@ clean_resource_by_id() {
|
||||
set -e
|
||||
}
|
||||
|
||||
clean_resource_by_id_for_namespace() {
|
||||
test_id=$1
|
||||
namespace=$2
|
||||
KUBECTL="kubectl --namespace $namespace"
|
||||
set +e
|
||||
echo test_id
|
||||
|
||||
fn_list=$(fission function list | grep $test_id | awk '{print $1}')
|
||||
for fn in $fn_list; do
|
||||
fission fn delete --name $fn
|
||||
done
|
||||
|
||||
pkg_list=$(fission package list | grep $test_id | awk '{print $1}')
|
||||
for pkg in $pkg_list; do
|
||||
fission pkg info --name $pkg
|
||||
fission pkg delete -f --name $pkg
|
||||
done
|
||||
|
||||
route_list=$(fission route list | grep $test_id | awk '{print $1}')
|
||||
for route in $route_list; do
|
||||
fission route delete --name $route
|
||||
done
|
||||
|
||||
crds=$($KUBECTL get crd | grep "fission.io" | awk '{print $1}')
|
||||
crds="$crds configmaps secrets"
|
||||
for crd in $crds; do
|
||||
$KUBECTL get $crd -o name | grep $test_id | xargs --no-run-if-empty $KUBECTL delete
|
||||
done
|
||||
|
||||
set -e
|
||||
}
|
||||
|
||||
test_fn() {
|
||||
if [ -z $FISSION_ROUTER ]; then
|
||||
log "Environment FISSION_ROUTER not set"
|
||||
|
||||
Reference in New Issue
Block a user