Add an UI to display the current port forwards status.

This commit is contained in:
2025-11-23 15:53:31 +00:00
parent 555f21c6f3
commit 9b57431f59
3 changed files with 267 additions and 2 deletions
+19 -1
View File
@@ -9,6 +9,13 @@ import (
"github.com/nvm/kportal/internal/k8s"
)
// StatusUpdater is an interface for updating forward status
type StatusUpdater interface {
UpdateStatus(id string, status string)
AddForward(id string, fwd *config.Forward)
Remove(id string)
}
// Manager orchestrates all port-forward workers.
// It handles starting, stopping, and hot-reloading forwards.
type Manager struct {
@@ -20,6 +27,7 @@ type Manager struct {
portChecker *PortChecker
verbose bool
currentConfig *config.Config
statusUI StatusUpdater
}
// NewManager creates a new forward Manager.
@@ -42,6 +50,11 @@ func NewManager(verbose bool) *Manager {
}
}
// SetStatusUI sets the status updater for the manager
func (m *Manager) SetStatusUI(ui StatusUpdater) {
m.statusUI = ui
}
// Start initializes and starts all port-forwards from the configuration.
func (m *Manager) Start(cfg *config.Config) error {
if cfg == nil {
@@ -230,8 +243,13 @@ func (m *Manager) startWorker(fwd config.Forward) error {
return fmt.Errorf("worker already exists for %s", fwd.ID())
}
// Notify UI about new forward
if m.statusUI != nil {
m.statusUI.AddForward(fwd.ID(), &fwd)
}
// Create and start worker
worker := NewForwardWorker(fwd, m.portForwarder, m.verbose)
worker := NewForwardWorker(fwd, m.portForwarder, m.verbose, m.statusUI)
worker.Start()
// Store worker