Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
Unique GKE clusters for integration tests (#144)
Browse files Browse the repository at this point in the history
* Setup/teardown unique GKE clusters for int tests

* Specify compute zone for GKE
  • Loading branch information
Alex Sloan authored Sep 1, 2017
1 parent 3185cf2 commit 3c97d2d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 5 additions & 0 deletions scripts/gke_cluster_cleanup.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Cloud Builder pipeline for tearing down integration test resources
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['--quiet', 'container', 'clusters', 'delete', '$_CLUSTER_NAME', '--zone=$_ZONE']

26 changes: 21 additions & 5 deletions scripts/gke_integration_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,20 @@ readonly projectName=$(gcloud info \
| sed 's/\]//')
readonly imageName="openjdk-gke-integration:$TAG"
readonly imageUrl="gcr.io/$projectName/$imageName"
readonly clusterName="openjdk-gke-integration"
readonly defaultZone="us-east1-c"

readonly imageUnderTest=$1
clusterName=$2
if [[ -z "$imageUnderTest" ]]; then
echo "Usage: ${0} <image_under_test>"
echo "Usage: ${0} <image_under_test> [gke_cluster_name]"
exit 1
fi

if [[ -z "$clusterName" ]]; then
clusterName=$(uuidgen)
readonly tearDown="true"
fi

# build the test app
pushd ${testAppDir}
mvn clean package -Ddeployment.token="${DEPLOYMENT_TOKEN}" -DskipTests --batch-mode
Expand All @@ -69,13 +75,13 @@ gcloud docker -- tag "$imageName" "$imageUrl"
gcloud docker -- push gcr.io/${projectName}/${imageName}

echo "Creating or searching for a Kubernetes cluster..."
TEST_CLUSTER_EXISTENCE=$(gcloud container clusters list | awk "/$clusterName/")
TEST_CLUSTER_EXISTENCE=$(gcloud container clusters list --zone="$defaultZone" | awk "/$clusterName/")
if [ -z "$TEST_CLUSTER_EXISTENCE" ]; then
gcloud container clusters create "$clusterName" --num-nodes=1 --disk-size=10
gcloud container clusters create "$clusterName" --num-nodes=1 --disk-size=10 --zone="$defaultZone"
fi

echo "Deploying application to Google Container Engine..."
gcloud container clusters get-credentials ${clusterName}
gcloud container clusters get-credentials ${clusterName} --zone="$defaultZone"
kubectl apply -f "openjdk-spring-boot.yaml"
popd

Expand All @@ -96,3 +102,13 @@ gcloud container builds submit \
--config ${dir}/integration_test.yaml \
--substitutions "_DEPLOYED_APP_URL=http://$DEPLOYED_APP_URL" \
${dir}

# teardown any resources we created
if [ "$tearDown" == "true" ]; then
# run a cleanup build once tests have finished executing
gcloud container builds submit \
--config $dir/gke_cluster_cleanup.yaml \
--substitutions "_CLUSTER_NAME=$clusterName,_ZONE=$defaultZone" \
--async \
--no-source
fi
2 changes: 1 addition & 1 deletion scripts/integration_test_cleanup.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Cloud Builder pipeline for tearing down integration test resources
steps:
- name: 'gcr.io/cloud-builders/gcloud'
args: ['app', 'versions', 'delete', '$_VERSION']
args: ['--quiet', 'app', 'versions', 'delete', '$_VERSION']

0 comments on commit 3c97d2d

Please sign in to comment.