Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
7 changes: 7 additions & 0 deletions apis/v1alpha2/nginxproxy_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ type NginxProxySpec struct {
//
// +optional
Kubernetes *KubernetesSpec `json:"kubernetes,omitempty"`
// WorkerConnections specifies the maximum number of simultaneous connections that can be opened by a worker process.
// Default is 1024.
//
// +optional
// +kubebuilder:validation:Minimum=1
// +kubebuilder:validation:Maximum=65535
WorkerConnections *int32 `json:"workerConnections,omitempty"`
}

// Telemetry specifies the OpenTelemetry configuration.
Expand Down
5 changes: 5 additions & 0 deletions apis/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/crd/bases/gateway.nginx.org_nginxproxies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7187,6 +7187,14 @@ spec:
- key
x-kubernetes-list-type: map
type: object
workerConnections:
description: |-
WorkerConnections specifies the maximum number of simultaneous connections that can be opened by a worker process.
Default is 1024.
format: int32
maximum: 65535
minimum: 1
type: integer
type: object
required:
- spec
Expand Down
8 changes: 8 additions & 0 deletions deploy/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7772,6 +7772,14 @@ spec:
- key
x-kubernetes-list-type: map
type: object
workerConnections:
description: |-
WorkerConnections specifies the maximum number of simultaneous connections that can be opened by a worker process.
Default is 1024.
format: int32
maximum: 65535
minimum: 1
type: integer
type: object
required:
- spec
Expand Down
4 changes: 0 additions & 4 deletions internal/controller/nginx/conf/nginx-plus.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ worker_processes auto;

pid /var/run/nginx/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/mime.types;
Expand Down
4 changes: 0 additions & 4 deletions internal/controller/nginx/conf/nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,6 @@ worker_processes auto;

