From 591c6384d1420e9d92df235478b71b418e8215cf Mon Sep 17 00:00:00 2001 From: Miguel Varela Ramos Date: Mon, 7 Dec 2020 15:46:25 +0100 Subject: [PATCH 1/5] Add makefile command to run the operator locally with a debugger --- Makefile | 13 ++++++++ dev/operator_local_debugger.sh | 60 ++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) create mode 100755 dev/operator_local_debugger.sh diff --git a/Makefile b/Makefile index 9571e20e8a..dc5f4c32f5 100644 --- a/Makefile +++ b/Makefile @@ -50,12 +50,25 @@ operator-local-gcp: @$(MAKE) operator-stop-gcp || true @./dev/operator_local.sh --operator-only --gcp || true +# start local operator and attach the delve debugger to it (in server mode) +operator-local-aws-dbg: + @$(MAKE) operator-stop || true + @./dev/operator_local_debugger.sh --aws || true +operator-local-gcp-dbg: + @$(MAKE) operator-stop || true + @./dev/operator_local_debugger.sh --gcp || true + # configure kubectl to point to the cluster specified in dev/config/cluster-[aws|gcp].yaml kubectl-aws: @eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-aws.yaml) && eksctl utils write-kubeconfig --cluster="$$CORTEX_CLUSTER_NAME" --region="$$CORTEX_REGION" | grep -v "saved kubeconfig as" | grep -v "using region" | grep -v "eksctl version" || true kubectl-gcp: @eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster-gcp.yaml) && gcloud container clusters get-credentials "$$CORTEX_CLUSTER_NAME" --zone "$$CORTEX_ZONE" --project "$$CORTEX_PROJECT" 2>&1 | grep -v "Fetching cluster" | grep -v "kubeconfig entry generated" || true +# configure kubectl to point to the cluster specified in dev/config/cluster.yaml +.PHONY: kubectl +kubectl: + @eval $$(python3 ./manager/cluster_config_env.py ./dev/config/cluster.yaml) && eksctl utils write-kubeconfig --cluster="$$CORTEX_CLUSTER_NAME" --region="$$CORTEX_REGION" | grep -v "saved kubeconfig as" | grep -v "using region" | grep -v "eksctl version" || true + cluster-up-aws: @$(MAKE) images-all-aws @$(MAKE) cli diff --git a/dev/operator_local_debugger.sh b/dev/operator_local_debugger.sh new file mode 100755 index 0000000000..d48c7d0148 --- /dev/null +++ b/dev/operator_local_debugger.sh @@ -0,0 +1,60 @@ +#!/bin/bash + +# Copyright 2020 Cortex Labs, Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set -euo pipefail + +arg1=${1:-""} + +provider="" +if [ "$arg1" = "--aws" ]; then + provider="aws" +elif [ "$arg1" = "--gcp" ]; then + provider="gcp" +else + echo "provider must be set: either pass in the --aws or the --gcp flag" + exit 1 +fi + +ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)" +DEBUG_CMD="dlv --listen=:2345 --headless=true --api-version=2 debug $ROOT/pkg/operator" + +kill $(pgrep -f "${DEBUG_CMD}") >/dev/null 2>&1 || true +kill $(pgrep -f __debug_bin) >/dev/null 2>&1 || true + +eval $(python3 $ROOT/manager/cluster_config_env.py "$ROOT/dev/config/cluster-${provider}.yaml") + +if [ "$provider" = "aws" ]; then + export CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY="$CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY_AWS" + export CLUSTER_AWS_ACCESS_KEY_ID="${CLUSTER_AWS_ACCESS_KEY_ID:-$AWS_ACCESS_KEY_ID}" + export CLUSTER_AWS_SECRET_ACCESS_KEY="${CLUSTER_AWS_SECRET_ACCESS_KEY:-$AWS_SECRET_ACCESS_KEY}" +else + export CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY="$CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY_GCP" +fi + +python3 $ROOT/dev/update_cli_config.py "$HOME/.cortex/cli.yaml" "${CORTEX_CLUSTER_NAME}-${provider}" "$provider" "http://localhost:8888" + +cp -r $ROOT/dev/config/cluster-${provider}.yaml ~/.cortex/cluster-dev.yaml + +if grep -qiP '^telemetry:\s*false\s*$' ~/.cortex/cli.yaml; then + echo "telemetry: false" >> ~/.cortex/cluster-dev.yaml +fi + +export CORTEX_OPERATOR_IN_CLUSTER=false +export CORTEX_CLUSTER_CONFIG_PATH=~/.cortex/cluster-dev.yaml + +mkdir -p $ROOT/bin + +echo 'starting local operator in debug mode...' && eval "${DEBUG_CMD}" From fc867b5fdcfc19c99988e1ff7333e15873f75259 Mon Sep 17 00:00:00 2001 From: Miguel Varela Ramos Date: Mon, 7 Dec 2020 15:46:55 +0100 Subject: [PATCH 2/5] Exclude common folders from the linting script --- build/lint.sh | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/build/lint.sh b/build/lint.sh index 656f4c4455..cdd6b5d4cd 100755 --- a/build/lint.sh +++ b/build/lint.sh @@ -71,6 +71,8 @@ fi output=$(cd "$ROOT" && find . -type f \ ! -path "./vendor/*" \ ! -path "**/.vscode/*" \ +! -path "**/.idea/*" \ +! -path "**/.history/*" \ ! -path "**/__pycache__/*" \ ! -path "./examples/*" \ ! -path "./dev/config/*" \ @@ -97,6 +99,8 @@ if [ "$is_release_branch" = "true" ]; then ! -path "./build/lint.sh" \ ! -path "./vendor/*" \ ! -path "**/.vscode/*" \ + ! -path "**/.idea/*" \ + ! -path "**/.history/*" \ ! -path "**/__pycache__/*" \ ! -path "./docs/contributing/development.md" \ ! -path "./dev/config/*" \ @@ -118,6 +122,8 @@ if [ "$is_release_branch" = "true" ]; then ! -path "./dev/*" \ ! -path "./vendor/*" \ ! -path "**/.vscode/*" \ + ! -path "**/.idea/*" \ + ! -path "**/.history/*" \ ! -path "**/__pycache__/*" \ ! -path "./dev/config/*" \ ! -path "./bin/*" \ @@ -181,6 +187,8 @@ fi # Check for trailing whitespace output=$(cd "$ROOT" && find . -type f \ ! -path "./vendor/*" \ +! -path "**/.idea/*" \ +! -path "**/.history/*" \ ! -path "**/.vscode/*" \ ! -path "**/__pycache__/*" \ ! -path "./dev/config/*" \ @@ -198,6 +206,8 @@ fi # Check for missing new line at end of file output=$(cd "$ROOT" && find . -type f \ ! -path "./vendor/*" \ +! -path "**/.idea/*" \ +! -path "**/.history/*" \ ! -path "**/.vscode/*" \ ! -path "**/__pycache__/*" \ ! -path "./dev/config/*" \ @@ -216,6 +226,8 @@ fi output=$(cd "$ROOT" && find . -type f \ ! -path "./vendor/*" \ ! -path "**/.vscode/*" \ +! -path "**/.idea/*" \ +! -path "**/.history/*" \ ! -path "**/__pycache__/*" \ ! -path "./dev/config/*" \ ! -path "./bin/*" \ @@ -232,6 +244,8 @@ fi # Check for new line(s) at beginning of file output=$(cd "$ROOT" && find . -type f \ ! -path "./vendor/*" \ +! -path "**/.idea/*" \ +! -path "**/.history/*" \ ! -path "**/.vscode/*" \ ! -path "**/__pycache__/*" \ ! -path "./dev/config/*" \ From 3fec6b43ef0f39d3cb91ee5c533ddc9af84e019f Mon Sep 17 00:00:00 2001 From: Miguel Varela Ramos Date: Tue, 8 Dec 2020 14:30:40 +0100 Subject: [PATCH 3/5] Move debug binary to bin/ folder --- dev/operator_local_debugger.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dev/operator_local_debugger.sh b/dev/operator_local_debugger.sh index d48c7d0148..e16494d6da 100755 --- a/dev/operator_local_debugger.sh +++ b/dev/operator_local_debugger.sh @@ -29,7 +29,7 @@ else fi ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)" -DEBUG_CMD="dlv --listen=:2345 --headless=true --api-version=2 debug $ROOT/pkg/operator" +DEBUG_CMD="dlv --listen=:2345 --headless=true --api-version=2 debug $ROOT/pkg/operator --output ${ROOT}/bin/__debug_bin" kill $(pgrep -f "${DEBUG_CMD}") >/dev/null 2>&1 || true kill $(pgrep -f __debug_bin) >/dev/null 2>&1 || true @@ -56,5 +56,4 @@ export CORTEX_OPERATOR_IN_CLUSTER=false export CORTEX_CLUSTER_CONFIG_PATH=~/.cortex/cluster-dev.yaml mkdir -p $ROOT/bin - echo 'starting local operator in debug mode...' && eval "${DEBUG_CMD}" From 4a0b77ce9160a06f96cd307f7aa12eb9caab3138 Mon Sep 17 00:00:00 2001 From: Miguel Varela Ramos Date: Tue, 8 Dec 2020 14:31:14 +0100 Subject: [PATCH 4/5] Rename operator local debug make commands --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index dc5f4c32f5..7f4273be54 100644 --- a/Makefile +++ b/Makefile @@ -51,10 +51,10 @@ operator-local-gcp: @./dev/operator_local.sh --operator-only --gcp || true # start local operator and attach the delve debugger to it (in server mode) -operator-local-aws-dbg: +operator-local-dbg-aws: @$(MAKE) operator-stop || true @./dev/operator_local_debugger.sh --aws || true -operator-local-gcp-dbg: +operator-local-dbg-gcp: @$(MAKE) operator-stop || true @./dev/operator_local_debugger.sh --gcp || true From 12f733c80dfc51b32971761d7c0e620e071ec211 Mon Sep 17 00:00:00 2001 From: Miguel Varela Ramos Date: Tue, 8 Dec 2020 14:31:36 +0100 Subject: [PATCH 5/5] Add delve to make tools command --- Makefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Makefile b/Makefile index 7f4273be54..0dd2f2e1ab 100644 --- a/Makefile +++ b/Makefile @@ -219,6 +219,7 @@ registry-clean-local: tools: @go get -u -v golang.org/x/lint/golint @go get -u -v github.com/VojtechVitek/rerun/cmd/rerun + @go get -u -v github.com/go-delve/delve/cmd/dlv @python3 -m pip install black 'pydoc-markdown>=3.0.0,<4.0.0' @if [[ "$$OSTYPE" == "darwin"* ]]; then brew install parallel; elif [[ "$$OSTYPE" == "linux"* ]]; then sudo apt-get install -y parallel; else echo "your operating system is not supported"; fi