Skip to content

Commit 83910d3

Browse files
committed
Add operator-local make command
1 parent 51c36c4 commit 83910d3

File tree

2 files changed

+50
-19
lines changed

2 files changed

+50
-19
lines changed

Makefile

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,29 @@ SHELL := /bin/bash
2020

2121
# Cortex
2222

23+
# build cli, start local operator, and watch for changes
2324
devstart:
2425
@$(MAKE) operator-stop || true
2526
@./dev/operator_local.sh || true
2627

28+
.PHONY: cli
29+
cli:
30+
@mkdir -p ./bin
31+
@go build -o ./bin/cortex ./cli
32+
33+
# build cli and watch for changes
34+
cli-watch:
35+
@clear && echo "building cli..."
36+
@$(MAKE) cli
37+
@clear && echo -e "\033[1;32mCLI built\033[0m"
38+
@watchmedo shell-command --command='clear && echo "rebuilding cli..." && go build -o ./bin/cortex ./cli && clear && echo "\033[1;32mCLI built\033[0m"' --patterns '*.go;*.yaml' --recursive --drop ./pkg ./cli
39+
40+
# start local operator and watch for changes
41+
operator-local:
42+
@$(MAKE) operator-stop || true
43+
@./dev/operator_local.sh --operator-only || true
44+
45+
# configure kubectl to point to the cluster specified in dev/config/cluster.yaml
2746
kubectl:
2847
@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
2948

@@ -70,6 +89,7 @@ cluster-configure-y:
7089
@kill $(shell pgrep -f make) >/dev/null 2>&1 || true
7190
@./bin/cortex -c=./dev/config/cluster.yaml cluster configure --yes
7291

92+
# stop the in-cluster operator
7393
operator-stop:
7494
@$(MAKE) kubectl
7595
@kubectl delete --namespace=default --ignore-not-found=true deployment operator
@@ -120,17 +140,6 @@ manager-local:
120140

121141
# Misc
122142

123-
.PHONY: cli
124-
cli:
125-
@mkdir -p ./bin
126-
@go build -o ./bin/cortex ./cli
127-
128-
cli-watch:
129-
@clear && echo "building cli..."
130-
@$(MAKE) cli
131-
@clear && echo -e "\033[1;32mCLI built\033[0m"
132-
@watchmedo shell-command --command='clear && echo "rebuilding cli..." && go build -o ./bin/cortex ./cli && clear && echo "\033[1;32mCLI built\033[0m"' --patterns '*.go;*.yaml' --recursive --drop ./pkg ./cli
133-
134143
aws-clear-bucket:
135144
@./dev/aws.sh clear-bucket
136145

dev/operator_local.sh

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
set -euo pipefail
1919

20+
arg1=${1:-""}
21+
2022
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. >/dev/null && pwd)"
2123

2224
kill $(pgrep -f make) >/dev/null 2>&1 || true
@@ -34,20 +36,40 @@ fi
3436
export CORTEX_OPERATOR_IN_CLUSTER=false
3537
export CORTEX_CLUSTER_CONFIG_PATH=~/.cortex/cluster-dev.yaml
3638

37-
clear && echo "starting local operator..."
39+
clear
40+
mkdir -p ./bin
41+
42+
if [ "$arg1" != "--operator-only" ]; then
43+
echo "building cli..."
44+
go build -o $ROOT/bin/cortex $ROOT/cli
45+
fi
3846

39-
mkdir -p ./bin && go build -o $ROOT/bin/cortex $ROOT/cli && go build -o $ROOT/bin/operator $ROOT/pkg/operator && ($ROOT/bin/operator &)
47+
echo "building operator..."
48+
go build -o $ROOT/bin/operator $ROOT/pkg/operator
49+
50+
echo "starting local operator..."
51+
($ROOT/bin/operator &)
4052

4153
trap ctrl_c INT
4254
function ctrl_c() {
4355
kill $(pgrep -f /bin/operator) >/dev/null 2>&1
56+
exit 1
4457
}
4558

46-
watchmedo shell-command \
47-
--command='kill $(pgrep -f /bin/operator);'" clear && echo 'restarting local operator...' && go build -o $ROOT/bin/cortex $ROOT/cli && go build -o $ROOT/bin/operator $ROOT/pkg/operator && $ROOT/bin/operator &" \
48-
--patterns '*.go;*.yaml' \
49-
--recursive \
50-
--drop \
51-
$ROOT/pkg $ROOT/cli $ROOT/dev/config
59+
if [ "$arg1" = "--operator-only" ]; then
60+
watchmedo shell-command \
61+
--command='kill $(pgrep -f /bin/operator);'" clear && echo 'rebuilding operator...' && go build -o $ROOT/bin/operator $ROOT/pkg/operator && echo 'starting local operator...' && $ROOT/bin/operator &" \
62+
--patterns '*.go;*.yaml' \
63+
--recursive \
64+
--drop \
65+
$ROOT/pkg $ROOT/dev/config
66+
else
67+
watchmedo shell-command \
68+
--command='kill $(pgrep -f /bin/operator);'" clear && echo 'rebuilding cli...' && go build -o $ROOT/bin/cortex $ROOT/cli && echo 'rebuilding operator...' && go build -o $ROOT/bin/operator $ROOT/pkg/operator && echo 'starting local operator...' && $ROOT/bin/operator &" \
69+
--patterns '*.go;*.yaml' \
70+
--recursive \
71+
--drop \
72+
$ROOT/cli $ROOT/pkg $ROOT/dev/config
73+
fi
5274

5375
# go run -race $ROOT/pkg/operator/main.go # Check for race conditions. Doesn't seem to catch them all?

0 commit comments

Comments
 (0)