Skip to content

Commit b3f9ff3

Browse files
committed
add dynamic worker connections to provisioner template
1 parent 6e21852 commit b3f9ff3

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed

internal/controller/provisioner/objects.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,14 @@ func (p *NginxProvisioner) buildNginxConfigMaps(
317317
logLevel = string(*nProxyCfg.Logging.ErrorLevel)
318318
}
319319

320+
workerConnections := int32(1024)
321+
if nProxyCfg != nil && nProxyCfg.WorkerConnections != nil {
322+
workerConnections = *nProxyCfg.WorkerConnections
323+
}
324+
320325
mainFields := map[string]interface{}{
321-
"ErrorLevel": logLevel,
326+
"ErrorLevel": logLevel,
327+
"WorkerConnections": workerConnections,
322328
}
323329

324330
bootstrapCM := &corev1.ConfigMap{

internal/controller/provisioner/objects_test.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,3 +1014,30 @@ func TestSetIPFamily(t *testing.T) {
10141014
g.Expect(svc.Spec.IPFamilyPolicy).To(Equal(helpers.GetPointer(corev1.IPFamilyPolicySingleStack)))
10151015
g.Expect(svc.Spec.IPFamilies).To(Equal([]corev1.IPFamily{corev1.IPv6Protocol}))
10161016
}
1017+
1018+
func TestBuildNginxConfigMaps_WorkerConnections(t *testing.T) {
1019+
t.Parallel()
1020+
g := NewWithT(t)
1021+
1022+
provisioner := &NginxProvisioner{
1023+
cfg: Config{
1024+
GatewayPodConfig: &config.GatewayPodConfig{
1025+
Namespace: "default",
1026+
ServiceName: "test-service",
1027+
},
1028+
},
1029+
}
1030+
objectMeta := metav1.ObjectMeta{Name: "test", Namespace: "default"}
1031+
1032+
// Test with custom worker connections
1033+
nProxyCfg := &graph.EffectiveNginxProxy{
1034+
WorkerConnections: helpers.GetPointer(int32(2048)),
1035+
}
1036+
1037+
configMaps := provisioner.buildNginxConfigMaps(objectMeta, nProxyCfg, "test-bootstrap", "test-agent", false, false)
1038+
g.Expect(configMaps).To(HaveLen(2))
1039+
1040+
bootstrapCM, ok := configMaps[0].(*corev1.ConfigMap)
1041+
g.Expect(ok).To(BeTrue())
1042+
g.Expect(bootstrapCM.Data["main.conf"]).To(ContainSubstring("worker_connections 2048;"))
1043+
}

internal/controller/provisioner/templates.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const mainTemplateText = `
1212
error_log stderr {{ .ErrorLevel }};
1313
1414
events {
15-
worker_connections 1024;
15+
worker_connections {{ .WorkerConnections }};
1616
}`
1717

1818
const mgmtTemplateText = `mgmt {

0 commit comments

Comments
 (0)