Skip to content

Commit 4edfd8d

Browse files
committed
MEDIUM: improved performance for startup and servers management
1 parent 8ef705c commit 4edfd8d

13 files changed

+27
-27
lines changed

crs/api/ingress/v1/backend.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
// +genclient
2424
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
25-
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.15-0.20241106115115-75c12953fe1f"
25+
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.16-0.20241206145631-acb903fd9ec2"
2626

2727
// Backend is a specification for a Backend resource
2828
type Backend struct {

crs/api/ingress/v1/defaults.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
// +genclient
2424
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
25-
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.15-0.20241106115115-75c12953fe1f"
25+
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.16-0.20241206145631-acb903fd9ec2"
2626

2727
// Defaults is a specification for a Defaults resource
2828
type Defaults struct {

crs/api/ingress/v1/global.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
// +genclient
2424
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
25-
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.15-0.20241106115115-75c12953fe1f"
25+
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.16-0.20241206145631-acb903fd9ec2"
2626
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.default_path)", message="spec.config.default_path is set by ingress controller internally"
2727
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.master__dash__worker)", message="spec.config.master-worker is set by ingress controller internally"
2828
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.pidfile)", message="spec.config.pidfile is set by ingress controller internally"

crs/api/ingress/v1/tcp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import (
2323

2424
// +genclient
2525
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
26-
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.15-0.20241106115115-75c12953fe1f"
26+
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.16-0.20241206145631-acb903fd9ec2"
2727

2828
// TCP is a specification for a TCP resource
2929
type TCP struct {

crs/definition/ingress.v1.haproxy.org_backends.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.14.0
7-
haproxy.org/client-native: v5.1.15-0.20241106115115-75c12953fe1f
7+
haproxy.org/client-native: v5.1.16-0.20241206145631-acb903fd9ec2
88
name: backends.ingress.v1.haproxy.org
99
spec:
1010
group: ingress.v1.haproxy.org

crs/definition/ingress.v1.haproxy.org_defaults.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.14.0
7-
haproxy.org/client-native: v5.1.15-0.20241106115115-75c12953fe1f
7+
haproxy.org/client-native: v5.1.16-0.20241206145631-acb903fd9ec2
88
name: defaults.ingress.v1.haproxy.org
99
spec:
1010
group: ingress.v1.haproxy.org

crs/definition/ingress.v1.haproxy.org_globals.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.14.0
7-
haproxy.org/client-native: v5.1.15-0.20241106115115-75c12953fe1f
7+
haproxy.org/client-native: v5.1.16-0.20241206145631-acb903fd9ec2
88
name: globals.ingress.v1.haproxy.org
99
spec:
1010
group: ingress.v1.haproxy.org

crs/definition/ingress.v1.haproxy.org_tcps.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ kind: CustomResourceDefinition
44
metadata:
55
annotations:
66
controller-gen.kubebuilder.io/version: v0.14.0
7-
haproxy.org/client-native: v5.1.15-0.20241106115115-75c12953fe1f
7+
haproxy.org/client-native: v5.1.16-0.20241206145631-acb903fd9ec2
88
name: tcps.ingress.v1.haproxy.org
99
spec:
1010
group: ingress.v1.haproxy.org

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/google/go-cmp v0.6.0
1111
github.com/google/renameio v1.0.1
1212
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed
13-
github.com/haproxytech/client-native/v5 v5.1.15-0.20241106115115-75c12953fe1f
13+
github.com/haproxytech/client-native/v5 v5.1.16-0.20241206145631-acb903fd9ec2
1414
github.com/jessevdk/go-flags v1.4.0
1515
github.com/pires/go-proxyproto v0.7.0
1616
github.com/prometheus/client_golang v1.20.5
@@ -81,6 +81,7 @@ require (
8181
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d // indirect
8282
golang.org/x/net v0.32.0 // indirect
8383
golang.org/x/oauth2 v0.24.0 // indirect
84+
golang.org/x/sync v0.10.0 // indirect
8485
golang.org/x/sys v0.28.0 // indirect
8586
golang.org/x/term v0.27.0 // indirect
8687
golang.org/x/text v0.21.0 // indirect

go.sum

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
7373
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
7474
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed h1:qjKxpoe4wYQmpGrrooqau88Fgusy9VQfulpXghBDqx8=
7575
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed/go.mod h1:xRVluo27FAjK4ag33+jUfpnNf9olXQlTRHUl3VMvq98=
76-
github.com/haproxytech/client-native/v5 v5.1.15-0.20241106115115-75c12953fe1f h1:v0eQBUs3g70gPHWpP4xBb7wP1qLSs3OCFdDTP/vGbww=
77-
github.com/haproxytech/client-native/v5 v5.1.15-0.20241106115115-75c12953fe1f/go.mod h1:dhwpFkOsWxJRtwNs+LTJtsUTf9pX3uWHKKip9loIK3c=
76+
github.com/haproxytech/client-native/v5 v5.1.16-0.20241206145631-acb903fd9ec2 h1:lqyVtvMrZpnkd/esB1BCmh5H0HLssbV3x9ow00628W4=
77+
github.com/haproxytech/client-native/v5 v5.1.16-0.20241206145631-acb903fd9ec2/go.mod h1:/ms7QkqUYwCBm31zYl/qT/0r/TBDRt60pusERVZ2j0Q=
7878
github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE=
7979
github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM=
8080
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
@@ -176,6 +176,8 @@ golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht
176176
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
177177
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
178178
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
179+
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
180+
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
179181
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
180182
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
181183
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

pkg/haproxy/api/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ type HAProxyClient interface { //nolint:interfacebloat
4242
BackendServerDeleteAll(backendName string) (deleteServers bool)
4343
BackendServerCreate(backendName string, data models.Server) error
4444
BackendServerEdit(backendName string, data models.Server) error
45+
BackendServerCreateOrEdit(backendName string, data models.Server) error
4546
BackendServerDelete(backendName string, serverName string) error
4647
BackendServersGet(backendName string) (models.Servers, error)
4748
BackendSwitchingRulesGet(frontendName string) (models.BackendSwitchingRules, error)

pkg/haproxy/api/backend.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,15 @@ func (c *clientNative) BackendServerEdit(backendName string, data models.Server)
169169
return configuration.EditServer(data.Name, "backend", backendName, &data, c.activeTransaction, 0)
170170
}
171171

172+
func (c *clientNative) BackendServerCreateOrEdit(backendName string, data models.Server) error {
173+
configuration, err := c.nativeAPI.Configuration()
174+
if err != nil {
175+
return err
176+
}
177+
c.activeTransactionHasChanges = true
178+
return configuration.CreateOrEditServer("backend", backendName, &data, c.activeTransaction, 0)
179+
}
180+
172181
func (c *clientNative) BackendServerDelete(backendName string, serverName string) error {
173182
configuration, err := c.nativeAPI.Configuration()
174183
if err != nil {

pkg/service/endpoints.go

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"errors"
1919
"fmt"
2020
"strconv"
21-
"strings"
2221

2322
"github.com/haproxytech/client-native/v5/models"
2423

@@ -58,7 +57,6 @@ func (s *Service) HandleHAProxySrvs(k8s store.K8s, client api.HAProxyClient) {
5857
}
5958
}
6059

61-
// updateHAProxySrv updates corresponding HAProxy backend server or creates one if it does not exist
6260
func (s *Service) updateHAProxySrv(client api.HAProxyClient, srvSlot store.HAProxySrv, port int64) {
6361
srv := models.Server{
6462
Name: srvSlot.Name,
@@ -75,21 +73,10 @@ func (s *Service) updateHAProxySrv(client api.HAProxyClient, srvSlot store.HAPro
7573
srv.Maintenance = "disabled"
7674
}
7775
logger.Tracef("[CONFIG] [BACKEND] [SERVER] backend %s: about to update server in configuration file : models.Server { Name: %s, Port: %d, Address: %s, Maintenance: %s }", s.backend.Name, srv.Name, *srv.Port, srv.Address, srv.Maintenance)
78-
// Update server
79-
errAPI := client.BackendServerEdit(s.backend.Name, srv)
76+
77+
errAPI := client.BackendServerCreateOrEdit(s.backend.Name, srv)
8078
if errAPI == nil {
81-
logger.Tracef("[CONFIG] [BACKEND] [SERVER] Updating server '%s/%s'", s.backend.Name, srv.Name)
82-
return
83-
}
84-
// Create server
85-
if strings.Contains(errAPI.Error(), "does not exist") {
86-
logger.Tracef("[CONFIG] [BACKEND] [SERVER] Creating server '%s/%s'", s.backend.Name, srv.Name)
87-
errAPI = client.BackendServerCreate(s.backend.Name, srv)
88-
if errAPI != nil {
89-
logger.Errorf("[CONFIG] [BACKEND] [SERVER] %v", errAPI)
90-
}
91-
} else {
92-
logger.Errorf("[CONFIG] [BACKEND] [SERVER] %v", errAPI)
79+
logger.Tracef("[CONFIG] [BACKEND] [SERVER] Creating/Updating server '%s/%s'", s.backend.Name, srv.Name)
9380
}
9481
}
9582

0 commit comments

Comments
 (0)