Skip to content

Commit

Permalink
MEDIUM: improved performance for startup and servers management
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanmatmati committed Dec 11, 2024
1 parent 8ef705c commit 4edfd8d
Show file tree
Hide file tree
Showing 13 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion crs/api/ingress/v1/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

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

// Backend is a specification for a Backend resource
type Backend struct {
Expand Down
2 changes: 1 addition & 1 deletion crs/api/ingress/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

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

// Defaults is a specification for a Defaults resource
type Defaults struct {
Expand Down
2 changes: 1 addition & 1 deletion crs/api/ingress/v1/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (

// +genclient
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.15-0.20241106115115-75c12953fe1f"
// +kubebuilder:metadata:annotations="haproxy.org/client-native=v5.1.16-0.20241206145631-acb903fd9ec2"
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.default_path)", message="spec.config.default_path is set by ingress controller internally"
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.master__dash__worker)", message="spec.config.master-worker is set by ingress controller internally"
// +kubebuilder:validation:XValidation:rule="!has(self.spec.config.pidfile)", message="spec.config.pidfile is set by ingress controller internally"
Expand Down
2 changes: 1 addition & 1 deletion crs/api/ingress/v1/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import (

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

// TCP is a specification for a TCP resource
type TCP struct {
Expand Down
2 changes: 1 addition & 1 deletion crs/definition/ingress.v1.haproxy.org_backends.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
haproxy.org/client-native: v5.1.15-0.20241106115115-75c12953fe1f
haproxy.org/client-native: v5.1.16-0.20241206145631-acb903fd9ec2
name: backends.ingress.v1.haproxy.org
spec:
group: ingress.v1.haproxy.org
Expand Down
2 changes: 1 addition & 1 deletion crs/definition/ingress.v1.haproxy.org_defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
haproxy.org/client-native: v5.1.15-0.20241106115115-75c12953fe1f
haproxy.org/client-native: v5.1.16-0.20241206145631-acb903fd9ec2
name: defaults.ingress.v1.haproxy.org
spec:
group: ingress.v1.haproxy.org
Expand Down
2 changes: 1 addition & 1 deletion crs/definition/ingress.v1.haproxy.org_globals.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
haproxy.org/client-native: v5.1.15-0.20241106115115-75c12953fe1f
haproxy.org/client-native: v5.1.16-0.20241206145631-acb903fd9ec2
name: globals.ingress.v1.haproxy.org
spec:
group: ingress.v1.haproxy.org
Expand Down
2 changes: 1 addition & 1 deletion crs/definition/ingress.v1.haproxy.org_tcps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.14.0
haproxy.org/client-native: v5.1.15-0.20241106115115-75c12953fe1f
haproxy.org/client-native: v5.1.16-0.20241206145631-acb903fd9ec2
name: tcps.ingress.v1.haproxy.org
spec:
group: ingress.v1.haproxy.org
Expand Down
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
github.com/google/go-cmp v0.6.0
github.com/google/renameio v1.0.1
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed
github.com/haproxytech/client-native/v5 v5.1.15-0.20241106115115-75c12953fe1f
github.com/haproxytech/client-native/v5 v5.1.16-0.20241206145631-acb903fd9ec2
github.com/jessevdk/go-flags v1.4.0
github.com/pires/go-proxyproto v0.7.0
github.com/prometheus/client_golang v1.20.5
Expand Down Expand Up @@ -81,6 +81,7 @@ require (
golang.org/x/exp v0.0.0-20241204233417-43b7b7cde48d // indirect
golang.org/x/net v0.32.0 // indirect
golang.org/x/oauth2 v0.24.0 // indirect
golang.org/x/sync v0.10.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/term v0.27.0 // indirect
golang.org/x/text v0.21.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed h1:qjKxpoe4wYQmpGrrooqau88Fgusy9VQfulpXghBDqx8=
github.com/haproxytech/client-native/v3 v3.1.2-0.20230607075433-231591da68ed/go.mod h1:xRVluo27FAjK4ag33+jUfpnNf9olXQlTRHUl3VMvq98=
github.com/haproxytech/client-native/v5 v5.1.15-0.20241106115115-75c12953fe1f h1:v0eQBUs3g70gPHWpP4xBb7wP1qLSs3OCFdDTP/vGbww=
github.com/haproxytech/client-native/v5 v5.1.15-0.20241106115115-75c12953fe1f/go.mod h1:dhwpFkOsWxJRtwNs+LTJtsUTf9pX3uWHKKip9loIK3c=
github.com/haproxytech/client-native/v5 v5.1.16-0.20241206145631-acb903fd9ec2 h1:lqyVtvMrZpnkd/esB1BCmh5H0HLssbV3x9ow00628W4=
github.com/haproxytech/client-native/v5 v5.1.16-0.20241206145631-acb903fd9ec2/go.mod h1:/ms7QkqUYwCBm31zYl/qT/0r/TBDRt60pusERVZ2j0Q=
github.com/haproxytech/go-logger v1.1.0 h1:HgGtYaI1ApkvbQdsm7f9AzQQoxTB7w37criTflh7IQE=
github.com/haproxytech/go-logger v1.1.0/go.mod h1:OekUd8HCb7ubxMplzHUPBTHNxZmddOWfOjWclZsqIeM=
github.com/imdario/mergo v0.3.16 h1:wwQJbIsHYGMUyLSPrEq1CT16AhnhNJQ51+4fdHUnCl4=
Expand Down Expand Up @@ -176,6 +176,8 @@ golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbht
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ=
golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
Expand Down
1 change: 1 addition & 0 deletions pkg/haproxy/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type HAProxyClient interface { //nolint:interfacebloat
BackendServerDeleteAll(backendName string) (deleteServers bool)
BackendServerCreate(backendName string, data models.Server) error
BackendServerEdit(backendName string, data models.Server) error
BackendServerCreateOrEdit(backendName string, data models.Server) error
BackendServerDelete(backendName string, serverName string) error
BackendServersGet(backendName string) (models.Servers, error)
BackendSwitchingRulesGet(frontendName string) (models.BackendSwitchingRules, error)
Expand Down
9 changes: 9 additions & 0 deletions pkg/haproxy/api/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,15 @@ func (c *clientNative) BackendServerEdit(backendName string, data models.Server)
return configuration.EditServer(data.Name, "backend", backendName, &data, c.activeTransaction, 0)
}

func (c *clientNative) BackendServerCreateOrEdit(backendName string, data models.Server) error {
configuration, err := c.nativeAPI.Configuration()
if err != nil {
return err
}
c.activeTransactionHasChanges = true
return configuration.CreateOrEditServer("backend", backendName, &data, c.activeTransaction, 0)
}

func (c *clientNative) BackendServerDelete(backendName string, serverName string) error {
configuration, err := c.nativeAPI.Configuration()
if err != nil {
Expand Down
19 changes: 3 additions & 16 deletions pkg/service/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"errors"
"fmt"
"strconv"
"strings"

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

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

// updateHAProxySrv updates corresponding HAProxy backend server or creates one if it does not exist
func (s *Service) updateHAProxySrv(client api.HAProxyClient, srvSlot store.HAProxySrv, port int64) {
srv := models.Server{
Name: srvSlot.Name,
Expand All @@ -75,21 +73,10 @@ func (s *Service) updateHAProxySrv(client api.HAProxyClient, srvSlot store.HAPro
srv.Maintenance = "disabled"
}
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)
// Update server
errAPI := client.BackendServerEdit(s.backend.Name, srv)

errAPI := client.BackendServerCreateOrEdit(s.backend.Name, srv)
if errAPI == nil {
logger.Tracef("[CONFIG] [BACKEND] [SERVER] Updating server '%s/%s'", s.backend.Name, srv.Name)
return
}
// Create server
if strings.Contains(errAPI.Error(), "does not exist") {
logger.Tracef("[CONFIG] [BACKEND] [SERVER] Creating server '%s/%s'", s.backend.Name, srv.Name)
errAPI = client.BackendServerCreate(s.backend.Name, srv)
if errAPI != nil {
logger.Errorf("[CONFIG] [BACKEND] [SERVER] %v", errAPI)
}
} else {
logger.Errorf("[CONFIG] [BACKEND] [SERVER] %v", errAPI)
logger.Tracef("[CONFIG] [BACKEND] [SERVER] Creating/Updating server '%s/%s'", s.backend.Name, srv.Name)
}
}

Expand Down

0 comments on commit 4edfd8d

Please sign in to comment.