Skip to content

Commit 8156feb

Browse files
authored
Add debugger makefile command for operator (#1662)
1 parent f1768e0 commit 8156feb

File tree

3 files changed

+87
-0
lines changed

3 files changed

+87
-0
lines changed

Makefile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,25 @@ operator-local-gcp:
5050
@$(MAKE) operator-stop-gcp || true
5151
@./dev/operator_local.sh --operator-only --gcp || true
5252

53+
# start local operator and attach the delve debugger to it (in server mode)
54+
operator-local-dbg-aws:
55+
@$(MAKE) operator-stop || true
56+
@./dev/operator_local_debugger.sh --aws || true
57+
operator-local-dbg-gcp:
58+
@$(MAKE) operator-stop || true
59+
@./dev/operator_local_debugger.sh --gcp || true
60+
5361
# configure kubectl to point to the cluster specified in dev/config/cluster-[aws|gcp].yaml
5462
kubectl-aws:
5563
@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
5664
kubectl-gcp:
5765
@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
5866

67+
# configure kubectl to point to the cluster specified in dev/config/cluster.yaml
68+
.PHONY: kubectl
69+
kubectl:
70+
@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
71+
5972
cluster-up-aws:
6073
@$(MAKE) images-all-aws
6174
@$(MAKE) cli
@@ -206,6 +219,7 @@ registry-clean-local:
206219
tools:
207220
@go get -u -v golang.org/x/lint/golint
208221
@go get -u -v github.com/VojtechVitek/rerun/cmd/rerun
222+
@go get -u -v github.com/go-delve/delve/cmd/dlv
209223
@python3 -m pip install black 'pydoc-markdown>=3.0.0,<4.0.0'
210224
@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
211225

build/lint.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ fi
7171
output=$(cd "$ROOT" && find . -type f \
7272
! -path "./vendor/*" \
7373
! -path "**/.vscode/*" \
74+
! -path "**/.idea/*" \
75+
! -path "**/.history/*" \
7476
! -path "**/__pycache__/*" \
7577
! -path "./examples/*" \
7678
! -path "./dev/config/*" \
@@ -97,6 +99,8 @@ if [ "$is_release_branch" = "true" ]; then
9799
! -path "./build/lint.sh" \
98100
! -path "./vendor/*" \
99101
! -path "**/.vscode/*" \
102+
! -path "**/.idea/*" \
103+
! -path "**/.history/*" \
100104
! -path "**/__pycache__/*" \
101105
! -path "./docs/contributing/development.md" \
102106
! -path "./dev/config/*" \
@@ -118,6 +122,8 @@ if [ "$is_release_branch" = "true" ]; then
118122
! -path "./dev/*" \
119123
! -path "./vendor/*" \
120124
! -path "**/.vscode/*" \
125+
! -path "**/.idea/*" \
126+
! -path "**/.history/*" \
121127
! -path "**/__pycache__/*" \
122128
! -path "./dev/config/*" \
123129
! -path "./bin/*" \
@@ -181,6 +187,8 @@ fi
181187
# Check for trailing whitespace
182188
output=$(cd "$ROOT" && find . -type f \
183189
! -path "./vendor/*" \
190+
! -path "**/.idea/*" \
191+
! -path "**/.history/*" \
184192
! -path "**/.vscode/*" \
185193
! -path "**/__pycache__/*" \
186194
! -path "./dev/config/*" \
@@ -198,6 +206,8 @@ fi
198206
# Check for missing new line at end of file
199207
output=$(cd "$ROOT" && find . -type f \
200208
! -path "./vendor/*" \
209+
! -path "**/.idea/*" \
210+
! -path "**/.history/*" \
201211
! -path "**/.vscode/*" \
202212
! -path "**/__pycache__/*" \
203213
! -path "./dev/config/*" \
@@ -216,6 +226,8 @@ fi
216226
output=$(cd "$ROOT" && find . -type f \
217227
! -path "./vendor/*" \
218228
! -path "**/.vscode/*" \
229+
! -path "**/.idea/*" \
230+
! -path "**/.history/*" \
219231
! -path "**/__pycache__/*" \
220232
! -path "./dev/config/*" \
221233
! -path "./bin/*" \
@@ -232,6 +244,8 @@ fi
232244
# Check for new line(s) at beginning of file
233245
output=$(cd "$ROOT" && find . -type f \
234246
! -path "./vendor/*" \
247+
! -path "**/.idea/*" \
248+
! -path "**/.history/*" \
235249
! -path "**/.vscode/*" \
236250
! -path "**/__pycache__/*" \
237251
! -path "./dev/config/*" \

dev/operator_local_debugger.sh

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/bin/bash
2+
3+
# Copyright 2020 Cortex Labs, Inc.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -euo pipefail
18+
19+
arg1=${1:-""}
20+
21+
provider=""
22+
if [ "$arg1" = "--aws" ]; then
23+
provider="aws"
24+
elif [ "$arg1" = "--gcp" ]; then
25+
provider="gcp"
26+
else
27+
echo "provider must be set: either pass in the --aws or the --gcp flag"
28+
exit 1
29+
fi
30+
31+
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
32+
DEBUG_CMD="dlv --listen=:2345 --headless=true --api-version=2 debug $ROOT/pkg/operator --output ${ROOT}/bin/__debug_bin"
33+
34+
kill $(pgrep -f "${DEBUG_CMD}") >/dev/null 2>&1 || true
35+
kill $(pgrep -f __debug_bin) >/dev/null 2>&1 || true
36+
37+
eval $(python3 $ROOT/manager/cluster_config_env.py "$ROOT/dev/config/cluster-${provider}.yaml")
38+
39+
if [ "$provider" = "aws" ]; then
40+
export CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY="$CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY_AWS"
41+
export CLUSTER_AWS_ACCESS_KEY_ID="${CLUSTER_AWS_ACCESS_KEY_ID:-$AWS_ACCESS_KEY_ID}"
42+
export CLUSTER_AWS_SECRET_ACCESS_KEY="${CLUSTER_AWS_SECRET_ACCESS_KEY:-$AWS_SECRET_ACCESS_KEY}"
43+
else
44+
export CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY="$CORTEX_DEV_DEFAULT_PREDICTOR_IMAGE_REGISTRY_GCP"
45+
fi
46+
47+
python3 $ROOT/dev/update_cli_config.py "$HOME/.cortex/cli.yaml" "${CORTEX_CLUSTER_NAME}-${provider}" "$provider" "http://localhost:8888"
48+
49+
cp -r $ROOT/dev/config/cluster-${provider}.yaml ~/.cortex/cluster-dev.yaml
50+
51+
if grep -qiP '^telemetry:\s*false\s*$' ~/.cortex/cli.yaml; then
52+
echo "telemetry: false" >> ~/.cortex/cluster-dev.yaml
53+
fi
54+
55+
export CORTEX_OPERATOR_IN_CLUSTER=false
56+
export CORTEX_CLUSTER_CONFIG_PATH=~/.cortex/cluster-dev.yaml
57+
58+
mkdir -p $ROOT/bin
59+
echo 'starting local operator in debug mode...' && eval "${DEBUG_CMD}"

0 commit comments

Comments
 (0)