From 89bc8eac48957ae501ab32121776d095cd46af46 Mon Sep 17 00:00:00 2001
From: kenichi-mashiyama <274147049+kenichi-mashiyama@users.noreply.github.com>
Date: Fri, 28 Aug 2026 09:15:26 +0900
Subject: [PATCH] Add defaults maxconn
---
apis/proxy/v1alpha1/instance_types.go | 4 ++
apis/proxy/v1alpha1/instance_types_test.go | 46 +++++++++++++++++++
apis/proxy/v1alpha1/zz_generated.deepcopy.go | 5 ++
docs/api-reference.md | 1 +
.../crds/proxy.haproxy.com_instances.yaml | 5 ++
5 files changed, 61 insertions(+)
diff --git a/apis/proxy/v1alpha1/instance_types.go b/apis/proxy/v1alpha1/instance_types.go
index f2030b9..ad58e00 100644
--- a/apis/proxy/v1alpha1/instance_types.go
+++ b/apis/proxy/v1alpha1/instance_types.go
@@ -647,6 +647,9 @@ type DefaultsConfiguration struct {
// +kubebuilder:default=http
// +kubebuilder:validation:Enum=http;tcp
Mode string `json:"mode"`
+ // Maxconn sets the maximum per-process number of concurrent connections for defaults.
+ // +optional
+ Maxconn *int64 `json:"maxconn,omitempty"`
// ErrorFiles custom error files to be used
// +optional
ErrorFiles []*configv1alpha1.ErrorFile `json:"errorFiles,omitempty"`
@@ -692,6 +695,7 @@ func (d *DefaultsConfiguration) Model() (models.Defaults, error) {
defaults.Name = defaultsSectionName
defaults.Mode = d.Mode
+ defaults.Maxconn = d.Maxconn
for name, timeout := range d.Timeouts {
switch name {
diff --git a/apis/proxy/v1alpha1/instance_types_test.go b/apis/proxy/v1alpha1/instance_types_test.go
index 3c88530..52a4d68 100644
--- a/apis/proxy/v1alpha1/instance_types_test.go
+++ b/apis/proxy/v1alpha1/instance_types_test.go
@@ -66,3 +66,49 @@ func TestDefaultsConfigurationAddToParserWithRetries(t *testing.T) {
t.Fatalf("expected config to contain retries 5, got:\n%s", cfg)
}
}
+
+func TestDefaultsConfigurationModelWithMaxconn(t *testing.T) {
+ d := &DefaultsConfiguration{
+ Mode: "http",
+ Maxconn: ptr.To(int64(2000)),
+ Timeouts: map[string]metav1.Duration{
+ "client": {Duration: 5 * time.Second},
+ "connect": {Duration: 5 * time.Second},
+ "server": {Duration: 10 * time.Second},
+ },
+ }
+
+ model, err := d.Model()
+ if err != nil {
+ t.Fatalf("Model() returned error: %v", err)
+ }
+
+ if model.Maxconn == nil || *model.Maxconn != 2000 {
+ t.Fatalf("expected maxconn 2000, got %#v", model.Maxconn)
+ }
+}
+
+func TestDefaultsConfigurationAddToParserWithMaxconn(t *testing.T) {
+ d := &DefaultsConfiguration{
+ Mode: "http",
+ Maxconn: ptr.To(int64(2000)),
+ Timeouts: map[string]metav1.Duration{
+ "client": {Duration: 5 * time.Second},
+ "connect": {Duration: 5 * time.Second},
+ "server": {Duration: 10 * time.Second},
+ },
+ }
+
+ p, err := parser.New()
+ if err != nil {
+ t.Fatalf("parser.New() returned error: %v", err)
+ }
+
+ if err := d.AddToParser(p); err != nil {
+ t.Fatalf("AddToParser() returned error: %v", err)
+ }
+
+ if !strings.Contains(p.String(), "maxconn 2000") {
+ t.Fatalf("expected generated config to contain maxconn 2000, got:\n%s", p.String())
+ }
+}
diff --git a/apis/proxy/v1alpha1/zz_generated.deepcopy.go b/apis/proxy/v1alpha1/zz_generated.deepcopy.go
index 596cc49..4932a14 100644
--- a/apis/proxy/v1alpha1/zz_generated.deepcopy.go
+++ b/apis/proxy/v1alpha1/zz_generated.deepcopy.go
@@ -52,6 +52,11 @@ func (in *Configuration) DeepCopy() *Configuration {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *DefaultsConfiguration) DeepCopyInto(out *DefaultsConfiguration) {
*out = *in
+ if in.Maxconn != nil {
+ in, out := &in.Maxconn, &out.Maxconn
+ *out = new(int64)
+ **out = **in
+ }
if in.ErrorFiles != nil {
in, out := &in.ErrorFiles, &out.ErrorFiles
*out = make([]*configv1alpha1.ErrorFile, len(*in))
diff --git a/docs/api-reference.md b/docs/api-reference.md
index fb36cd5..3439de5 100644
--- a/docs/api-reference.md
+++ b/docs/api-reference.md
@@ -1260,6 +1260,7 @@ _Appears in:_
| Field | Description | Default | Validation |
| --- | --- | --- | --- |
| `mode` _string_ | Mode can be either 'tcp' or 'http'. In tcp mode it is a layer 4 proxy. In http mode it is a layer 7 proxy. | http | Enum: [http tcp]
|
+| `maxconn` _integer_ | Maxconn sets the maximum per-process number of concurrent connections for defaults. | | Optional: \{\}
|
| `errorFiles` _[ErrorFile](#errorfile) array_ | ErrorFiles custom error files to be used | | Optional: \{\}
|
| `timeouts` _object (keys:string, values:[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.32/#duration-v1-meta))_ | Timeouts: check, client, client-fin, connect, http-keep-alive, http-request, queue, server, server-fin, tunnel.
The timeout value specified in milliseconds by default, but can be in any other unit if the number is suffixed by the unit.
More info: https://cbonte.github.io/haproxy-dconv/2.6/configuration.html | \{ client:5s connect:5s server:10s \} | |
| `retries` _integer_ | Retries sets the maximum number of retries on a connection failure. | | Minimum: 1
Optional: \{\}
|
diff --git a/helm/haproxy-operator/crds/proxy.haproxy.com_instances.yaml b/helm/haproxy-operator/crds/proxy.haproxy.com_instances.yaml
index c55e7c5..03fc303 100644
--- a/helm/haproxy-operator/crds/proxy.haproxy.com_instances.yaml
+++ b/helm/haproxy-operator/crds/proxy.haproxy.com_instances.yaml
@@ -170,6 +170,11 @@ spec:
format: int64
minimum: 1
type: integer
+ maxconn:
+ description: Maxconn sets the maximum per-process number
+ of concurrent connections for defaults.
+ format: int64
+ type: integer
timeouts:
additionalProperties:
type: string