Skip to content
This repository has been archived by the owner on Aug 11, 2020. It is now read-only.

Commit

Permalink
Adding kill all port forwardings
Browse files Browse the repository at this point in the history
  • Loading branch information
tsorya committed May 10, 2020
1 parent a6147be commit f0c8509
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@ bm-inventory
.idea
.terraform
*__pycache__*
minikube
*.log

7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,10 @@ deploy_nodes:
destroy_nodes:
skipper run discovery-infra/delete_nodes.py

destroy: destroy_nodes delete_minikube
kill_all_port_forwardings:
scripts/utils.sh kill_all_port_forwardings

destroy: destroy_nodes delete_minikube kill_all_port_forwardings
rm -rf build/terraform/*

_deploy_bm_inventory: bring_bm_inventory
Expand Down Expand Up @@ -161,5 +164,5 @@ deploy_bm_inventory_with_external_ip:
download_iso_for_remote_use: deploy_bm_inventory_with_external_ip
skipper make _download_iso

deploy_ui: run
deploy_ui: start_minikube
scripts/deploy_ui.sh
4 changes: 2 additions & 2 deletions scripts/deploy_ui.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export UI_PORT=${UI_PORT:-6008}
export UI_INTERNAL_PORT=80
export KUBECONFIG=${KUBECONFIG:-$HOME/.kube/config}
export CONTAINER_COMMAND=${CONTAINER_COMMAND:-podman}
export UI_DEPLOY_FILE=ui_deploy.yaml
export UI_DEPLOY_FILE=build/ui_deploy.yaml
export UI_SERVICE_NAME=ocp-metal-ui

echo "Starting ui"
Expand All @@ -25,7 +25,7 @@ wait_for_url_and_run "$(minikube service ${UI_SERVICE_NAME} --url)" "echo \"wait

echo "starting port forwarding for deployment/${UI_SERVICE_NAME}"

wait_for_url_and_run "http://${NODE_IP}:${UI_PORT}" "spawn_port_forwarding_command ${UI_PORT} ${UI_INTERNAL_PORT} deployment/ocp-metal-ui"
wait_for_url_and_run "http://${NODE_IP}:${UI_PORT}" "spawn_port_forwarding_command ${UI_PORT} ${UI_INTERNAL_PORT} ${UI_SERVICE_NAME}"

echo "OCP METAL UI can be reached at http://${NODE_IP}:${UI_PORT}"

Expand Down
2 changes: 1 addition & 1 deletion scripts/external_bm_inventory.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ wait_for_url_and_run "$(minikube service ${SERVICE_NAME} --url)" "echo \"waiting

echo "starting port forwarding for deployment/${SERVICE_NAME}"

wait_for_url_and_run "http://${INVENTORY_URL}:${INVENTORY_PORT}" "spawn_port_forwarding_command ${INVENTORY_PORT} ${INVENTORY_INTERNAL_PORT} deployment/${SERVICE_NAME}"
wait_for_url_and_run "http://${INVENTORY_URL}:${INVENTORY_PORT}" "spawn_port_forwarding_command ${INVENTORY_PORT} ${INVENTORY_INTERNAL_PORT} ${SERVICE_NAME}"

echo "${SERVICE_NAME} can be reached at http://${INVENTORY_URL}:${INVENTORY_PORT} "

Expand Down
5 changes: 2 additions & 3 deletions scripts/port_forwarding_loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
source scripts/utils.sh

function create_port_forwarding() {
kubectl --kubeconfig=${KUBECONFIG} port-forward $3 $1:$2 --address 0.0.0.0
kubectl --kubeconfig=${KUBECONFIG} port-forward deployment/$3 $1:$2 --address 0.0.0.0
}

while true; do
while kubectl --kubeconfig=${KUBECONFIG} get deployment | grep $3; do
create_port_forwarding $1 $2 $3
done

11 changes: 9 additions & 2 deletions scripts/utils.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ function run_in_background() {

function kill_portforwarding_loop() {
kill -9 $(ps aux | grep "port_forwarding_loop.sh $1 $2 $3" | grep -v grep | awk '{print $2}') || true
kill -9 $(ps aux | grep "kubectl --kubeconfig=${KUBECONFIG} port-forward $3 $1:$2" | grep -v grep | awk '{print $2}') || true
kill -9 $(ps aux | grep "kubectl --kubeconfig=${KUBECONFIG} port-forward | grep $3" | grep -v grep | awk '{print $2}') || true
}

function kill_all_port_forwardings() {
kill -9 $(ps aux | grep "port_forwarding_loop" | grep -v grep | awk '{print $2}') || true
kill -9 $(ps aux | grep "port-forward" | grep -v grep | awk '{print $2}') || true
}

function get_main_ip() {
Expand Down Expand Up @@ -51,4 +56,6 @@ function wait_for_url_and_run() {
echo "Timeout reached, url not reachable"
exit 1
fi
}
}

"$@"

0 comments on commit f0c8509

Please sign in to comment.