Skip to content

Commit e452511

Browse files
committed
Fix events block error
1 parent ca42cd7 commit e452511

File tree

7 files changed

+74
-13
lines changed

7 files changed

+74
-13
lines changed

internal/controller/nginx/conf/nginx-plus.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ worker_processes auto;
55

66
pid /var/run/nginx/nginx.pid;
77

8+
events {
9+
include /etc/nginx/events-includes/*.conf;
10+
}
11+
812
http {
913
include /etc/nginx/conf.d/*.conf;
1014
include /etc/nginx/mime.types;

internal/controller/nginx/conf/nginx.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ worker_processes auto;
55

66
pid /var/run/nginx/nginx.pid;
77

8+
events {
9+
include /etc/nginx/events-includes/*.conf;
10+
}
11+
812
http {
913
include /etc/nginx/conf.d/*.conf;
1014
include /etc/nginx/mime.types;

internal/controller/nginx/config/generator.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ const (
3838
// For example, these files include load_module directives and snippets that target the main context.
3939
mainIncludesFolder = configFolder + "/main-includes"
4040

41+
// eventsIncludesFolder is the folder where NGINX events context configuration files are stored.
42+
eventsIncludesFolder = configFolder + "/events-includes"
43+
4144
// secretsFolder is the folder where secrets (like TLS certs/keys) are stored.
4245
secretsFolder = configFolder + "/secrets"
4346

@@ -56,6 +59,9 @@ const (
5659
// mainIncludesConfigFile is the path to the file containing NGINX configuration in the main context.
5760
mainIncludesConfigFile = mainIncludesFolder + "/main.conf"
5861

62+
// eventsIncludesConfigFile is the path to the file containing NGINX events configuration.
63+
eventsIncludesConfigFile = eventsIncludesFolder + "/events.conf"
64+
5965
// mgmtIncludesFile is the path to the file containing the NGINX Plus mgmt config.
6066
mgmtIncludesFile = mainIncludesFolder + "/mgmt.conf"
6167

@@ -196,6 +202,7 @@ func (g GeneratorImpl) getExecuteFuncs(
196202
) []executeFunc {
197203
return []executeFunc{
198204
executeMainConfig,
205+
executeEventsConfig,
199206
executeBaseHTTPConfig,
200207
g.newExecuteServersFunc(generator, keepAliveCheck),
201208
newExecuteUpstreamsFunc(upstreams),

internal/controller/nginx/config/main_config.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ import (
1515
)
1616

1717
var (
18-
mainConfigTemplate = gotemplate.Must(gotemplate.New("main").Parse(mainConfigTemplateText))
19-
mgmtConfigTemplate = gotemplate.Must(gotemplate.New("mgmt").Parse(mgmtConfigTemplateText))
18+
mainConfigTemplate = gotemplate.Must(gotemplate.New("main").Parse(mainConfigTemplateText))
19+
mgmtConfigTemplate = gotemplate.Must(gotemplate.New("mgmt").Parse(mgmtConfigTemplateText))
20+
eventsConfigTemplate = gotemplate.Must(gotemplate.New("events").Parse(eventsConfigTemplateText))
2021
)
2122

2223
type mainConfig struct {
@@ -42,6 +43,17 @@ func executeMainConfig(conf dataplane.Configuration) []executeResult {
4243
return results
4344
}
4445

46+
func executeEventsConfig(conf dataplane.Configuration) []executeResult {
47+
eventsData := helpers.MustExecuteTemplate(eventsConfigTemplate, conf)
48+
49+
return []executeResult{
50+
{
51+
dest: eventsIncludesConfigFile,
52+
data: eventsData,
53+
},
54+
}
55+
}
56+
4557
type mgmtConf struct {
4658
Endpoint string
4759
Resolver string

internal/controller/nginx/config/main_config_template.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@ load_module modules/ngx_otel_module.so;
77
88
error_log stderr {{ .Conf.Logging.ErrorLevel }};
99
10-
events {
11-
worker_connections {{ .Conf.WorkerConnections }};
12-
}
1310
1411
{{ range $i := .Includes -}}
1512
include {{ $i.Name }};
1613
{{ end -}}
1714
`
1815

16+
const eventsConfigTemplateText = `
17+
worker_connections {{ .WorkerConnections }};
18+
`
19+
1920
const mgmtConfigTemplateText = `
2021
mgmt {
2122
{{- if .Endpoint }}

internal/controller/provisioner/objects.go

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,23 @@ func (p *NginxProvisioner) buildNginxConfigMaps(
419419
bootstrapCM.Data["mgmt.conf"] = string(helpers.MustExecuteTemplate(mgmtTemplate, mgmtFields))
420420
}
421421

422+
// Create events ConfigMap with worker_connections using template
423+
eventsFields := map[string]interface{}{
424+
"WorkerConnections": workerConnections,
425+
}
426+
427+
eventsCM := &corev1.ConfigMap{
428+
ObjectMeta: metav1.ObjectMeta{
429+
Name: p.cfg.GatewayPodConfig.Name + "-events",
430+
Namespace: objectMeta.Namespace,
431+
Labels: objectMeta.Labels,
432+
Annotations: objectMeta.Annotations,
433+
},
434+
Data: map[string]string{
435+
"events.conf": string(helpers.MustExecuteTemplate(eventsTemplate, eventsFields)),
436+
},
437+
}
438+
422439
metricsPort := config.DefaultNginxMetricsPort
423440
port, enableMetrics := graph.MetricsEnabledForNginxProxy(nProxyCfg)
424441
if port != nil {
@@ -457,7 +474,7 @@ func (p *NginxProvisioner) buildNginxConfigMaps(
457474
},
458475
}
459476

460-
return []client.Object{bootstrapCM, agentCM}
477+
return []client.Object{bootstrapCM, agentCM, eventsCM}
461478
}
462479

463480
func (p *NginxProvisioner) buildOpenshiftObjects(objectMeta metav1.ObjectMeta) []client.Object {
@@ -826,6 +843,7 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
826843
{MountPath: "/etc/nginx/conf.d", Name: "nginx-conf"},
827844
{MountPath: "/etc/nginx/stream-conf.d", Name: "nginx-stream-conf"},
828845
{MountPath: "/etc/nginx/main-includes", Name: "nginx-main-includes"},
846+
{MountPath: "/etc/nginx/events-includes", Name: "nginx-events-includes"},
829847
{MountPath: "/etc/nginx/secrets", Name: "nginx-secrets"},
830848
{MountPath: "/var/run/nginx", Name: "nginx-run"},
831849
{MountPath: "/var/cache/nginx", Name: "nginx-cache"},
@@ -845,6 +863,8 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
845863
"--destination", "/etc/nginx-agent",
846864
"--source", "/includes/main.conf",
847865
"--destination", "/etc/nginx/main-includes",
866+
"--source", "/events/events.conf",
867+
"--destination", "/etc/nginx/events-includes",
848868
},
849869
Env: []corev1.EnvVar{
850870
{
@@ -860,7 +880,9 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
860880
{MountPath: "/agent", Name: "nginx-agent-config"},
861881
{MountPath: "/etc/nginx-agent", Name: "nginx-agent"},
862882
{MountPath: "/includes", Name: "nginx-includes-bootstrap"},
883+
{MountPath: "/events", Name: "nginx-events-bootstrap"},
863884
{MountPath: "/etc/nginx/main-includes", Name: "nginx-main-includes"},
885+
{MountPath: "/etc/nginx/events-includes", Name: "nginx-events-includes"},
864886
},
865887
SecurityContext: &corev1.SecurityContext{
866888
Capabilities: &corev1.Capabilities{
@@ -927,6 +949,7 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
927949
{Name: "nginx-conf", VolumeSource: emptyDirVolumeSource},
928950
{Name: "nginx-stream-conf", VolumeSource: emptyDirVolumeSource},
929951
{Name: "nginx-main-includes", VolumeSource: emptyDirVolumeSource},
952+
{Name: "nginx-events-includes", VolumeSource: emptyDirVolumeSource},
930953
{Name: "nginx-secrets", VolumeSource: emptyDirVolumeSource},
931954
{Name: "nginx-run", VolumeSource: emptyDirVolumeSource},
932955
{Name: "nginx-cache", VolumeSource: emptyDirVolumeSource},
@@ -941,6 +964,16 @@ func (p *NginxProvisioner) buildNginxPodTemplateSpec(
941964
},
942965
},
943966
},
967+
{
968+
Name: "nginx-events-bootstrap",
969+
VolumeSource: corev1.VolumeSource{
970+
ConfigMap: &corev1.ConfigMapVolumeSource{
971+
LocalObjectReference: corev1.LocalObjectReference{
972+
Name: p.cfg.GatewayPodConfig.Name + "-events",
973+
},
974+
},
975+
},
976+
},
944977
},
945978
},
946979
}

internal/controller/provisioner/templates.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,17 @@ package provisioner
33
import gotemplate "text/template"
44

55
var (
6-
mainTemplate = gotemplate.Must(gotemplate.New("main").Parse(mainTemplateText))
7-
mgmtTemplate = gotemplate.Must(gotemplate.New("mgmt").Parse(mgmtTemplateText))
8-
agentTemplate = gotemplate.Must(gotemplate.New("agent").Parse(agentTemplateText))
6+
mainTemplate = gotemplate.Must(gotemplate.New("main").Parse(mainTemplateText))
7+
mgmtTemplate = gotemplate.Must(gotemplate.New("mgmt").Parse(mgmtTemplateText))
8+
agentTemplate = gotemplate.Must(gotemplate.New("agent").Parse(agentTemplateText))
9+
eventsTemplate = gotemplate.Must(gotemplate.New("events").Parse(eventsTemplateText))
910
)
1011

1112
const mainTemplateText = `
12-
error_log stderr {{ .ErrorLevel }};
13+
error_log stderr {{ .ErrorLevel }};`
1314

14-
events {
15-
worker_connections {{ .WorkerConnections }};
16-
}`
15+
const eventsTemplateText = `
16+
worker_connections {{ .WorkerConnections }};`
1717

1818
const mgmtTemplateText = `mgmt {
1919
{{- if .UsageEndpoint }}

0 commit comments

Comments
 (0)