Skip to content

Commit

Permalink
Fix logic and ignore annotations that are not template
Browse files Browse the repository at this point in the history
  • Loading branch information
danieloliveira079 committed May 18, 2022
1 parent 4d3467b commit 909c0d8
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/reconcilers/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func WithCustomAnnotationsTemplate() IngressOption {
}

if !strings.Contains(v, "{{") || !strings.Contains(v, "}}") {
return nil
continue
}

t, err := template.New("gs").Parse(v)
Expand Down
63 changes: 63 additions & 0 deletions pkg/reconcilers/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,69 @@ func Test_WithCustomAnnotationsTemplate(t *testing.T) {
wantErr: false,
expected: map[string]string{},
},
{
name: "with custom envoy annotation with template",
gameserverName: "game-10",
annotations: map[string]string{
"octops-projectcontour.io/websocket-routes": "/{{ .Name }}",
},
wantErr: false,
expected: map[string]string{
"projectcontour.io/websocket-routes": "/game-10",
},
},
{
name: "with multiples annotations",
gameserverName: "game-10",
annotations: map[string]string{
"annotation/not-custom": "somevalue",
"octops-projectcontour.io/websocket-routes": "/{{ .Name }}",
},
wantErr: false,
expected: map[string]string{
"projectcontour.io/websocket-routes": "/game-10",
},
},
{
name: "with multiples annotations inverted",
gameserverName: "game-11",
annotations: map[string]string{
"octops-projectcontour.io/websocket-routes": "/{{ .Name }}",
"annotation/not-custom": "somevalue",
},
wantErr: false,
expected: map[string]string{
"projectcontour.io/websocket-routes": "/game-11",
},
},
{
name: "with multiples annotations with template",
gameserverName: "game-12",
annotations: map[string]string{
"octops-projectcontour.io/websocket-routes": "/{{ .Name }}",
"octops-annotation/custom": "custom-{{ .Name }}",
},
wantErr: false,
expected: map[string]string{
"projectcontour.io/websocket-routes": "/game-12",
"annotation/custom": "custom-game-12",
},
},
{
name: "with mixed annotations with template",
gameserverName: "game-13",
annotations: map[string]string{
"annotation/not-custom": "some-value",
"annotation/not-custom-template": "some-{{ .Name }}",
"octops-projectcontour.io/websocket-routes": "/{{ .Name }}",
"octops-annotation/custom": "custom-{{ .Name }}",
},
wantErr: false,
expected: map[string]string{
"projectcontour.io/websocket-routes": "/game-13",
"annotation/custom": "custom-game-13",
},
},
}

for _, tc := range testCase {
Expand Down

0 comments on commit 909c0d8

Please sign in to comment.