#!/bin/bash

# John Hummel 20220601
# This script uses the Google `gcloud` command to set up a Kubernetes cluster that 
# can host Wallaroo Community Edition.
# For more details, see the Wallaroo Documentation site:  
# https://docs.wallaroo.ai

# Variables for the script. 
# Updated these depending on your organization's requirements.

WALLAROO_GCP_PROJECT=wallaroodocs-ce
WALLAROO_CLUSTER=wallaroodocs-ce
WALLAROO_GCP_REGION=us-central1
WALLAROO_NODE_LOCATION=us-central1-f
WALLAROO_GCP_NETWORK_NAME=wallaroodocs-network
WALLAROO_GCP_SUBNETWORK_NAME=wallaroodocs-subnet-1
WALLAROO_GCP_MACHINE_TYPE=e2-standard-8
WALLAROO_CLUSTER_SIZE=4
K8S_VERSION=1.27

# Create the network

gcloud compute networks \
create $WALLAROO_GCP_NETWORK_NAME \
--bgp-routing-mode regional \
--subnet-mode custom

# Create the cluster

gcloud container clusters \
create $WALLAROO_CLUSTER \
--region $WALLAROO_GCP_REGION \
--node-locations $WALLAROO_NODE_LOCATION \
--machine-type $WALLAROO_GCP_MACHINE_TYPE \
--num-nodes $WALLAROO_CLUSTER_SIZE \
--network $WALLAROO_GCP_NETWORK_NAME \
--create-subnetwork name=$WALLAROO_GCP_SUBNETWORK_NAME \
--enable-ip-alias \
--cluster-version=$K8S_VERSION

# Download the kubernets credentials

gcloud container clusters \
get-credentials $WALLAROO_CLUSTER \
--region $WALLAROO_GCP_REGION
