Skip to content

Commit

Permalink
feature: comment() filter to comment a given filter chain. (#2905)
Browse files Browse the repository at this point in the history
One example use case is to use it in more complex objects like RouteGroups and have something that is shown also on kubectl edit rg case

Signed-off-by: Sandor Szücs <[email protected]>
  • Loading branch information
szuecs authored Feb 6, 2024
1 parent 250456e commit 3082a04
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
16 changes: 16 additions & 0 deletions docs/reference/filters.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ Example:
route1: Host(/^all401\.example\.org$/) -> status(401) -> <shunt>;
```

## comment

No operation, only to comment the route or a group of filters of a route

Parameters:

* msg (string)

Example:

```
route1: *
-> comment("nothing to see")
-> <shunt>;
```

## HTTP Headers
### preserveHost

Expand Down
1 change: 1 addition & 0 deletions filters/builtin/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const (
func Filters() []filters.Spec {
return []filters.Spec{
NewBackendIsProxy(),
NewComment(),
NewRequestHeader(),
NewSetRequestHeader(),
NewAppendRequestHeader(),
Expand Down
40 changes: 40 additions & 0 deletions filters/builtin/comment.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package builtin

import (
"github.com/zalando/skipper/filters"
"github.com/zalando/skipper/routing"
)

type comment struct{}

// NewComment is a filter to comment a filter chain. It does nothing
func NewComment() filters.Spec {
return &comment{}
}

func (*comment) Name() string {
return filters.CommentName
}

func (c *comment) CreateFilter(args []interface{}) (filters.Filter, error) {
return c, nil
}

func (*comment) Request(filters.FilterContext) {}

func (*comment) Response(filters.FilterContext) {}

type CommentPostProcessor struct{}

func (CommentPostProcessor) Do(routes []*routing.Route) []*routing.Route {
for _, r := range routes {
var ff []*routing.RouteFilter
for _, f := range r.Filters {
if f.Name != filters.CommentName {
ff = append(ff, f)
}
}
r.Filters = ff
}
return routes
}
1 change: 1 addition & 0 deletions filters/filters.go
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ func (r Registry) Register(s Spec) {
// All Skipper filter names
const (
BackendIsProxyName = "backendIsProxy"
CommentName = "comment"
ModRequestHeaderName = "modRequestHeader"
SetRequestHeaderName = "setRequestHeader"
AppendRequestHeaderName = "appendRequestHeader"
Expand Down
1 change: 1 addition & 0 deletions skipper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1910,6 +1910,7 @@ func run(o Options, sig chan os.Signal, idleConnsCH chan struct{}) error {
builtin.NewRouteCreationMetrics(mtr),
fadein.NewPostProcessor(fadein.PostProcessorOptions{EndpointRegistry: endpointRegistry}),
admissionControlSpec.PostProcessor(),
builtin.CommentPostProcessor{},
},
SignalFirstLoad: o.WaitFirstRouteLoad,
}
Expand Down

0 comments on commit 3082a04

Please sign in to comment.