Skip to content

Commit 55466ca

Browse files
authored
Fix main includes (#2666)
Problem: The main includes were defined twice, causing some issues in reloading nginx. Solution: Deduplicate the code.
1 parent 4626043 commit 55466ca

File tree

10 files changed

+125
-104
lines changed

10 files changed

+125
-104
lines changed

charts/nginx-gateway-fabric/values.schema.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,20 @@
519519
"required": [],
520520
"title": "securityContext",
521521
"type": "object"
522+
},
523+
"snippetsFilters": {
524+
"properties": {
525+
"enable": {
526+
"default": false,
527+
"description": "Enable SnippetsFilters feature. SnippetsFilters allow inserting NGINX configuration into the generated NGINX\nconfig for HTTPRoute and GRPCRoute resources.",
528+
"required": [],
529+
"title": "enable",
530+
"type": "boolean"
531+
}
532+
},
533+
"required": [],
534+
"title": "snippetsFilters",
535+
"type": "object"
522536
}
523537
},
524538
"required": [

deploy/snippets-filters-nginx-plus/deploy.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,19 @@ subjects:
153153
namespace: nginx-gateway
154154
---
155155
apiVersion: v1
156+
data:
157+
main.conf: |
158+
error_log stderr info;
159+
kind: ConfigMap
160+
metadata:
161+
labels:
162+
app.kubernetes.io/instance: nginx-gateway
163+
app.kubernetes.io/name: nginx-gateway
164+
app.kubernetes.io/version: edge
165+
name: nginx-includes
166+
namespace: nginx-gateway
167+
---
168+
apiVersion: v1
156169
kind: Service
157170
metadata:
158171
labels:
@@ -299,6 +312,33 @@ spec:
299312
name: nginx-cache
300313
- mountPath: /etc/nginx/includes
301314
name: nginx-includes
315+
initContainers:
316+
- command:
317+
- /usr/bin/gateway
318+
- copy
319+
- --source
320+
- /includes/main.conf
321+
- --destination
322+
- /etc/nginx/main-includes/main.conf
323+
image: ghcr.io/nginxinc/nginx-gateway-fabric:edge
324+
imagePullPolicy: Always
325+
name: copy-nginx-config
326+
securityContext:
327+
capabilities:
328+
add:
329+
- KILL
330+
drop:
331+
- ALL
332+
readOnlyRootFilesystem: true
333+
runAsGroup: 1001
334+
runAsUser: 102
335+
seccompProfile:
336+
type: RuntimeDefault
337+
volumeMounts:
338+
- mountPath: /includes
339+
name: nginx-includes-configmap
340+
- mountPath: /etc/nginx/main-includes
341+
name: nginx-main-includes
302342
securityContext:
303343
fsGroup: 1001
304344
runAsNonRoot: true
@@ -320,6 +360,9 @@ spec:
320360
name: nginx-cache
321361
- emptyDir: {}
322362
name: nginx-includes
363+
- configMap:
364+
name: nginx-includes
365+
name: nginx-includes-configmap
323366
---
324367
apiVersion: gateway.networking.k8s.io/v1
325368
kind: GatewayClass

deploy/snippets-filters/deploy.yaml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@ subjects:
145145
namespace: nginx-gateway
146146
---
147147
apiVersion: v1
148+
data:
149+
main.conf: |
150+
error_log stderr info;
151+
kind: ConfigMap
152+
metadata:
153+
labels:
154+
app.kubernetes.io/instance: nginx-gateway
155+
app.kubernetes.io/name: nginx-gateway
156+
app.kubernetes.io/version: edge
157+
name: nginx-includes
158+
namespace: nginx-gateway
159+
---
160+
apiVersion: v1
148161
kind: Service
149162
metadata:
150163
labels:
@@ -290,6 +303,33 @@ spec:
290303
name: nginx-cache
291304
- mountPath: /etc/nginx/includes
292305
name: nginx-includes
306+
initContainers:
307+
- command:
308+
- /usr/bin/gateway
309+
- copy
310+
- --source
311+
- /includes/main.conf
312+
- --destination
313+
- /etc/nginx/main-includes/main.conf
314+
image: ghcr.io/nginxinc/nginx-gateway-fabric:edge
315+
imagePullPolicy: Always
316+
name: copy-nginx-config
317+
securityContext:
318+
capabilities:
319+
add:
320+
- KILL
321+
drop:
322+
- ALL
323+
readOnlyRootFilesystem: true
324+
runAsGroup: 1001
325+
runAsUser: 102
326+
seccompProfile:
327+
type: RuntimeDefault
328+
volumeMounts:
329+
- mountPath: /includes
330+
name: nginx-includes-configmap
331+
- mountPath: /etc/nginx/main-includes
332+
name: nginx-main-includes
293333
securityContext:
294334
fsGroup: 1001
295335
runAsNonRoot: true
@@ -311,6 +351,9 @@ spec:
311351
name: nginx-cache
312352
- emptyDir: {}
313353
name: nginx-includes
354+
- configMap:
355+
name: nginx-includes
356+
name: nginx-includes-configmap
314357
---
315358
apiVersion: gateway.networking.k8s.io/v1
316359
kind: GatewayClass

internal/mode/static/nginx/config/generator.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,6 @@ func (g GeneratorImpl) getExecuteFuncs(generator policies.Generator) []executeFu
146146
g.executeStreamUpstreams,
147147
executeStreamMaps,
148148
executeVersion,
149-
executeMainIncludesConfig,
150149
}
151150
}
152151

