From 2f4dc0acbd5470f6b675d9a343460b837f23aba7 Mon Sep 17 00:00:00 2001 From: Omer Spillinger Date: Thu, 4 Jul 2019 11:42:16 -0700 Subject: [PATCH 1/2] Add AWS region support --- cortex.sh | 12 ++++++++++++ docs/cluster/config.md | 3 +++ manager/info.sh | 3 +-- manager/install_cortex.sh | 16 +++++++++++----- manager/install_eks.sh | 4 ++-- manager/uninstall_cortex.sh | 2 +- manager/uninstall_eks.sh | 3 +-- manager/uninstall_operator.sh | 2 +- 8 files changed, 32 insertions(+), 13 deletions(-) diff --git a/cortex.sh b/cortex.sh index 7f48178575..17603343ac 100755 --- a/cortex.sh +++ b/cortex.sh @@ -108,6 +108,7 @@ fi export CORTEX_LOG_GROUP="${CORTEX_LOG_GROUP:-cortex}" export CORTEX_BUCKET="${CORTEX_BUCKET:-""}" export CORTEX_REGION="${CORTEX_REGION:-us-west-2}" +export CORTEX_ZONES="${CORTEX_ZONES:-""}" export CORTEX_CLUSTER="${CORTEX_CLUSTER:-cortex}" export CORTEX_NODE_TYPE="${CORTEX_NODE_TYPE:-t3.small}" @@ -141,10 +142,12 @@ export CORTEX_ENABLE_TELEMETRY="${CORTEX_ENABLE_TELEMETRY:-""}" ########################## function install_eks() { + echo docker run --entrypoint /root/install_eks.sh \ -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ -e CORTEX_CLUSTER=$CORTEX_CLUSTER \ + -e CORTEX_REGION=$CORTEX_REGION \ -e CORTEX_NODE_TYPE=$CORTEX_NODE_TYPE \ -e CORTEX_NODES_MIN=$CORTEX_NODES_MIN \ -e CORTEX_NODES_MAX=$CORTEX_NODES_MAX \ @@ -152,14 +155,17 @@ function install_eks() { } function uninstall_eks() { + echo docker run --entrypoint /root/uninstall_eks.sh \ -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ -e CORTEX_CLUSTER=$CORTEX_CLUSTER \ + -e CORTEX_REGION=$CORTEX_REGION \ $CORTEX_IMAGE_MANAGER } function install_cortex() { + echo docker run --entrypoint /root/install_cortex.sh \ -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ @@ -190,28 +196,34 @@ function install_cortex() { } function uninstall_cortex() { + echo docker run --entrypoint /root/uninstall_cortex.sh \ -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ -e CORTEX_CLUSTER=$CORTEX_CLUSTER \ + -e CORTEX_REGION=$CORTEX_REGION \ -e CORTEX_NAMESPACE=$CORTEX_NAMESPACE \ $CORTEX_IMAGE_MANAGER } function uninstall_operator() { + echo docker run --entrypoint /root/uninstall_operator.sh \ -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ -e CORTEX_CLUSTER=$CORTEX_CLUSTER \ + -e CORTEX_REGION=$CORTEX_REGION \ -e CORTEX_NAMESPACE=$CORTEX_NAMESPACE \ $CORTEX_IMAGE_MANAGER } function info() { + echo docker run --entrypoint /root/info.sh \ -e AWS_ACCESS_KEY_ID=$AWS_ACCESS_KEY_ID \ -e AWS_SECRET_ACCESS_KEY=$AWS_SECRET_ACCESS_KEY \ -e CORTEX_CLUSTER=$CORTEX_CLUSTER \ + -e CORTEX_REGION=$CORTEX_REGION \ -e CORTEX_NAMESPACE=$CORTEX_NAMESPACE \ $CORTEX_IMAGE_MANAGER } diff --git a/docs/cluster/config.md b/docs/cluster/config.md index bef7951080..04b5d0033f 100644 --- a/docs/cluster/config.md +++ b/docs/cluster/config.md @@ -20,6 +20,9 @@ export CORTEX_BUCKET="cortex-[RANDOM_ID]" # The AWS region Cortex will use export CORTEX_REGION="us-west-2" +# The AWS zones Cortex will use +export CORTEX_ZONES="" + # The name of the EKS cluster Cortex will use export CORTEX_CLUSTER="cortex" diff --git a/manager/info.sh b/manager/info.sh index 571042defa..d34e683c65 100755 --- a/manager/info.sh +++ b/manager/info.sh @@ -26,11 +26,10 @@ function get_apis_endpoint() { kubectl -n=$CORTEX_NAMESPACE get service nginx-controller-apis -o json | tr -d '[:space:]' | sed 's/.*{\"hostname\":\"\(.*\)\".*/\1/' } -eksctl utils write-kubeconfig --name=$CORTEX_CLUSTER | grep -v "saved kubeconfig as" || true +eksctl utils write-kubeconfig --name=$CORTEX_CLUSTER --region=$CORTEX_REGION | grep -v "saved kubeconfig as" || true operator_endpoint=$(get_operator_endpoint) apis_endpoint=$(get_apis_endpoint) -echo echo "Operator endpoint: $operator_endpoint" echo "APIs endpoint: $apis_endpoint" diff --git a/manager/install_cortex.sh b/manager/install_cortex.sh index f16400a3c8..b6ff055994 100755 --- a/manager/install_cortex.sh +++ b/manager/install_cortex.sh @@ -25,10 +25,16 @@ function setup_bucket() { if ! aws s3api head-bucket --bucket $CORTEX_BUCKET --output json 2>/dev/null; then if aws s3 ls "s3://$CORTEX_BUCKET" --output json 2>&1 | grep -q 'NoSuchBucket'; then echo "āœ“ Creating an S3 bucket: $CORTEX_BUCKET" - aws s3api create-bucket --bucket $CORTEX_BUCKET \ - --region $CORTEX_REGION \ - --create-bucket-configuration LocationConstraint=$CORTEX_REGION \ - >/dev/null + if [ "$CORTEX_REGION" == "us-east-1" ]; then + aws s3api create-bucket --bucket $CORTEX_BUCKET \ + --region $CORTEX_REGION \ + >/dev/null + else + aws s3api create-bucket --bucket $CORTEX_BUCKET \ + --region $CORTEX_REGION \ + --create-bucket-configuration LocationConstraint=$CORTEX_REGION \ + >/dev/null + fi else echo "A bucket named \"${CORTEX_BUCKET}\" already exists, but you do not have access to it" exit 1 @@ -152,7 +158,7 @@ function validate_cortex() { eksctl utils write-kubeconfig --name=$CORTEX_CLUSTER --region=$CORTEX_REGION | grep -v "saved kubeconfig as" || true -echo -e "\nInstalling Cortex ..." +echo "Installing Cortex ..." setup_bucket setup_cloudwatch_logs diff --git a/manager/install_eks.sh b/manager/install_eks.sh index e69e00e3e9..49e70a8aff 100755 --- a/manager/install_eks.sh +++ b/manager/install_eks.sh @@ -16,11 +16,11 @@ set -e -echo -e "\nSpinning up the cluster ... (this will about 15 minutes)" +echo -e "Spinning up the cluster ... (this will take about 15 minutes)\n" -echo eksctl create cluster --name=$CORTEX_CLUSTER \ --region=$CORTEX_REGION \ + --zones=$CORTEX_ZONES \ --node-type=$CORTEX_NODE_TYPE \ --nodes-min=$CORTEX_NODES_MIN \ --nodes-max=$CORTEX_NODES_MAX \ diff --git a/manager/uninstall_cortex.sh b/manager/uninstall_cortex.sh index a0c5f8b56a..720cb22ff0 100755 --- a/manager/uninstall_cortex.sh +++ b/manager/uninstall_cortex.sh @@ -18,7 +18,7 @@ set -e eksctl utils write-kubeconfig --name=$CORTEX_CLUSTER --region=$CORTEX_REGION | grep -v "saved kubeconfig as" || true -echo -e "\nUninstalling Cortex ..." +echo "Uninstalling Cortex ..." # Remove finalizers on sparkapplications (they sometimes create deadlocks) if kubectl get namespace $CORTEX_NAMESPACE >/dev/null 2>&1 && kubectl get customresourcedefinition sparkapplications.sparkoperator.k8s.io >/dev/null 2>&1; then diff --git a/manager/uninstall_eks.sh b/manager/uninstall_eks.sh index 87f0aa1d61..bddff2286e 100755 --- a/manager/uninstall_eks.sh +++ b/manager/uninstall_eks.sh @@ -16,9 +16,8 @@ set -e -echo -e "\nSpinning down the cluster ... (this will take a few minutes)" +echo -e "Spinning down the cluster ... (this will take a few minutes)\n" -echo eksctl delete cluster --name=$CORTEX_CLUSTER --region=$CORTEX_REGION echo -e "\nāœ“ Spun down the cluster" diff --git a/manager/uninstall_operator.sh b/manager/uninstall_operator.sh index 9f70194607..b51c6f22d8 100755 --- a/manager/uninstall_operator.sh +++ b/manager/uninstall_operator.sh @@ -20,7 +20,7 @@ set -e eksctl utils write-kubeconfig --name=$CORTEX_CLUSTER --region=$CORTEX_REGION | grep -v "saved kubeconfig as" || true -echo -e "\nUninstalling the Cortex operator ..." +echo "Uninstalling the Cortex operator ..." kubectl -n=$CORTEX_NAMESPACE delete --ignore-not-found=true deployment operator >/dev/null 2>&1 From e5b6d54d0f14b13f30b3d27134a3709e485b4f01 Mon Sep 17 00:00:00 2001 From: Omer Spillinger Date: Fri, 5 Jul 2019 11:20:11 -0700 Subject: [PATCH 2/2] Update config.md --- docs/cluster/config.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cluster/config.md b/docs/cluster/config.md index 04b5d0033f..96e32251ef 100644 --- a/docs/cluster/config.md +++ b/docs/cluster/config.md @@ -20,7 +20,7 @@ export CORTEX_BUCKET="cortex-[RANDOM_ID]" # The AWS region Cortex will use export CORTEX_REGION="us-west-2" -# The AWS zones Cortex will use +# The AWS zones Cortex will use (e.g. "us-east-1a,us-east-1b") export CORTEX_ZONES="" # The name of the EKS cluster Cortex will use