Provide option for kubernetes to watch only a specific namespace (#433)

This commit is contained in:
Geoff Bourne
2025-07-20 12:59:14 -05:00
committed by GitHub
parent 9a457138ab
commit 7a4f83a30f
19 changed files with 663 additions and 142 deletions
+21 -4
View File
@@ -120,18 +120,27 @@ func NewServer(ctx context.Context, config *Config) (*Server, error) {
StartApiServer(config.ApiBinding)
}
routeWatchers := make([]RouteFinder, 0)
if config.InKubeCluster {
err = K8sWatcher.StartInCluster(ctx, config.AutoScale.Up, config.AutoScale.Down)
k8sWatcher, err := NewK8sWatcherInCluster()
if err != nil {
return nil, fmt.Errorf("could not start in-cluster k8s integration: %w", err)
return nil, fmt.Errorf("could not create in-cluster k8s watcher: %w", err)
}
k8sWatcher.WithAutoScale(config.AutoScale.Up, config.AutoScale.Down)
k8sWatcher.WithNamespace(config.KubeNamespace)
routeWatchers = append(routeWatchers, k8sWatcher)
} else if config.KubeConfig != "" {
err := K8sWatcher.StartWithConfig(ctx, config.KubeConfig, config.AutoScale.Up, config.AutoScale.Down)
k8sWatcher, err := NewK8sWatcherWithConfig(config.KubeConfig)
if err != nil {
return nil, fmt.Errorf("could not start k8s integration with kube config: %w", err)
return nil, fmt.Errorf("could not create k8s watcher with kube config: %w", err)
}
k8sWatcher.WithAutoScale(config.AutoScale.Up, config.AutoScale.Down)
k8sWatcher.WithNamespace(config.KubeNamespace)
routeWatchers = append(routeWatchers, k8sWatcher)
}
// TODO convert to RouteFinder
if config.InDocker {
err = DockerWatcher.Start(config.DockerSocket, config.DockerTimeout, config.DockerRefreshInterval, config.AutoScale.Up, config.AutoScale.Down)
if err != nil {
@@ -141,6 +150,7 @@ func NewServer(ctx context.Context, config *Config) (*Server, error) {
}
}
// TODO convert to RouteFinder
if config.InDockerSwarm {
err = DockerSwarmWatcher.Start(config.DockerSocket, config.DockerTimeout, config.DockerRefreshInterval, config.AutoScale.Up, config.AutoScale.Down)
if err != nil {
@@ -150,6 +160,13 @@ func NewServer(ctx context.Context, config *Config) (*Server, error) {
}
}
for _, watcher := range routeWatchers {
err := watcher.Start(ctx, Routes)
if err != nil {
return nil, fmt.Errorf("could not start route watcher %s: %w", watcher, err)
}
}
Routes.SimplifySRV(config.SimplifySRV)
err = metricsBuilder.Start(ctx)