Skip to content

Commit

Permalink
Allow specifying a GKE version for running E2E tests (kubernetes#239)
Browse files Browse the repository at this point in the history
  • Loading branch information
adrcunha authored and knative-prow-robot committed Nov 6, 2018
1 parent f710a70 commit f6c0fa3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 11 deletions.
3 changes: 3 additions & 0 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ project `$PROJECT_ID` and run the tests against it.
`K8S_USER_OVERRIDE` and `DOCKER_REPO_OVERRIDE` set will immediately start the
tests against the cluster.

1. You can force running the tests against a specific GKE cluster version by using
the `--cluster-version` flag and passing a X.Y.Z version as the flag value.

### Sample end-to-end test script

This script will test that the latest Knative Serving nightly release works. It
Expand Down
39 changes: 28 additions & 11 deletions scripts/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,23 @@ function go_test_e2e() {

# Download the k8s binaries required by kubetest.
function download_k8s() {
local version=${SERVING_GKE_VERSION}
local version=${E2E_CLUSTER_VERSION}
# Fetch valid versions
local versions="$(gcloud container get-server-config \
--project=${GCP_PROJECT} \
--format='value(validMasterVersions)' \
--region=${E2E_CLUSTER_REGION})"
local gke_versions=(`echo -n ${versions//;/ /}`)
echo "Valid GKE versions are [${versions//;/, }]"
if [[ "${version}" == "latest" ]]; then
# Fetch latest valid version
local versions="$(gcloud container get-server-config \
--project=${GCP_PROJECT} \
--format='value(validMasterVersions)' \
--region=${E2E_CLUSTER_REGION})"
local gke_versions=(`echo -n ${versions//;/ /}`)
# Get first (latest) version, excluding the "-gke.#" suffix
version="${gke_versions[0]%-*}"
echo "Latest GKE is ${version}, from [${versions//;/, }]"
echo "Using latest version, ${version}"
elif [[ "${version}" == "default" ]]; then
echo "ERROR: `default` GKE version is not supported yet"
return 1
else
echo "Using command-line supplied version ${version}"
fi
# Download k8s to staging dir
version=v${version}
Expand Down Expand Up @@ -282,6 +285,12 @@ RUN_TESTS=0
EMIT_METRICS=0
USING_EXISTING_CLUSTER=1
E2E_SCRIPT=""
E2E_CLUSTER_VERSION=""

function abort() {
echo "error: $@"
exit 1
}

# Parse flags and initialize the test cluster.
function initialize() {
Expand All @@ -291,6 +300,8 @@ function initialize() {
E2E_SCRIPT="$(cd ${E2E_SCRIPT%/*} && echo $PWD/${E2E_SCRIPT##*/})"
readonly E2E_SCRIPT

E2E_CLUSTER_VERSION="${SERVING_GKE_VERSION}"

cd ${REPO_ROOT_DIR}
while [[ $# -ne 0 ]]; do
local parameter=$1
Expand All @@ -308,16 +319,22 @@ function initialize() {
case $parameter in
--run-tests) RUN_TESTS=1 ;;
--emit-metrics) EMIT_METRICS=1 ;;
--cluster-version)
shift
[[ $# -ge 1 ]] || abort "missing version after --cluster-version"
[[ $1 =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || abort "kubernetes version must be 'X.Y.Z'"
E2E_CLUSTER_VERSION=$1
;;
*)
echo "error: unknown option ${parameter}"
echo "usage: $0 [--run-tests][--emit-metrics]"
exit 1
echo "usage: $0 [--run-tests][--emit-metrics][--cluster-version X.Y.Z]"
abort "unknown option ${parameter}"
;;
esac
shift
done
readonly RUN_TESTS
readonly EMIT_METRICS
readonly E2E_CLUSTER_VERSION

if (( ! RUN_TESTS )); then
create_test_cluster
Expand Down

0 comments on commit f6c0fa3

Please sign in to comment.