Skip to content

Commit

Permalink
dataclients/kubernetes: partially create RouteGroup routes on missing…
Browse files Browse the repository at this point in the history
… service (#2796)

Ignore routes that reference missing service.

Signed-off-by: Alexander Yastrebov <[email protected]>
  • Loading branch information
AlexanderYastrebov authored Jan 2, 2024
1 parent d3edfd8 commit d4ea45b
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dataclients/kubernetes/clusterclient_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ func TestLoggingInterval(t *testing.T) {
defer log.SetOutput(os.Stderr)

countMessages := func() int {
return strings.Count(out.String(), "Error transforming external hosts")
return strings.Count(out.String(), "Ignoring route 0: service not found: default/myapp")
}

a, err := kubernetestest.NewAPI(kubernetestest.TestAPIOptions{}, manifest)
Expand Down
13 changes: 10 additions & 3 deletions dataclients/kubernetes/routegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -407,9 +407,13 @@ func transformExplicitGroupRoute(ctx *routeContext) (*eskip.Route, error) {
// explicitGroupRoutes creates routes for those route groups that have the
// `route` field explicitly defined.
func explicitGroupRoutes(ctx *routeGroupContext) ([]*eskip.Route, error) {
var routes []*eskip.Route
var result []*eskip.Route
rg := ctx.routeGroup

nextRoute:
for routeIndex, rgr := range rg.Spec.Routes {
var routes []*eskip.Route

if len(rgr.Methods) == 0 {
rgr.Methods = []string{""}
}
Expand Down Expand Up @@ -437,7 +441,8 @@ func explicitGroupRoutes(ctx *routeGroupContext) ([]*eskip.Route, error) {
backend: be,
})
if err != nil {
return nil, err
ctx.logger.Errorf("Ignoring route %d: %v", routeIndex, err)
continue nextRoute
}

backendTraffic[bref.BackendName].apply(r)
Expand All @@ -447,9 +452,11 @@ func explicitGroupRoutes(ctx *routeGroupContext) ([]*eskip.Route, error) {
routes = appendHTTPSRedirect(ctx, routes, r)
}
}

result = append(result, routes...)
}

return routes, nil
return result, nil
}

func transformRouteGroup(ctx *routeGroupContext) ([]*eskip.Route, error) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Error transforming external hosts: service not found: foo/non-existent
Ignoring route 0: service not found: foo/non-existent
kind=RouteGroup name=myapp-no-service ns=foo
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
kube_rg____example_org__catchall__0_0: Host("^(example[.]org[.]?(:[0-9]+)?)$") -> <shunt>;
kube_rg__default__myapp__all__0_0: Host("^(example[.]org[.]?(:[0-9]+)?)$") && Path("/app1") -> <roundRobin, "http://10.2.4.16:80", "http://10.2.4.8:80">;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
kind=RouteGroup name=myapp
Ignoring route 1: service not found: default/myapp-2
Ignoring route 2: service not found: default/myapp-2
Ignoring route 3: service not found: default/myapp-2
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
apiVersion: zalando.org/v1
kind: RouteGroup
metadata:
name: myapp
spec:
hosts:
- example.org
backends:
- name: myapp-1
type: service
serviceName: myapp-1
servicePort: 80
- name: myapp-2
type: service
serviceName: myapp-2
servicePort: 80
defaultBackends:
- backendName: myapp-2
routes:
- path: /app1
backends:
- backendname: myapp-1
- path: /app2
backends:
- backendname: myapp-2
- path: /split
backends:
- backendname: myapp-1
- backendname: myapp-2
- path: /default

---
apiVersion: v1
kind: Service
metadata:
name: myapp-1
spec:
ports:
- port: 80
protocol: TCP
targetPort: 80
selector:
application: myapp
type: ClusterIP
---
apiVersion: v1
kind: Endpoints
metadata:
name: myapp-1
subsets:
- addresses:
- ip: 10.2.4.8
- ip: 10.2.4.16
ports:
- port: 80
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Error transforming internal hosts: service not found: default/myapp
Ignoring route 0: service not found: default/myapp
kind=RouteGroup name=myapp

0 comments on commit d4ea45b

Please sign in to comment.