Skip to content

Commit

Permalink
fix(annotations) use "." as header separator (#3155)
Browse files Browse the repository at this point in the history
Co-authored-by: Travis Raines <571832+rainest@users.noreply.github.com>
  • Loading branch information
randmonkey and rainest committed Nov 10, 2022
1 parent a0bf26e commit c1890e6
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,12 @@ Adding a new version? You'll need three changes:
[#3121](https://github.com/Kong/kubernetes-ingress-controller/pull/3121)
- Services support annotations for retries.
[#3121](https://github.com/Kong/kubernetes-ingress-controller/pull/3121)
- Routes support annotations for headers.
- Routes support annotations for headers. These use a special
`konghq.com/headers.HEADERNAME` format. For example, adding
`konghq.com/headers.x-example: green` to an Ingress will create routes that
only match requests with an `x-example: green` request header.
[#3121](https://github.com/Kong/kubernetes-ingress-controller/pull/3121)
[#3155](https://github.com/Kong/kubernetes-ingress-controller/pull/3155)
- Routes support annotations for path handling.
[#3121](https://github.com/Kong/kubernetes-ingress-controller/pull/3121)
- Warning events are recorded when CA secrets cannot be properly translated into Kong configuration.
Expand Down
2 changes: 1 addition & 1 deletion internal/annotations/annotations.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ func ExtractRetries(anns map[string]string) (string, bool) {
// ExtractHeaders extracts the parsed headers annotations values. It returns a map of header names to slices of values.
func ExtractHeaders(anns map[string]string) (map[string][]string, bool) {
headers := make(map[string][]string)
prefix := AnnotationPrefix + HeadersKey + "/"
prefix := AnnotationPrefix + HeadersKey + "."
for key, val := range anns {
if strings.HasPrefix(key, prefix) {
header := strings.TrimPrefix(key, prefix)
Expand Down
4 changes: 2 additions & 2 deletions internal/annotations/annotations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ func TestExtractHeaders(t *testing.T) {
name: "non-empty",
args: args{
anns: map[string]string{
"konghq.com/headers/foo": "foo",
"konghq.com/headers.foo": "foo",
},
},
want: map[string][]string{"foo": {"foo"}},
Expand All @@ -867,7 +867,7 @@ func TestExtractHeaders(t *testing.T) {
name: "no header name",
args: args{
anns: map[string]string{
"konghq.com/headers/": "foo",
"konghq.com/headers.": "foo",
},
},
want: map[string][]string{},
Expand Down
12 changes: 6 additions & 6 deletions internal/dataplane/kongstate/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ func TestOverrideHeaders(t *testing.T) {
name: "single header single value",
args: args{
anns: map[string]string{
"konghq.com/headers/x-example": "example",
"konghq.com/headers.x-example": "example",
},
},
want: Route{
Expand All @@ -1086,7 +1086,7 @@ func TestOverrideHeaders(t *testing.T) {
name: "single header multi value",
args: args{
anns: map[string]string{
"konghq.com/headers/x-example": "foo,bar",
"konghq.com/headers.x-example": "foo,bar",
},
},
want: Route{
Expand All @@ -1099,8 +1099,8 @@ func TestOverrideHeaders(t *testing.T) {
name: "multi header single value",
args: args{
anns: map[string]string{
"konghq.com/headers/x-foo": "example",
"konghq.com/headers/x-bar": "example",
"konghq.com/headers.x-foo": "example",
"konghq.com/headers.x-bar": "example",
},
},
want: Route{
Expand All @@ -1116,8 +1116,8 @@ func TestOverrideHeaders(t *testing.T) {
name: "multi header multi value",
args: args{
anns: map[string]string{
"konghq.com/headers/x-foo": "foo,bar",
"konghq.com/headers/x-bar": "bar,baz",
"konghq.com/headers.x-foo": "foo,bar",
"konghq.com/headers.x-bar": "bar,baz",
},
},
want: Route{
Expand Down

0 comments on commit c1890e6

Please sign in to comment.