Skip to content

Commit 1e902ab

Browse files
pleshakovsoneillf5
authored andcommitted
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 0e0f9a0 commit 1e902ab

File tree

14 files changed

+154
-30
lines changed

14 files changed

+154
-30
lines changed

cmd/nginx-ingress/main.go

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

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

172172
globalConfiguration = flag.String("global-configuration", "",
173173
`The namespace/name of the GlobalConfiguration resource for global configuration of the Ingress Controller. Requires -enable-custom-resources. Format: <namespace>/<name>`)
@@ -655,6 +655,7 @@ func main() {
655655
IsPrometheusEnabled: *enablePrometheusMetrics,
656656
IsLatencyMetricsEnabled: *enableLatencyMetrics,
657657
IsTLSPassthroughEnabled: *enableTLSPassthrough,
658+
SnippetsEnabled: *enableSnippets,
658659
}
659660

660661
lbc := k8s.NewLoadBalancerController(lbcInput)

deployments/helm-chart/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ Parameter | Description | Default
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

deployments/helm-chart/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ controller:
168168
# port: 5353
169169
# protocol: TCP
170170

171-
## Enable custom NGINX configuration snippets in VirtualServer, VirtualServerRoute and TransportServer resources.
171+
## Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources.
172172
enableSnippets: false
173173

174174
## 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-web/configuration/global-configuration/command-line-arguments.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Below we describe the available command-line arguments:
88
```eval_rst
99
.. option:: -enable-snippets
1010
11-
Enable custom NGINX configuration snippets in VirtualServer, VirtualServerRoute and TransportServer resources. (default false)
11+
Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources. (default false)
1212
1313
.. option:: -default-server-tls-secret <string>
1414

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

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

7070
See the [snippets annotations](/nginx-ingress-controller/configuration/ingress-resources/advanced-configuration-with-annotations/#snippets-and-custom-templates) documentation for more information.
71+
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.
7172

7273
## Disadvantages of Using Snippets
7374

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ The following tables lists the configurable parameters of the NGINX Ingress cont
252252
- The spec of the GlobalConfiguration for defining the global configuration parameters of the Ingress Controller.
253253
- {}
254254
* - ``controller.enableSnippets``
255-
- Enable custom NGINX configuration snippets in VirtualServer, VirtualServerRoute and TransportServer resources.
255+
- Enable custom NGINX configuration snippets in Ingress, VirtualServer, VirtualServerRoute and TransportServer resources.
256256
- false
257257
* - ``controller.healthStatus``
258258
- 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.

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

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

55
This document explains how to use OpenTracing with the Ingress Controller.
66

7+
**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.
8+
79
## Prerequisites
810
1. **Use the Ingress Controller image with OpenTracing.** The default Ingress Controller images don’t include the OpenTracing module. To use OpenTracing, you need to build the image with that module. Follow the build instructions to build the image using `openshift-image` for NGINX or `openshift-image-plus` for NGINX Plus.
911
By default, the Dockerfiles install Jaeger as a tracer. However, it is possible to replace Jaeger with other supported [tracers](https://github.com/opentracing-contrib/nginx-opentracing#building-from-source). For that, please modify the Dockerfile accordingly:

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
@@ -35,6 +35,7 @@ func createTestConfiguration() *Configuration {
3535
}),
3636
validation.NewTransportServerValidator(isTLSPassthroughEnabled, snippetsEnabled, isPlus),
3737
isTLSPassthroughEnabled,
38+
snippetsEnabled,
3839
)
3940
}
4041

internal/k8s/controller.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ type NewLoadBalancerControllerInput struct {
186186
IsPrometheusEnabled bool
187187
IsLatencyMetricsEnabled bool
188188
IsTLSPassthroughEnabled bool
189+
SnippetsEnabled bool
189190
}
190191

191192
// NewLoadBalancerController creates a controller
@@ -308,7 +309,8 @@ func NewLoadBalancerController(input NewLoadBalancerControllerInput) *LoadBalanc
308309
input.VirtualServerValidator,
309310
input.GlobalConfigurationValidator,
310311
input.TransportServerValidator,
311-
input.IsTLSPassthroughEnabled)
312+
input.IsTLSPassthroughEnabled,
313+
input.SnippetsEnabled)
312314

313315
lbc.appProtectConfiguration = appprotect.NewConfiguration()
314316

0 commit comments

Comments
 (0)