-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vivek Reddy
committed
Oct 13, 2024
1 parent
25ea86d
commit dcc88b9
Showing
2 changed files
with
75 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |