mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-07-11 07:22:15 +00:00
Add an UI to display the current port forwards status.
This commit is contained in:
@@ -22,10 +22,11 @@ type ForwardWorker struct {
|
||||
doneChan chan struct{}
|
||||
verbose bool
|
||||
lastPod string // Track the last pod we connected to
|
||||
statusUI StatusUpdater
|
||||
}
|
||||
|
||||
// NewForwardWorker creates a new ForwardWorker for a single forward configuration.
|
||||
func NewForwardWorker(fwd config.Forward, portForwarder *k8s.PortForwarder, verbose bool) *ForwardWorker {
|
||||
func NewForwardWorker(fwd config.Forward, portForwarder *k8s.PortForwarder, verbose bool, statusUI StatusUpdater) *ForwardWorker {
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
|
||||
return &ForwardWorker{
|
||||
@@ -36,6 +37,7 @@ func NewForwardWorker(fwd config.Forward, portForwarder *k8s.PortForwarder, verb
|
||||
stopChan: make(chan struct{}),
|
||||
doneChan: make(chan struct{}),
|
||||
verbose: verbose,
|
||||
statusUI: statusUI,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,6 +88,9 @@ func (w *ForwardWorker) run() {
|
||||
|
||||
// Check if pod changed (restart detected)
|
||||
if w.lastPod != "" && w.lastPod != podName {
|
||||
if w.statusUI != nil {
|
||||
w.statusUI.UpdateStatus(w.forward.ID(), "Reconnecting")
|
||||
}
|
||||
log.Printf("[%s] Switched to new pod: %s → %s", w.forward.ID(), w.lastPod, podName)
|
||||
} else if w.lastPod == "" {
|
||||
log.Printf("[%s] Forwarding %s → localhost:%d",
|
||||
@@ -94,6 +99,11 @@ func (w *ForwardWorker) run() {
|
||||
|
||||
w.lastPod = podName
|
||||
|
||||
// Update status to active
|
||||
if w.statusUI != nil {
|
||||
w.statusUI.UpdateStatus(w.forward.ID(), "Active")
|
||||
}
|
||||
|
||||
// Establish port-forward connection
|
||||
err = w.establishForward(podName)
|
||||
|
||||
@@ -104,6 +114,11 @@ func (w *ForwardWorker) run() {
|
||||
return
|
||||
}
|
||||
|
||||
// Update status to error
|
||||
if w.statusUI != nil {
|
||||
w.statusUI.UpdateStatus(w.forward.ID(), "Reconnecting")
|
||||
}
|
||||
|
||||
// Log the error
|
||||
log.Printf("[%s] Port-forward connection failed: %v", w.forward.ID(), err)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user