Skip to content

Commit f4709eb

Browse files
pleshakovsoneillf5
andauthored
Apply -enable-snippets cli arg to Ingresses (#2124)
* Apply -enable-snippets cli arg to Ingresses * Update docs * add snippet flag python tests * removing snippets check as we rely on validation * removing used param Co-authored-by: Sean O'Neill <[email protected]>
1 parent fea3c77 commit f4709eb

File tree

15 files changed

+162
-33
lines changed

15 files changed

+162
-33
lines changed

cmd/nginx-ingress/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ var (
154154
"Enable preview policies")
155155

156156
enableSnippets = flag.Bool("enable-snippets", false,
157-
"Enable custom NGINX configuration snippets in VirtualServer, VirtualServerRoute and TransportServer resources.")
157+
"Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources.")
158158

159159
globalConfiguration = flag.String("global-configuration", "",
160160
`The namespace/name of the GlobalConfiguration resource for global configuration of the Ingress Controller. Requires -enable-custom-resources. Format: <namespace>/<name>`)
@@ -638,6 +638,7 @@ func main() {
638638
IsPrometheusEnabled: *enablePrometheusMetrics,
639639
IsLatencyMetricsEnabled: *enableLatencyMetrics,
640640
IsTLSPassthroughEnabled: *enableTLSPassthrough,
641+
SnippetsEnabled: *enableSnippets,
641642
}
642643

643644
lbc := k8s.NewLoadBalancerController(lbcInput)

deployments/helm-chart/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Parameter | Description | Default
180180
`controller.enableTLSPassthrough` | Enable TLS Passthrough on port 443. Requires `controller.enableCustomResources`. | false
181181
`controller.globalConfiguration.create` | Creates the GlobalConfiguration custom resource. Requires `controller.enableCustomResources`. | false
182182
`controller.globalConfiguration.spec` | The spec of the GlobalConfiguration for defining the global configuration parameters of the Ingress Controller. | {}
183-
`controller.enableSnippets` | Enable custom NGINX configuration snippets in VirtualServer, VirtualServerRoute and TransportServer resources. | false
183+
`controller.enableSnippets` | Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources. | false
184184
`controller.healthStatus` | Add a location "/nginx-health" to the default server. The location responds with the 200 status code for any request. Useful for external health-checking of the Ingress controller. | false
185185
`controller.healthStatusURI` | Sets the URI of health status location in the default server. Requires `controller.healthStatus`. | "/nginx-health"
186186
`controller.nginxStatus.enable` | Enable the NGINX stub_status, or the NGINX Plus API. | true

deployments/helm-chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ controller:
155155
# port: 5353
156156
# protocol: TCP
157157

158-
## Enable custom NGINX configuration snippets in VirtualServer, VirtualServerRoute and TransportServer resources.
158+
## Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources.
159159
enableSnippets: false
160160

161161
## Add a location based on the value of health-status-uri to the default server. The location responds with the 200 status code for any request.

docs/content/configuration/global-configuration/command-line-arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ Below we describe the available command-line arguments:
1818

1919
### -enable-snippets
2020

21-
Enable custom NGINX configuration snippets in VirtualServer, VirtualServerRoute and TransportServer resources.
21+
Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources.
2222

2323
Default `false`.
2424
&nbsp;

