Skip to content

Commit

Permalink
Block 'run' and 'debug' makefile rules if controller is not scaled to 0
Browse files Browse the repository at this point in the history
In order to prevent potentially confusing errors, block running the
controller locally if the in-cluster deployment is not scaled to 0. This
is necessary as running two instances of the controller can result in
conflicting reconcile outputs, causing each instance to compete against
the other.

Signed-off-by: Angel Misevski <[email protected]>
  • Loading branch information
amisevsk committed Jul 4, 2022
1 parent 480d686 commit 3d892a0
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions build/make/deploy.mk
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ _store_tls_cert:
$(K8S_CLI) get secret devworkspace-webhookserver-tls -n $(NAMESPACE) -o json | jq -r '.data["tls.key"]' | base64 -d > /tmp/k8s-webhook-server/serving-certs/tls.key
endif

_check_controller_running:
REPLICAS=$$($(K8S_CLI) get deploy devworkspace-controller-manager -n $(NAMESPACE) -o=json | jq -r '.spec.replicas')
if [ "$$REPLICAS" != "0" ]; then \
echo "Controller is already running in cluster, cannot run locally. Scale controller to 0 first." ;\
exit 1 ;\
fi

### install: Install controller in the configured Kubernetes cluster in ~/.kube/config
install: _print_vars _check_cert_manager _init_devworkspace_crds _create_namespace generate_deployment
ifeq ($(PLATFORM),kubernetes)
Expand Down Expand Up @@ -143,15 +150,15 @@ _bump_kubeconfig:
cp $(CONFIG_FILE) $(BUMPED_KUBECONFIG)

### run: Runs against the configured Kubernetes cluster in ~/.kube/config
run: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa _store_tls_cert
run: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa _store_tls_cert _check_controller_running
source $(CONTROLLER_ENV_FILE)
export KUBECONFIG=$(BUMPED_KUBECONFIG)
CONTROLLER_SERVICE_ACCOUNT_NAME=$(DEVWORKSPACE_CTRL_SA) \
WATCH_NAMESPACE=$(NAMESPACE) \
go run ./main.go

### debug: Runs the controller locally with debugging enabled, watching cluster defined in ~/.kube/config
debug: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa _store_tls_cert
debug: _print_vars _gen_configuration_env _bump_kubeconfig _login_with_devworkspace_sa _store_tls_cert _check_controller_running
source $(CONTROLLER_ENV_FILE)
export KUBECONFIG=$(BUMPED_KUBECONFIG)
CONTROLLER_SERVICE_ACCOUNT_NAME=$(DEVWORKSPACE_CTRL_SA) \
Expand Down

0 comments on commit 3d892a0

Please sign in to comment.