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

[#4479] Add stream-snippet as a ConfigMap option #6404

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 5 additions & 0 deletions docs/user-guide/nginx-configuration/configmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ The following table shows a configuration option's name, type, and the default v
|[datadog-sample-rate](#datadog-sample-rate)|float|1.0|
|[main-snippet](#main-snippet)|string|""|
|[http-snippet](#http-snippet)|string|""|
|[stream-snippet](#stream-snippet)|string|""|
|[server-snippet](#server-snippet)|string|""|
|[location-snippet](#location-snippet)|string|""|
|[custom-http-errors](#custom-http-errors)|[]int|[]int{}|
Expand Down Expand Up @@ -888,6 +889,10 @@ Adds custom configuration to the main section of the nginx configuration.

Adds custom configuration to the http section of the nginx configuration.

## stream-snippet

Adds custom configuration to the stream section of the nginx configuration.

## server-snippet

Adds custom configuration to all the servers in the nginx configuration.
Expand Down
3 changes: 3 additions & 0 deletions internal/ingress/controller/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -613,6 +613,9 @@ type Configuration struct {
// HTTPSnippet adds custom configuration to the http section of the nginx configuration
HTTPSnippet string `json:"http-snippet"`

// StreamSnippet adds custom configuration to the stream section of the nginx configuration
StreamSnippet string `json:"stream-snippet"`

// ServerSnippet adds custom configuration to all the servers in the nginx configuration
ServerSnippet string `json:"server-snippet"`

Expand Down
5 changes: 5 additions & 0 deletions rootfs/etc/nginx/template/nginx.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,11 @@ stream {
{{ end }}
{{ end }}

{{ if not (empty $cfg.StreamSnippet) }}
# Custom code snippet configured in the configuration configmap
{{ $cfg.StreamSnippet }}
{{ end }}

upstream upstream_balancer {
server 0.0.0.1:1234; # placeholder

Expand Down
40 changes: 40 additions & 0 deletions test/e2e/settings/stream_snippet.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
Copyright 2020 The Kubernetes Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package settings

import (
"strings"

"github.com/onsi/ginkgo"

"k8s.io/ingress-nginx/test/e2e/framework"
)

var _ = framework.DescribeSetting("stream-snippet", func() {
f := framework.NewDefaultFramework("stream-snippet")
streamSnippet := "stream-snippet"

ginkgo.It("should add value of stream-snippet setting to nginx config", func() {
expectedComment := "# stream snippet"
f.UpdateNginxConfigMapData(streamSnippet, expectedComment)

f.WaitForNginxConfiguration(
func(cfg string) bool {
return strings.Contains(cfg, expectedComment)
})
})
})