2021-11-29 08:07:17 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
2022-03-11 18:38:32 +00:00
|
|
|
source .utils
|
|
|
|
|
2022-06-17 05:32:41 +00:00
|
|
|
DRY_RUN=0
|
2021-11-29 08:07:17 +00:00
|
|
|
NAMESPACE="org-giantswarm"
|
|
|
|
RELEASE="20.0.0-alpha1"
|
|
|
|
PROVIDER="aws"
|
|
|
|
AZS="eu-west-1a"
|
2022-06-17 05:32:41 +00:00
|
|
|
DESCRIPTION="$(whoami)'s test cluster"
|
2021-11-29 08:07:17 +00:00
|
|
|
|
|
|
|
print_usage() {
|
2022-06-17 05:32:41 +00:00
|
|
|
orange "gs-create-cluster - create a Giant Swarm managed CAPI workload cluster"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Usage:"
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "gs-create-cluster [cluster-name]"
|
|
|
|
echo " "
|
|
|
|
echo " "
|
2022-03-11 18:38:32 +00:00
|
|
|
underline "Options:"
|
2021-11-29 08:07:17 +00:00
|
|
|
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
|
|
|
|
;;
|
2022-06-17 05:32:41 +00:00
|
|
|
--dry-run)
|
|
|
|
DRY_RUN=1
|
|
|
|
shift
|
|
|
|
;;
|
2021-11-29 08:07:17 +00:00
|
|
|
-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
|
|
|
|
|
2022-08-17 10:51:20 +00:00
|
|
|
CAPA_CLUSTER="--provider capa"
|
2022-06-17 05:32:41 +00:00
|
|
|
CAPZ_CLUSTER="--provider azure --release ${RELEASE}"
|
2022-07-08 05:04:09 +00:00
|
|
|
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"
|
2022-06-17 05:32:41 +00:00
|
|
|
TEMPLATE_ARGS="--name ${NAME:0:5} --organization ${NAMESPACE}"
|
|
|
|
case "${PROVIDER}" in
|
|
|
|
aws)
|
2022-08-11 08:35:57 +00:00
|
|
|
TEMPLATE_ARGS="${TEMPLATE_ARGS} ${CAPA_CLUSTER}"
|
2022-06-17 05:32:41 +00:00
|
|
|
;;
|
|
|
|
gcp)
|
|
|
|
TEMPLATE_ARGS="${TEMPLATE_ARGS} ${CAPG_CLUSTER}"
|
|
|
|
;;
|
|
|
|
azure)
|
|
|
|
TEMPLATE_ARGS="${TEMPLATE_ARGS} ${CAPZ_CLUSTER}"
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unsupported provider type"
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2021-11-29 08:07:17 +00:00
|
|
|
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
|
2022-06-17 05:32:41 +00:00
|
|
|
elif [[ "${PROVIDER}" = "aws" ]]; then
|
2021-11-29 08:07:17 +00:00
|
|
|
echo "Cleaning up any old awsclusterroleidentities..."
|
2021-12-14 08:24:18 +00:00
|
|
|
kubectl delete --namespace ${PREFIXED_NAMESPACE} awsclusterroleidentities ${NAME} 2>/dev/null
|
2021-11-29 08:07:17 +00:00
|
|
|
fi
|
|
|
|
|
2022-06-17 05:32:41 +00:00
|
|
|
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
|
2021-11-29 08:07:17 +00:00
|
|
|
|
2022-06-17 05:32:41 +00:00
|
|
|
if [[ $DRY_RUN = 0 ]]; then
|
|
|
|
sleep 10
|
|
|
|
echo "✨ Checking status..."
|
|
|
|
gs-get-cluster --namespace ${PREFIXED_NAMESPACE} ${NAME}
|
|
|
|
fi
|