diff --git a/internal/configs/version2/nginx-plus.transportserver.tmpl b/internal/configs/version2/nginx-plus.transportserver.tmpl index b3d59172d4..f3e47b3a42 100644 --- a/internal/configs/version2/nginx-plus.transportserver.tmpl +++ b/internal/configs/version2/nginx-plus.transportserver.tmpl @@ -18,8 +18,8 @@ upstream {{ $u.Name }} { {{- end }} {{- range $snippet := .StreamSnippets }} -{{- $snippet }} -{{ end }} +{{ $snippet }} +{{- end }} {{ with $m := .Match }} match {{ $m.Name }} { @@ -60,7 +60,7 @@ server { {{- end }} {{- range $snippet := $s.ServerSnippets }} - {{- $snippet }} + {{ $snippet }} {{- end }} proxy_pass {{ $s.ProxyPass }}; diff --git a/internal/configs/version2/nginx-plus.virtualserver.tmpl b/internal/configs/version2/nginx-plus.virtualserver.tmpl index b8c2ba27da..2f6a3faa59 100644 --- a/internal/configs/version2/nginx-plus.virtualserver.tmpl +++ b/internal/configs/version2/nginx-plus.virtualserver.tmpl @@ -48,7 +48,7 @@ map {{ $m.Source }} {{ $m.Variable }} { {{- end }} {{- range $snippet := .HTTPSnippets }} -{{- $snippet }} +{{ $snippet }} {{- end }} {{- range $z := .LimitReqZones }} @@ -286,7 +286,7 @@ server { {{- end }} {{- range $snippet := $s.Snippets }} - {{- $snippet }} + {{ $snippet }} {{- end }} {{- range $l := $s.InternalRedirectLocations }} @@ -351,7 +351,7 @@ server { internal; {{- end }} {{- range $snippet := $l.Snippets }} - {{- $snippet }} + {{ $snippet }} {{- end }} {{- with $l.PoliciesErrorReturn }} diff --git a/internal/configs/version2/nginx.transportserver.tmpl b/internal/configs/version2/nginx.transportserver.tmpl index 901def05fa..15f0a97fd0 100644 --- a/internal/configs/version2/nginx.transportserver.tmpl +++ b/internal/configs/version2/nginx.transportserver.tmpl @@ -14,7 +14,7 @@ upstream {{ $u.Name }} { {{- end }} {{- range $snippet := .StreamSnippets }} -{{- $snippet }} +{{ $snippet }} {{- end }} {{- $s := .Server }} @@ -42,7 +42,7 @@ server { {{- end }} {{- range $snippet := $s.ServerSnippets }} - {{- $snippet }} + {{ $snippet }} {{- end }} proxy_pass {{ $s.ProxyPass }}; diff --git a/internal/configs/version2/nginx.virtualserver.tmpl b/internal/configs/version2/nginx.virtualserver.tmpl index 6469634d59..da6fa1985a 100644 --- a/internal/configs/version2/nginx.virtualserver.tmpl +++ b/internal/configs/version2/nginx.virtualserver.tmpl @@ -32,7 +32,7 @@ map {{ $m.Source }} {{ $m.Variable }} { {{- end }} {{- range $snippet := .HTTPSnippets }} -{{- $snippet }} +{{ $snippet }} {{- end }} {{- range $z := .LimitReqZones }} @@ -166,7 +166,7 @@ server { {{- end }} {{- range $snippet := $s.Snippets }} - {{- $snippet }} + {{ $snippet }} {{- end }} {{- range $l := $s.InternalRedirectLocations }} @@ -208,7 +208,7 @@ server { internal; {{- end }} {{- range $snippet := $l.Snippets }} - {{- $snippet }} + {{ $snippet }} {{- end }} {{- with $l.PoliciesErrorReturn }} diff --git a/tests/data/transport-server/transport-server-snippets.yaml b/tests/data/transport-server/transport-server-snippets.yaml index ec3c58ba99..8665463603 100644 --- a/tests/data/transport-server/transport-server-snippets.yaml +++ b/tests/data/transport-server/transport-server-snippets.yaml @@ -4,7 +4,10 @@ metadata: name: transport-server spec: streamSnippets: limit_conn_zone $binary_remote_addr zone=addr:10m; - serverSnippets: limit_conn addr 1; + serverSnippets: | + limit_conn addr 1; + # a comment is allowed in snippets + add_header X-test-header "test-value"; listener: name: dns-tcp protocol: TCP diff --git a/tests/suite/test_transport_server.py b/tests/suite/test_transport_server.py index fa72fbd694..4af17653dc 100644 --- a/tests/suite/test_transport_server.py +++ b/tests/suite/test_transport_server.py @@ -55,10 +55,11 @@ def test_snippets( transport_server_setup.namespace, ) - assert ( - "limit_conn_zone $binary_remote_addr zone=addr:10m;" in conf # stream-snippets - and "limit_conn addr 1;" in conf # server-snippets - ) + conf_lines = [line.strip() for line in conf.split("\n")] + assert "limit_conn_zone $binary_remote_addr zone=addr:10m;" in conf_lines # stream-snippets on separate line + assert "limit_conn addr 1;" in conf_lines # server-snippets on separate line + assert "# a comment is allowed in snippets" in conf_lines # comments are allowed in server snippets + assert 'add_header X-test-header "test-value";' in conf_lines # new line in server-snippets on separate line def test_configurable_timeout_directives( self, kube_apis, crd_ingress_controller, transport_server_setup, ingress_controller_prerequisites