Provide option for kubernetes to watch only a specific namespace (#433)
This commit is contained in:
+21
-4
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user