Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snippets cherry pick #5059

Merged
merged 4 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading