Skip to content

Commit

Permalink
routesrv: require kubernetes option
Browse files Browse the repository at this point in the history
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 <alexander.yastrebov@zalando.de>
  • Loading branch information
AlexanderYastrebov committed Feb 21, 2024
1 parent d4e9b79 commit 8cbf03b
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v0.20
v0.21
1 change: 1 addition & 0 deletions redis_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ spec:

rsvo := skipper.Options{
Address: findAddress(t),
Kubernetes: true,
KubernetesURL: lb.URL,
KubernetesRedisServiceNamespace: "skipper",
KubernetesRedisServiceName: "redis",
Expand Down
5 changes: 5 additions & 0 deletions routesrv/routesrv.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package routesrv

import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -85,6 +86,10 @@ func New(opts skipper.Options) (*RouteServer, error) {
supportHandler.Handle("/debug/pprof/", metricsHandler)
}

if !opts.Kubernetes {
return nil, fmt.Errorf("kubernetes option is required")
}

dataclient, err := kubernetes.New(opts.KubernetesDataClientOptions())
if err != nil {
return nil, err
Expand Down
12 changes: 12 additions & 0 deletions routesrv/routesrv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -293,6 +296,7 @@ func TestFetchedIngressRoutesAreServedInEskipFormat(t *testing.T) {
defer ks.Close()
rs := newRouteServerWithOptions(t, skipper.Options{
SourcePollTimeout: pollInterval,
Kubernetes: true,
KubernetesURL: ks.URL,
})

Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -610,6 +617,7 @@ func TestESkipBytesHandlerWithXCount(t *testing.T) {
defer ks.Close()
rs := newRouteServerWithOptions(t, skipper.Options{
SourcePollTimeout: pollInterval,
Kubernetes: true,
KubernetesURL: ks.URL,
})

Expand Down Expand Up @@ -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)"),
Expand Down Expand Up @@ -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"),
Expand Down Expand Up @@ -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",
})
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions routesrv/shutdown_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit 8cbf03b

Please sign in to comment.