diff --git a/skylib/k8s_test_namespace.sh.tpl b/skylib/k8s_test_namespace.sh.tpl index ab7cffee..7332ad64 100644 --- a/skylib/k8s_test_namespace.sh.tpl +++ b/skylib/k8s_test_namespace.sh.tpl @@ -24,6 +24,8 @@ TEST_UNDECLARED_OUTPUTS_DIR=${TEST_UNDECLARED_OUTPUTS_DIR:-.} KUBECTL=%{kubectl} KUBECONFIG=%{kubeconfig} +CLUSTER_FILE=%{cluster} + SET_NAMESPACE=%{set_namespace} IT_MANIFEST_FILTER=%{it_manifest_filter} @@ -32,8 +34,8 @@ NAMESPACE_NAME_FILE=${TEST_UNDECLARED_OUTPUTS_DIR}/namespace KUBECONFIG_FILE=${TEST_UNDECLARED_OUTPUTS_DIR}/kubeconfig # get cluster and username from provided configuration -CLUSTER=$(${KUBECTL} --kubeconfig=${KUBECONFIG} config view -o jsonpath='{.clusters[0].name}') -USER=$(${KUBECTL} --kubeconfig=${KUBECONFIG} config view -o jsonpath='{.users[0].name}') +CLUSTER=$(cat ${CLUSTER_FILE}) +USER=$(${KUBECTL} --kubeconfig=${KUBECONFIG} config view -o jsonpath='{.users[?(@.name == '"\"${CLUSTER}\")].name}") echo "Cluster: ${CLUSTER}" >&2 echo "User: ${USER}" >&2 @@ -53,7 +55,7 @@ else DELETE_NAMESPACE_FLAG="-delete_namespace" COUNT="0" while true; do - NAMESPACE=${USER}-$(( (RANDOM) + 32767 )) + NAMESPACE=`whoami`-$(( (RANDOM) + 32767 )) ${KUBECTL} --kubeconfig=${KUBECONFIG} --cluster=${CLUSTER} --user=${USER} create namespace ${NAMESPACE} && break COUNT=$[$COUNT + 1] if [ $COUNT -ge 10 ]; then