docs/content/configuration/ingress-resources/advanced-configuration-with-snippets.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ server {
8181
## Summary of Snippets
8282

8383
See the [snippets annotations](/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/#snippets-and-custom-templates) documentation for more information.
84+
However, because of the disadvantages described below, snippets are disabled by default. To use snippets, set the [`enable-snippets`](/nginx-ingress-controller/configuration/global-configuration/command-line-arguments#cmdoption-enable-snippets) command-line argument.
8485

8586
## Disadvantages of Using Snippets
8687

docs/content/configuration/security.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ We recommend the following for the most secure configuration:
4141
we recommend [configuring HTTPS](/nginx-ingress-controller/configuration/global-configuration/command-line-arguments/#cmdoption-prometheus-tls-secret) for Prometheus.
4242

4343
### Snippets
44-
[Snippets](/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-snippets/)
45-
Snippets will be disabled by default in the future.
46-
Be sure to understand the implications of configurations you provide through the Snippets capability.
44+
45+
Snippets allow you to insert raw NGINX config into different contexts of NGINX configuration and are supported for [Ingress](/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-snippets/), [VirtualServer/VirtualServerRoute](/nginx-ingress-controller/configuration/virtualserver-and-virtualserverroute-resources/#using-snippets), and [TransportServer](/nginx-ingress-controller/configuration/transportserver-resource/#using-snippets) resources. Additionally, the [ConfigMap](/nginx-ingress-controller/configuration/global-configuration/configmap-resource#snippets-and-custom-templates) resource configures snippets globally.
46+
47+
Snippets are disabled by default. To use snippets, set the [`enable-snippets`](/nginx-ingress-controller/configuration/global-configuration/command-line-arguments#cmdoption-enable-snippets) command-line argument. Note that for the ConfigMap resource, snippets are always enabled.

docs/content/installation/installation-with-helm.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ The following tables lists the configurable parameters of the NGINX Ingress cont
181181
|``controller.enableTLSPassthrough`` | Enable TLS Passthrough on port 443. Requires ``controller.enableCustomResources``. | false |
182182
|``controller.globalConfiguration.create`` | Creates the GlobalConfiguration custom resource. Requires ``controller.enableCustomResources``. | false |
183183
|``controller.globalConfiguration.spec`` | The spec of the GlobalConfiguration for defining the global configuration parameters of the Ingress Controller. | {} |
184-
|``controller.enableSnippets`` | Enable custom NGINX configuration snippets in VirtualServer, VirtualServerRoute and TransportServer resources. | false |
184+
|``controller.enableSnippets`` | Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources. | false |
185185
|``controller.healthStatus`` | Add a location "/nginx-health" to the default server. The location responds with the 200 status code for any request. Useful for external health-checking of the Ingress controller. | false |
186186
|``controller.healthStatusURI`` | Sets the URI of health status location in the default server. Requires ``controller.healthStatus``. | "/nginx-health" |
187187
|``controller.nginxStatus.enable`` | Enable the NGINX stub_status, or the NGINX Plus API. | true |

docs/content/third-party-modules/opentracing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ The Ingress Controller supports [OpenTracing](https://opentracing.io/) with the
1313

1414
This document explains how to use OpenTracing with the Ingress Controller.
1515

16+
**Note**: The examples below use the snippets annotations, which are disabled by default. To use snippets, set the [`enable-snippets`](/nginx-ingress-controller/configuration/global-configuration/command-line-arguments#cmdoption-enable-snippets) command-line argument.
17+
1618
## Prerequisites
1719
1. **Use the Ingress Controller image with OpenTracing.** You can find the images with NGINX or NGINX Plus with OpenTracing listed [here](/nginx-ingress-controller/technical-specifications/#supported-docker-images). Alternatively, you can follow the build instructions to build the image using `debian-image-opentracing` for NGINX or `debian-image-opentracing-plus` for NGINX Plus.
1820
[Jaeger](https://github.com/jaegertracing/jaeger-client-cpp), [Zipkin](https://github.com/rnburn/zipkin-cpp-opentracing) and [Datadog](https://github.com/DataDog/dd-opentracing-cpp/) tracers are installed by default.

internal/k8s/configuration.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,7 @@ type Configuration struct {
348348
appProtectEnabled bool
349349
internalRoutesEnabled bool
350350
isTLSPassthroughEnabled bool
351+
snippetsEnabled bool
351352

352353
lock sync.RWMutex
353354
}
@@ -362,6 +363,7 @@ func NewConfiguration(
362363
globalConfigurationValidator *validation.GlobalConfigurationValidator,
363364
transportServerValidator *validation.TransportServerValidator,
364365
isTLSPassthroughEnabled bool,
366+
snippetsEnabled bool,
365367
) *Configuration {
366368
return &Configuration{
367369
hosts: make(map[string]Resource),
@@ -385,6 +387,7 @@ func NewConfiguration(
385387
appProtectEnabled: appProtectEnabled,
386388
internalRoutesEnabled: internalRoutesEnabled,
387389
isTLSPassthroughEnabled: isTLSPassthroughEnabled,
390+
snippetsEnabled: snippetsEnabled,
388391
}
389392
}
390393

@@ -399,7 +402,7 @@ func (c *Configuration) AddOrUpdateIngress(ing *networking.Ingress) ([]ResourceC
399402
if !c.hasCorrectIngressClass(ing) {
400403
delete(c.ingresses, key)
401404
} else {
402-
validationError = validateIngress(ing, c.isPlus, c.appProtectEnabled, c.internalRoutesEnabled).ToAggregate()
405+
validationError = validateIngress(ing, c.isPlus, c.appProtectEnabled, c.internalRoutesEnabled, c.snippetsEnabled).ToAggregate()
403406
if validationError != nil {
404407
delete(c.ingresses, key)
405408
} else {

internal/k8s/configuration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ func createTestConfiguration() *Configuration {
3434
}),
3535
validation.NewTransportServerValidator(isTLSPassthroughEnabled, snippetsEnabled, isPlus),
3636
isTLSPassthroughEnabled,
37+
snippetsEnabled,
3738
)
3839
}
3940

0 commit comments

Comments
 (0)