From 86c01b27421f4c34023f941f4339664bc52805f9 Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Thu, 22 Feb 2024 11:13:09 +0100 Subject: [PATCH] routesrv: require kubernetes option (#2950) Require kubernetes option (explicitly or via -kubernetes flag). Initially routesrv implied this option as it was envisioned for serving Kubernetes dataclient routes. Later an endpoint to serve Redis endpoints was added by #2237 Within #2476 skipper allows Redis endpoints discovery without using kubernetes dataclient for routing. This behaviour is configured by the -kubernetes flag. The plan is to allow routesrv the same - provide Redis endpoints without using Kubernetes dataclient to create routes. This change is the first step that converts implied Kubernetes option into required. This is a breaking change for users that run routesrv without -kubernetes flag or use it from the library without setting Kubernetes option. For #2476 Signed-off-by: Alexander Yastrebov --- VERSION | 2 +- cmd/routesrv/main.go | 4 ++++ redis_test.go | 1 + routesrv/routesrv.go | 5 +++++ routesrv/routesrv_test.go | 12 ++++++++++++ routesrv/shutdown_test.go | 1 + 6 files changed, 24 insertions(+), 1 deletion(-) diff --git a/VERSION b/VERSION index ef27085c8a..6e75c01de5 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -v0.20 +v0.21 diff --git a/cmd/routesrv/main.go b/cmd/routesrv/main.go index 88e800b382..9b3e2206fd 100644 --- a/cmd/routesrv/main.go +++ b/cmd/routesrv/main.go @@ -12,6 +12,10 @@ func main() { log.Fatalf("Error processing config: %s", err) } + if !cfg.KubernetesIngress { + log.Fatalf("-kubernetes flag required") + } + log.SetLevel(cfg.ApplicationLogLevel) if cfg.ApplicationLogJSONEnabled { log.SetFormatter(&log.JSONFormatter{}) diff --git a/redis_test.go b/redis_test.go index 6be128dbc7..9eac1b1924 100644 --- a/redis_test.go +++ b/redis_test.go @@ -136,6 +136,7 @@ spec: rsvo := skipper.Options{ Address: findAddress(t), + Kubernetes: true, KubernetesURL: lb.URL, KubernetesRedisServiceNamespace: "skipper", KubernetesRedisServiceName: "redis", diff --git a/routesrv/routesrv.go b/routesrv/routesrv.go index f1cf459aaa..4c4d249a5c 100644 --- a/routesrv/routesrv.go +++ b/routesrv/routesrv.go @@ -2,6 +2,7 @@ package routesrv import ( "context" + "fmt" "net/http" "os" "os/signal" @@ -85,6 +86,10 @@ func New(opts skipper.Options) (*RouteServer, error) { supportHandler.Handle("/debug/pprof/", metricsHandler) } + if !opts.Kubernetes { + return nil, fmt.Errorf(`option "Kubernetes" is required`) + } + dataclient, err := kubernetes.New(opts.KubernetesDataClientOptions()) if err != nil { return nil, err diff --git a/routesrv/routesrv_test.go b/routesrv/routesrv_test.go index a85e78720e..04e5b51f68 100644 --- a/routesrv/routesrv_test.go +++ b/routesrv/routesrv_test.go @@ -72,6 +72,7 @@ func loadKubeYAML(t *testing.T, path string) io.Reader { func newRouteServer(t *testing.T, kubeServer *httptest.Server) *routesrv.RouteServer { return newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: kubeServer.URL, }) } @@ -249,6 +250,7 @@ func TestRedisEndpointSlices(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, KubernetesRedisServiceNamespace: "namespace1", KubernetesRedisServiceName: "service1", @@ -272,6 +274,7 @@ func TestRedisEndpoints(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, KubernetesRedisServiceNamespace: "namespace1", KubernetesRedisServiceName: "service1", @@ -293,6 +296,7 @@ func TestFetchedIngressRoutesAreServedInEskipFormat(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, }) @@ -376,6 +380,7 @@ func TestRoutesWithDefaultFilters(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, DefaultFilters: &eskip.DefaultFilters{ Prepend: []*eskip.Filter{ @@ -419,6 +424,7 @@ func TestRoutesWithOAuth2Callback(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, EnableOAuth2GrantFlow: true, OAuth2CallbackPath: "/.well-known/oauth2-callback", @@ -450,6 +456,7 @@ func TestRoutesWithEastWest(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, KubernetesEastWestRangeDomains: []string{"ingress.cluster.local"}, KubernetesEastWestRangePredicates: []*eskip.Predicate{ @@ -610,6 +617,7 @@ func TestESkipBytesHandlerWithXCount(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, }) @@ -642,6 +650,7 @@ func TestRoutesWithEditRoute(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, EditRoute: []*eskip.Editor{ eskip.NewEditor(regexp.MustCompile("Host[(](.*)[)]"), "HostAny($1)"), @@ -674,6 +683,7 @@ func TestRoutesWithCloneRoute(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, CloneRoute: []*eskip.Clone{ eskip.NewClone(regexp.MustCompile("Host"), "HostAny"), @@ -706,6 +716,7 @@ func TestRoutesWithExplicitLBAlgorithm(t *testing.T) { defer ks.Close() rs := newRouteServerWithOptions(t, skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, KubernetesDefaultLoadBalancerAlgorithm: "powerOfRandomNChoices", }) @@ -793,6 +804,7 @@ func TestESkipBytesHandlerGzipServedForDefaultClient(t *testing.T) { rs, err := routesrv.New(skipper.Options{ SourcePollTimeout: pollInterval, + Kubernetes: true, KubernetesURL: ks.URL, }) require.NoError(t, err) diff --git a/routesrv/shutdown_test.go b/routesrv/shutdown_test.go index f5a0c43576..04d40223a9 100644 --- a/routesrv/shutdown_test.go +++ b/routesrv/shutdown_test.go @@ -69,6 +69,7 @@ func TestServerShutdownHTTP(t *testing.T) { ks.Start() o := skipper.Options{ + Kubernetes: true, KubernetesURL: "http://" + ks.Listener.Addr().String(), SourcePollTimeout: 500 * time.Millisecond, }