Skip to content

Commit

Permalink
fix new lines in snippets (#4832)
Browse files Browse the repository at this point in the history
* fix new lines in snippets

* add test for server snippet new lines

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
Jim Ryan and pre-commit-ci[bot] authored Dec 21, 2023
1 parent 95f8da6 commit f63f0db
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
6 changes: 3 additions & 3 deletions internal/configs/version2/nginx-plus.transportserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ upstream {{ $u.Name }} {
{{- end }}

{{- range $snippet := .StreamSnippets }}
{{- $snippet }}
{{ end }}
{{ $snippet }}
{{- end }}

{{ with $m := .Match }}
match {{ $m.Name }} {
Expand Down Expand Up @@ -60,7 +60,7 @@ server {
{{- end }}

{{- range $snippet := $s.ServerSnippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

proxy_pass {{ $s.ProxyPass }};
Expand Down
6 changes: 3 additions & 3 deletions internal/configs/version2/nginx-plus.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ map {{ $m.Source }} {{ $m.Variable }} {
{{- end }}

{{- range $snippet := .HTTPSnippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

{{- range $z := .LimitReqZones }}
Expand Down Expand Up @@ -286,7 +286,7 @@ server {
{{- end }}

{{- range $snippet := $s.Snippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

{{- range $l := $s.InternalRedirectLocations }}
Expand Down Expand Up @@ -351,7 +351,7 @@ server {
internal;
{{- end }}
{{- range $snippet := $l.Snippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

{{- with $l.PoliciesErrorReturn }}
Expand Down
4 changes: 2 additions & 2 deletions internal/configs/version2/nginx.transportserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ upstream {{ $u.Name }} {
{{- end }}

{{- range $snippet := .StreamSnippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

{{- $s := .Server }}
Expand Down Expand Up @@ -42,7 +42,7 @@ server {
{{- end }}

{{- range $snippet := $s.ServerSnippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

proxy_pass {{ $s.ProxyPass }};
Expand Down
6 changes: 3 additions & 3 deletions internal/configs/version2/nginx.virtualserver.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ map {{ $m.Source }} {{ $m.Variable }} {
{{- end }}

{{- range $snippet := .HTTPSnippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

{{- range $z := .LimitReqZones }}
Expand Down Expand Up @@ -166,7 +166,7 @@ server {
{{- end }}

{{- range $snippet := $s.Snippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

{{- range $l := $s.InternalRedirectLocations }}
Expand Down Expand Up @@ -208,7 +208,7 @@ server {
internal;
{{- end }}
{{- range $snippet := $l.Snippets }}
{{- $snippet }}
{{ $snippet }}
{{- end }}

{{- with $l.PoliciesErrorReturn }}
Expand Down
5 changes: 4 additions & 1 deletion tests/data/transport-server/transport-server-snippets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions tests/suite/test_transport_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f63f0db

Please sign in to comment.