From 94d04656f3cfb310101f5e8aa8b36f3b5f896431 Mon Sep 17 00:00:00 2001 From: Simon Baumer Date: Mon, 5 Feb 2024 15:06:59 +0100 Subject: [PATCH 1/7] Add long running central port-forward script --- bin/central-port | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 bin/central-port diff --git a/bin/central-port b/bin/central-port new file mode 100644 index 0000000..61bb560 --- /dev/null +++ b/bin/central-port @@ -0,0 +1,41 @@ +#!/bin/bash + +# Function to start port forwarding +start_port_forward() { + kubectl -n stackrox port-forward svc/central 8000:443 & + # Capture the process ID of the background process + PORT_FORWARD_PID=$! + wait $PORT_FORWARD_PID +} + +# Function to check the connection +check_connection() { + while true; do + # Use curl to ping the endpoint + if curl -sSf http://localhost:8000 > /dev/null; then + echo "Connection is active." + else + echo "Connection lost. Restarting port forward..." + # If the connection is lost, kill the port forward process + kill $PORT_FORWARD_PID + break + fi + sleep 1 + done +} + +# Main loop +while true; do + echo "Starting port forward..." + start_port_forward + + # Start the connection check in the background + check_connection & + + # Wait for the port forward process to exit + wait $PORT_FORWARD_PID + + # If the process exits, wait for a few seconds and restart + echo "Port forward process exited. Restarting in 5 seconds..." + sleep 5 +done From 68c5ce00ed570f2423659e6a3134b2633bc71dd8 Mon Sep 17 00:00:00 2001 From: Simon Baumer Date: Mon, 5 Feb 2024 15:08:38 +0100 Subject: [PATCH 2/7] WIP --- bin/central-port | 4 ++++ 1 file changed, 4 insertions(+) mode change 100644 => 100755 bin/central-port diff --git a/bin/central-port b/bin/central-port old mode 100644 new mode 100755 index 61bb560..a1ff275 --- a/bin/central-port +++ b/bin/central-port @@ -1,5 +1,9 @@ #!/bin/bash +# This script starts a port-forwarding process to a Central pod. It automatically detects Central in the current selected +# namespace. When the pod restarts this script automatically re-establishes the port-forward to never loose the connection +# again. + # Function to start port forwarding start_port_forward() { kubectl -n stackrox port-forward svc/central 8000:443 & From f4b9c83ae07571ab1b308ce38c0b2aea53fe0498 Mon Sep 17 00:00:00 2001 From: Simon Baumer Date: Mon, 5 Feb 2024 15:09:33 +0100 Subject: [PATCH 3/7] WIP --- bin/central-port | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/bin/central-port b/bin/central-port index a1ff275..0763201 100755 --- a/bin/central-port +++ b/bin/central-port @@ -1,8 +1,6 @@ #!/bin/bash -# This script starts a port-forwarding process to a Central pod. It automatically detects Central in the current selected -# namespace. When the pod restarts this script automatically re-establishes the port-forward to never loose the connection -# again. +# Automatically restart the port-forwarding process after a restart of the Central pod. # Function to start port forwarding start_port_forward() { From fb352201d2c1db8b588de6e44295d1d800ef6594 Mon Sep 17 00:00:00 2001 From: Simon Baumer Date: Mon, 5 Feb 2024 15:10:06 +0100 Subject: [PATCH 4/7] WIP --- bin/central-port | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/central-port b/bin/central-port index 0763201..008684a 100755 --- a/bin/central-port +++ b/bin/central-port @@ -1,6 +1,6 @@ #!/bin/bash -# Automatically restart the port-forwarding process after a restart of the Central pod. +# Create a port-forward to central which automatically restarts the process after a restart of the Central pod. # Function to start port forwarding start_port_forward() { From f6f2f6df6056df2f5d7543653b1ac9f1fefb8549 Mon Sep 17 00:00:00 2001 From: Simon Baumer Date: Mon, 5 Feb 2024 15:10:23 +0100 Subject: [PATCH 5/7] WIP --- bin/central-port | 2 -- 1 file changed, 2 deletions(-) diff --git a/bin/central-port b/bin/central-port index 008684a..4011558 100755 --- a/bin/central-port +++ b/bin/central-port @@ -2,7 +2,6 @@ # Create a port-forward to central which automatically restarts the process after a restart of the Central pod. -# Function to start port forwarding start_port_forward() { kubectl -n stackrox port-forward svc/central 8000:443 & # Capture the process ID of the background process @@ -10,7 +9,6 @@ start_port_forward() { wait $PORT_FORWARD_PID } -# Function to check the connection check_connection() { while true; do # Use curl to ping the endpoint From 80b050e882f7fa260152ea3ac0dc91acfea433a7 Mon Sep 17 00:00:00 2001 From: Simon Baumer Date: Mon, 5 Feb 2024 15:11:37 +0100 Subject: [PATCH 6/7] WIP --- bin/central-port | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/central-port b/bin/central-port index 4011558..040b5e8 100755 --- a/bin/central-port +++ b/bin/central-port @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # Create a port-forward to central which automatically restarts the process after a restart of the Central pod. From 5c8ad534af4fc25700feb431a3591c592a2daf5b Mon Sep 17 00:00:00 2001 From: Simon Baumer Date: Mon, 5 Feb 2024 15:12:46 +0100 Subject: [PATCH 7/7] WIP --- bin/central-port | 3 +++ 1 file changed, 3 insertions(+) diff --git a/bin/central-port b/bin/central-port index 040b5e8..cb1cdb7 100755 --- a/bin/central-port +++ b/bin/central-port @@ -2,6 +2,9 @@ # Create a port-forward to central which automatically restarts the process after a restart of the Central pod. +# Usage: +# central-port Port-forwards local 8000 to Central and keeps the connection alive. + start_port_forward() { kubectl -n stackrox port-forward svc/central 8000:443 & # Capture the process ID of the background process