From dcc88b9fadf3864400e661392f36d4db20c09b3e Mon Sep 17 00:00:00 2001 From: Vivek Reddy Date: Sat, 12 Oct 2024 22:46:06 -0700 Subject: [PATCH] added script to create gcp cluster --- test/README.md | 5 +++ test/deploy-gcp-cluster.sh | 70 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100755 test/deploy-gcp-cluster.sh diff --git a/test/README.md b/test/README.md index 23fbb7e40..d01a8a331 100644 --- a/test/README.md +++ b/test/README.md @@ -79,6 +79,11 @@ STORAGE_ACCOUNT STORAGE_ACCOUNT_KEY CLUSTER_PROVIDER=[azure] +For Azure: +GCP_SERVICE_ACCOUNT_KEY +CLUSTER_PROVIDER=[gcp] +ECR_REGISTRY + ## Writing tests diff --git a/test/deploy-gcp-cluster.sh b/test/deploy-gcp-cluster.sh new file mode 100755 index 000000000..ed70958bf --- /dev/null +++ b/test/deploy-gcp-cluster.sh @@ -0,0 +1,70 @@ +#!/bin/bash + +if [[ -z "${GCP_VPC_PUBLIC_SUBNET_STRING}" ]]; then + echo "GCP PUBLIC SUBNET STRING not set. Changing to env.sh value" + export GCP_VPC_PUBLIC_SUBNET_STRING="${VPC_PUBLIC_SUBNET_STRING}" +fi + +if [[ -z "${GCP_VPC_PRIVATE_SUBNET_STRING}" ]]; then + echo "GCP PRIVATE SUBNET STRING not set. Changing to env.sh value" + export GCP_VPC_PRIVATE_SUBNET_STRING="${VPC_PRIVATE_SUBNET_STRING}" +fi + +if [[ -z "${GCR_REPOSITORY}" ]]; then + echo "GCR_REPOSITORY not set. Changing to env.sh value" + export GCR_REPOSITORY="${PRIVATE_REGISTRY}" +fi + +if [[ -z "${GKE_CLUSTER_K8_VERSION}" ]]; then + echo "GKE_CLUSTER_K8_VERSION not set. Changing to 1.26" + export GKE_CLUSTER_K8_VERSION="1.26" +fi + +function deleteCluster() { + echo "Cleanup remaining PVC on the GKE Cluster ${TEST_CLUSTER_NAME}" + tools/cleanup.sh + gcloud container clusters delete ${TEST_CLUSTER_NAME} --zone ${GCP_ZONE} --quiet + if [ $? -ne 0 ]; then + echo "Unable to delete cluster - ${TEST_CLUSTER_NAME}" + return 1 + fi + return 0 +} + +function createCluster() { + # Deploy gcloud cluster if not deployed + rc=$(which gcloud) + if [ -z "$rc" ]; then + echo "gcloud is not installed or in the PATH. Please install gcloud from https://cloud.google.com/sdk/docs/install." + return 1 + fi + + found=$(gcloud container clusters list --filter="name=${TEST_CLUSTER_NAME}" --format="value(name)") + if [ -z "${found}" ]; then + gcloud container clusters create ${TEST_CLUSTER_NAME} \ + --num-nodes=${CLUSTER_WORKERS} \ + --zone=${GCP_ZONE} \ + --subnetwork=${GCP_VPC_PUBLIC_SUBNET_STRING} \ + --cluster-version=${GKE_CLUSTER_K8_VERSION} \ + --machine-type=n1-standard-4 + if [ $? -ne 0 ]; then + echo "Unable to create cluster - ${TEST_CLUSTER_NAME}" + return 1 + fi + else + echo "Retrieving kubeconfig for ${TEST_CLUSTER_NAME}" + # Cluster exists but kubeconfig may not + gcloud container clusters get-credentials ${TEST_CLUSTER_NAME} --zone ${GCP_ZONE} + fi + + echo "Logging in to GCR" + gcloud auth configure-docker + if [ $? -ne 0 ]; then + echo "Unable to configure Docker for GCR" + return 1 + fi + + # Output + echo "GKE cluster nodes:" + kubectl get nodes +}