internal/mode/static/nginx/config/main_config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ import (
1111
var mainConfigTemplate = gotemplate.Must(gotemplate.New("main").Parse(mainConfigTemplateText))
1212

1313
type mainConfig struct {
14-
Includes []shared.Include
15-
TelemetryEnabled bool
14+
Includes []shared.Include
15+
Conf dataplane.Configuration
1616
}
1717

1818
func executeMainConfig(conf dataplane.Configuration) []executeResult {
1919
includes := createIncludesFromSnippets(conf.MainSnippets)
2020

2121
mc := mainConfig{
22-
TelemetryEnabled: conf.Telemetry.Endpoint != "",
23-
Includes: includes,
22+
Conf: conf,
23+
Includes: includes,
2424
}
2525

2626
results := make([]executeResult, 0, len(includes)+1)

internal/mode/static/nginx/config/main_config_template.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package config
22

33
const mainConfigTemplateText = `
4-
{{ if .TelemetryEnabled -}}
4+
{{ if .Conf.Telemetry.Endpoint -}}
55
load_module modules/ngx_otel_module.so;
66
{{ end -}}
77
8+
error_log stderr {{ .Conf.Logging.ErrorLevel }};
9+
810
{{ range $i := .Includes -}}
911
include {{ $i.Name }};
1012
{{ end -}}

internal/mode/static/nginx/config/main_config_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ func TestExecuteMainConfig_Telemetry(t *testing.T) {
5656
}
5757
}
5858

59+
func TestExecuteMainConfig_Logging(t *testing.T) {
60+
t.Parallel()
61+
62+
conf := dataplane.Configuration{
63+
Logging: dataplane.Logging{
64+
ErrorLevel: "info",
65+
},
66+
}
67+
68+
g := NewWithT(t)
69+
70+
res := executeMainConfig(conf)
71+
g.Expect(res).To(HaveLen(1))
72+
g.Expect(res[0].dest).To(Equal(mainIncludesConfigFile))
73+
74+
g.Expect(string(res[0].data)).To(ContainSubstring("error_log stderr info"))
75+
}
76+
5977
func TestExecuteMainConfig_Snippets(t *testing.T) {
6078
t.Parallel()
6179

internal/mode/static/nginx/config/main_includes.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

internal/mode/static/nginx/config/main_includes_template.go

Lines changed: 0 additions & 7 deletions
This file was deleted.

internal/mode/static/nginx/config/main_includes_test.go

Lines changed: 0 additions & 72 deletions
This file was deleted.

0 commit comments

Comments
 (0)