pid /var/run/nginx/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/conf.d/*.conf;
include /etc/nginx/mime.types;
Expand Down
4 changes: 4 additions & 0 deletions internal/controller/nginx/config/main_config_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ load_module modules/ngx_otel_module.so;

error_log stderr {{ .Conf.Logging.ErrorLevel }};

events {
worker_connections {{ .Conf.WorkerConnections }};
}

{{ range $i := .Includes -}}
include {{ $i.Name }};
{{ end -}}
Expand Down
52 changes: 52 additions & 0 deletions internal/controller/nginx/config/main_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,55 @@ func TestGenerateMgmtFiles_Panic(t *testing.T) {
gen.generateMgmtFiles(dataplane.Configuration{})
}).To(Panic())
}

func TestExecuteMainConfig_WorkerConnections(t *testing.T) {
t.Parallel()

tests := []struct {
name string
expWorkerConnections string
conf dataplane.Configuration
}{
{
name: "default worker connections",
conf: dataplane.Configuration{
WorkerConnections: 1024,
},
expWorkerConnections: "worker_connections 1024;",
},
{
name: "custom worker connections",
conf: dataplane.Configuration{
WorkerConnections: 2048,
},
expWorkerConnections: "worker_connections 2048;",
},
{
name: "minimum worker connections",
conf: dataplane.Configuration{
WorkerConnections: 1,
},
expWorkerConnections: "worker_connections 1;",
},
{
name: "maximum worker connections",
conf: dataplane.Configuration{
WorkerConnections: 65535,
},
expWorkerConnections: "worker_connections 65535;",
},
}

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

res := executeMainConfig(test.conf)
g.Expect(res).To(HaveLen(1))
g.Expect(res[0].dest).To(Equal(mainIncludesConfigFile))
g.Expect(string(res[0].data)).To(ContainSubstring(test.expWorkerConnections))
g.Expect(string(res[0].data)).To(ContainSubstring("events {"))
})
}
}
6 changes: 5 additions & 1 deletion internal/controller/provisioner/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ var (
)

const mainTemplateText = `
error_log stderr {{ .ErrorLevel }};`
error_log stderr {{ .ErrorLevel }};

events {
worker_connections 1024;
}`

const mgmtTemplateText = `mgmt {
{{- if .UsageEndpoint }}
Expand Down
35 changes: 26 additions & 9 deletions internal/controller/state/dataplane/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,13 @@ func BuildConfiguration(
buildRefCertificateBundles(g.ReferencedSecrets, g.ReferencedCaCertConfigMaps),
backendGroups,
),
Telemetry: buildTelemetry(g, gateway),
BaseHTTPConfig: baseHTTPConfig,
Logging: buildLogging(gateway),
NginxPlus: nginxPlus,
MainSnippets: buildSnippetsForContext(gatewaySnippetsFilters, ngfAPIv1alpha1.NginxContextMain),
AuxiliarySecrets: buildAuxiliarySecrets(g.PlusSecrets),
Telemetry: buildTelemetry(g, gateway),
BaseHTTPConfig: baseHTTPConfig,
Logging: buildLogging(gateway),
NginxPlus: nginxPlus,
MainSnippets: buildSnippetsForContext(gatewaySnippetsFilters, ngfAPIv1alpha1.NginxContextMain),
AuxiliarySecrets: buildAuxiliarySecrets(g.PlusSecrets),
WorkerConnections: buildWorkerConnections(gateway),
}

return config
Expand Down Expand Up @@ -1105,6 +1106,21 @@ func buildLogging(gateway *graph.Gateway) Logging {
return logSettings
}

func buildWorkerConnections(gateway *graph.Gateway) int32 {
defaultWorkerConnections := int32(1024)

if gateway == nil || gateway.EffectiveNginxProxy == nil {
return defaultWorkerConnections
}

ngfProxy := gateway.EffectiveNginxProxy
if ngfProxy.WorkerConnections != nil {
return *ngfProxy.WorkerConnections
}

return defaultWorkerConnections
}

func buildAuxiliarySecrets(
secrets map[types.NamespacedName][]graph.PlusSecretFile,
) map[graph.SecretFileType][]byte {
Expand Down Expand Up @@ -1143,8 +1159,9 @@ func buildNginxPlus(gateway *graph.Gateway) NginxPlus {

func GetDefaultConfiguration(g *graph.Graph, gateway *graph.Gateway) Configuration {
return Configuration{
Logging: buildLogging(gateway),
NginxPlus: NginxPlus{},
AuxiliarySecrets: buildAuxiliarySecrets(g.PlusSecrets),
Logging: buildLogging(gateway),
NginxPlus: NginxPlus{},
AuxiliarySecrets: buildAuxiliarySecrets(g.PlusSecrets),
WorkerConnections: buildWorkerConnections(gateway),
}
}
59 changes: 59 additions & 0 deletions internal/controller/state/dataplane/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4895,3 +4895,62 @@ func TestBuildNginxPlus(t *testing.T) {
})
}
}

func TestBuildWorkerConnections(t *testing.T) {
t.Parallel()

tests := []struct {
gw *graph.Gateway
msg string
expWorkerConnections int32
}{
{
msg: "NginxProxy is nil",
gw: &graph.Gateway{},
expWorkerConnections: 1024,
},
{
msg: "NginxProxy doesn't specify worker connections",
gw: &graph.Gateway{
EffectiveNginxProxy: &graph.EffectiveNginxProxy{},
},
expWorkerConnections: 1024,
},
{
msg: "NginxProxy specifies worker connections",
gw: &graph.Gateway{
EffectiveNginxProxy: &graph.EffectiveNginxProxy{
WorkerConnections: helpers.GetPointer(int32(2048)),
},
},
expWorkerConnections: 2048,
},
{
msg: "NginxProxy specifies minimum worker connections",
gw: &graph.Gateway{
EffectiveNginxProxy: &graph.EffectiveNginxProxy{
WorkerConnections: helpers.GetPointer(int32(1)),
},
},
expWorkerConnections: 1,
},
{
msg: "NginxProxy specifies maximum worker connections",
gw: &graph.Gateway{
EffectiveNginxProxy: &graph.EffectiveNginxProxy{
WorkerConnections: helpers.GetPointer(int32(65535)),
},
},
expWorkerConnections: 65535,
},
}

for _, tc := range tests {
t.Run(tc.msg, func(t *testing.T) {
t.Parallel()
g := NewWithT(t)

g.Expect(buildWorkerConnections(tc.gw)).To(Equal(tc.expWorkerConnections))
})
}
}
2 changes: 2 additions & 0 deletions internal/controller/state/dataplane/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ type Configuration struct {
NginxPlus NginxPlus
// BaseHTTPConfig holds the configuration options at the http context.
BaseHTTPConfig BaseHTTPConfig
// WorkerConnections specifies the max number of simultaneous connections that can be opened by a worker process.
WorkerConnections int32
}

// SSLKeyPairID is a unique identifier for a SSLKeyPair.
Expand Down
Loading