mirror of
https://github.com/lukaszraczylo/kportal.git
synced 2026-10-11 04:27:10 +00:00
* feat: add --context to forward only selected contexts
kportal forwards every context in the config file. When the file describes
several clusters that host the same services, that means holding connections
open to clusters nobody is using, and - because all contexts are active at once
- every localPort has to be globally unique. The same service therefore lands on
a different local port per cluster, so switching clusters means reconfiguring
the app being developed.
--context limits a run to the contexts you name. It is repeatable and accepts
comma-separated values, and composes with -headless:
kportal --context development-team-a
kportal --context team-a,team-b -headless
kportal --context team-a --context team-b
An unknown name is an error listing the contexts the file defines, so a typo
fails loudly instead of silently forwarding nothing.
Local-port and mDNS-hostname conflicts are now scoped to forwards that could run
at the same time: same context, or both contexts in the active selection. With
no selection every context is active, so existing behaviour is unchanged.
Contexts that are never selected together may reuse the same localPort, which is
what lets a service keep one fixed local port in every cluster.
Validation still covers the whole file, so a problem in a context outside the
selection is still reported and --check does not get weaker. Loading, validating
and filtering are shared by every path that re-reads the config (startup, file
watcher, SIGHUP in both headless and verbose modes), so no path can forget the
selection.
Also fixes a latent identity bug this makes reachable: Forward.ID() is only
"alias:localPort" when an alias is set, which was unique across contexts only
because duplicate local ports were globally rejected. With ports now shareable,
deleting or editing a forward from the TUI could have matched same-alias
forwards in other contexts and silently removed them. Delete and edit are now
scoped to the context the row came from.
* fix(config): keep the running config when no selected context remains
A reload dropped selected contexts that no longer exist in the file.
When all of them vanished, the reload returned an empty config and the
manager stopped every forward after a single rename.
LoadForRuntime now returns an error in that case. The watcher keeps the
previous config, as it does for any other invalid reload.
Refs #80
* fix(ui): apply new table columns after a successful SIGHUP reload
The context selection moved the SIGHUP reload into reloadFromSignal,
which had no way to update the verbose table columns. The function now
takes a callback that runs only after the manager reloads without error.
The verbose table passes SetColumns.
Refs #80
* style: gofmt run_test.go
---------
Co-authored-by: André Cruz <[email protected]>
35 lines
1.5 KiB
Go
35 lines
1.5 KiB
Go
package ui
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/lukaszraczylo/kportal/internal/config"
|
|
"github.com/lukaszraczylo/kportal/internal/k8s"
|
|
)
|
|
|
|
// DiscoveryInterface defines the interface for Kubernetes discovery operations
|
|
// This allows for mocking in tests
|
|
type DiscoveryInterface interface {
|
|
ListContexts() ([]string, error)
|
|
GetCurrentContext() (string, error)
|
|
ListNamespaces(ctx context.Context, contextName string) ([]string, error)
|
|
ListPods(ctx context.Context, contextName, namespace string) ([]k8s.PodInfo, error)
|
|
ListPodsWithSelector(ctx context.Context, contextName, namespace, selector string) ([]k8s.PodInfo, error)
|
|
ListServices(ctx context.Context, contextName, namespace string) ([]k8s.ServiceInfo, error)
|
|
}
|
|
|
|
// MutatorInterface defines the interface for configuration mutation operations
|
|
// This allows for mocking in tests
|
|
type MutatorInterface interface {
|
|
AddForward(contextName, namespaceName string, fwd config.Forward) error
|
|
RemoveForwards(predicate func(ctx, ns string, fwd config.Forward) bool) error
|
|
RemoveForwardByID(id string) error
|
|
RemoveForwardByIDInContext(contextName, id string) error
|
|
UpdateForward(oldID, newContextName, newNamespaceName string, newFwd config.Forward) error
|
|
UpdateForwardInContext(oldContextName, oldID, newContextName, newNamespaceName string, newFwd config.Forward) error
|
|
}
|
|
|
|
// Compile-time checks to ensure real types implement interfaces
|
|
var _ DiscoveryInterface = (*k8s.Discovery)(nil)
|
|
var _ MutatorInterface = (*config.Mutator)(nil)
|