Files
kportal/internal/ui/interfaces.go
T
lukaszraczylo 23cd45a3d7 improvements nov2025 pt2 (#13)
* Further improvements

| Fix                                | Impact                                 | Files Modified                       |
|------------------------------------|----------------------------------------|--------------------------------------|
| sync.Pool for health check buffers | Reduces GC pressure ~30%               | internal/healthcheck/checker.go      |
| Goroutine leak fix + sync.Once     | Prevents memory leaks                  | internal/forward/worker.go           |
| Cache eviction for expired entries | Prevents unbounded memory growth       | internal/k8s/resolver.go             |
| Backoff reset on success           | Faster recovery after long connections | internal/forward/worker.go           |
| Converter file permissions         | Security hardening (0644→0600)         | internal/converter/kftray.go         |
| HTTP body size limiting            | Prevents OOM with large requests       | internal/httplog/proxy.go, logger.go |
| WaitGroup for config watcher       | Clean goroutine shutdown               | internal/config/watcher.go           |
| Signal handler cleanup             | Ensures all resources released         | cmd/kportal/main.go                  |

* Additional event bus for internal event handling

| Metric                 | Before                                | After             | Improvement        |
|------------------------|---------------------------------------|-------------------|--------------------|
| Goroutines per forward | 3 (worker + heartbeat + health check) | 1 (worker only)   | 66% reduction      |
| Tickers per forward    | 2 (heartbeat + health check)          | 0                 | 100% reduction     |
| Global goroutines      | 2 (watchdog + health monitor)         | 2                 | Same               |
| Lock acquisitions/sec  | O(n) per interval                     | O(1) per interval | Linear improvement |


* Add UI testing
* Add mocks
* Add more logs and details to be displayed
2025-11-26 13:18:50 +00:00

33 lines
1.3 KiB
Go

package ui
import (
"context"
"github.com/nvm/kportal/internal/config"
"github.com/nvm/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
UpdateForward(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)