109 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			109 lines
		
	
	
		
			2.7 KiB
		
	
	
	
		
			Bash
		
	
	
		
			Executable File
		
	
	
	
	
#!/usr/bin/env bash
 | 
						|
 | 
						|
source .utils
 | 
						|
 | 
						|
DRY_RUN=0
 | 
						|
NAMESPACE="org-giantswarm"
 | 
						|
RELEASE="20.0.0-alpha1"
 | 
						|
PROVIDER="aws"
 | 
						|
AZS="eu-west-1a"
 | 
						|
DESCRIPTION="$(whoami)'s test cluster"
 | 
						|
 | 
						|
print_usage() {
 | 
						|
  orange "gs-create-cluster - create a Giant Swarm managed CAPI workload cluster"
 | 
						|
  echo " "
 | 
						|
  underline "Usage:"
 | 
						|
  echo "gs-create-cluster [cluster-name]"
 | 
						|
  echo " "
 | 
						|
  echo " "
 | 
						|
  underline "Options:"
 | 
						|
  echo "-h, --help            show this help text"
 | 
						|
  echo "-n, --namespace       the namespace the cluster is in (default: org-giantswarm)"
 | 
						|
  echo "-r, --release         the namespace the cluster is in (default: 20.0.0-alpha1)"
 | 
						|
  echo "-p, --provider        the cloud provider to use (default: aws)"
 | 
						|
}
 | 
						|
 | 
						|
while test $# -gt 0; do
 | 
						|
  case "$1" in
 | 
						|
    -n|--namespace)
 | 
						|
      shift
 | 
						|
      NAMESPACE=$1
 | 
						|
      shift
 | 
						|
      ;;
 | 
						|
    -r|--release)
 | 
						|
      shift
 | 
						|
      RELEASE=$1
 | 
						|
      shift
 | 
						|
      ;;
 | 
						|
    -p|--provider)
 | 
						|
      shift
 | 
						|
      PROVIDER=$1
 | 
						|
      shift
 | 
						|
      ;;
 | 
						|
    --dry-run)
 | 
						|
      DRY_RUN=1
 | 
						|
      shift
 | 
						|
      ;;
 | 
						|
    -h|--help)
 | 
						|
      print_usage
 | 
						|
      exit 0
 | 
						|
      ;;
 | 
						|
    *)
 | 
						|
      break
 | 
						|
      ;;
 | 
						|
  esac
 | 
						|
done
 | 
						|
 | 
						|
# Positional args
 | 
						|
NAME=${1:-wc001}
 | 
						|
 | 
						|
PREFIXED_NAMESPACE="org-$NAMESPACE"
 | 
						|
case $NAMESPACE in org-*)
 | 
						|
  PREFIXED_NAMESPACE="$NAMESPACE"
 | 
						|
  NAMESPACE=${NAMESPACE#"org-"}
 | 
						|
esac
 | 
						|
 | 
						|
CAPA_CLUSTER="--provider capa"
 | 
						|
CAPZ_CLUSTER="--provider azure --release ${RELEASE}"
 | 
						|
CAPG_CLUSTER="--provider gcp --gcp-project giantswarm-352614 --region europe-west3 --gcp-failure-domains europe-west3-a --gcp-machine-deployment-failure-domain europe-west3-a"
 | 
						|
TEMPLATE_ARGS="--name ${NAME:0:5} --organization ${NAMESPACE}"
 | 
						|
case "${PROVIDER}" in
 | 
						|
  aws)
 | 
						|
    TEMPLATE_ARGS="${TEMPLATE_ARGS} ${CAPA_CLUSTER}"
 | 
						|
    ;;
 | 
						|
  gcp)
 | 
						|
    TEMPLATE_ARGS="${TEMPLATE_ARGS} ${CAPG_CLUSTER}"
 | 
						|
    ;;
 | 
						|
  azure)
 | 
						|
    TEMPLATE_ARGS="${TEMPLATE_ARGS} ${CAPZ_CLUSTER}"
 | 
						|
    ;;
 | 
						|
  *)
 | 
						|
    echo "Unsupported provider type"
 | 
						|
    exit 1
 | 
						|
    ;;
 | 
						|
esac
 | 
						|
 | 
						|
echo "✨  Pre-flight checks"
 | 
						|
gs-get-cluster --namespace ${PREFIXED_NAMESPACE} ${NAME} &>/dev/null
 | 
						|
if [ $? -eq 0 ]; then
 | 
						|
  echo "Cluster named '${NAME}' already exists"
 | 
						|
  exit 1
 | 
						|
elif [[ "${PROVIDER}" = "aws" ]]; then
 | 
						|
  echo "Cleaning up any old awsclusterroleidentities..."
 | 
						|
  kubectl delete --namespace ${PREFIXED_NAMESPACE} awsclusterroleidentities ${NAME} 2>/dev/null
 | 
						|
fi
 | 
						|
 | 
						|
echo "✨  Creating a new ${PROVIDER} cluster called '${NAMESPACE}/${NAME}' with release '${RELEASE}'"
 | 
						|
if [[ $DRY_RUN = 1 ]]; then
 | 
						|
  echo kubectl-gs template cluster ${TEMPLATE_ARGS} --description "${DESCRIPTION}"
 | 
						|
  kubectl-gs template cluster ${TEMPLATE_ARGS} --description "${DESCRIPTION}"
 | 
						|
else
 | 
						|
  kubectl-gs template cluster ${TEMPLATE_ARGS} --description "${DESCRIPTION}" | kubectl apply -f -
 | 
						|
fi
 | 
						|
 | 
						|
if [[ $DRY_RUN = 0 ]]; then
 | 
						|
  sleep 10
 | 
						|
  echo "✨  Checking status..."
 | 
						|
  gs-get-cluster --namespace ${PREFIXED_NAMESPACE} ${NAME}
 | 
						|
fi
 |