Skip to content

Commit 25676bc

Browse files
committed
MEDIUM: API consolidation: remove support for multi-process
1 parent 6d210be commit 25676bc

25 files changed

+239
-566
lines changed

client-native/cn.go

Lines changed: 58 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@ package cn
33
import (
44
"context"
55
"fmt"
6-
"strconv"
76
"sync"
87
"time"
98

109
clientnative "github.com/haproxytech/client-native/v6"
11-
"github.com/haproxytech/client-native/v6/models"
1210

1311
"github.com/haproxytech/client-native/v6/configuration"
1412
configuration_options "github.com/haproxytech/client-native/v6/configuration/options"
@@ -84,72 +82,32 @@ func ConfigureRuntimeClient(ctx context.Context, confClient configuration.Config
8482
// If master socket is set and a valid unix socket, use only this
8583
if haproxyOptions.MasterRuntime != "" && misc.IsUnixSocketAddr(haproxyOptions.MasterRuntime) {
8684
masterSocket := haproxyOptions.MasterRuntime
87-
// if nbproc is set, set nbproc sockets
88-
if globalConf.Nbproc > 0 {
89-
nbproc := int(globalConf.Nbproc)
90-
ms := runtime_options.MasterSocket(masterSocket, nbproc)
91-
runtimeClient, err = runtime_api.New(ctx, mapsDir, ms, waitForRuntimeOption)
92-
if err == nil {
93-
return runtimeClient
94-
}
95-
log.Warningf("Error setting up runtime client with master socket: %s : %s", masterSocket, err.Error())
96-
} else {
97-
// if nbproc is not set, use master socket with 1 process
98-
ms := runtime_options.MasterSocket(masterSocket, 1)
99-
runtimeClient, err = runtime_api.New(ctx, mapsDir, ms, waitForRuntimeOption)
100-
if err == nil {
101-
return runtimeClient
102-
}
103-
log.Warningf("Error setting up runtime client with master socket: %s : %s", masterSocket, err.Error())
85+
// nbproc has been removed, use master socket with 1 process
86+
ms := runtime_options.MasterSocket(masterSocket)
87+
runtimeClient, err = runtime_api.New(ctx, mapsDir, ms, waitForRuntimeOption)
88+
if err == nil {
89+
return runtimeClient
10490
}
91+
log.Warningf("Error setting up runtime client with master socket: %s : %s", masterSocket, err.Error())
10592
}
93+
10694
runtimeAPIs := globalConf.RuntimeAPIs
107-
// if no master socket set, read from first valid socket if nbproc <= 1
108-
if globalConf.Nbproc <= 1 {
109-
sockets := make(map[int]string)
110-
for _, r := range runtimeAPIs {
111-
if misc.IsUnixSocketAddr(*r.Address) {
112-
sockets[1] = *r.Address
113-
socketsL := runtime_options.Sockets(sockets)
114-
runtimeClient, err = runtime_api.New(ctx, mapsDir, socketsL, waitForRuntimeOption)
115-
if err == nil {
116-
muSocketsList.Lock()
117-
socketsList = sockets
118-
muSocketsList.Unlock()
119-
return runtimeClient
120-
}
121-
log.Warningf("Error setting up runtime client with socket: %s : %s", *r.Address, err.Error())
122-
}
123-
}
124-
} else {
125-
// else try to find process specific sockets and set them up
126-
sockets := make(map[int]string)
127-
for _, r := range runtimeAPIs {
128-
//nolint:govet
129-
if misc.IsUnixSocketAddr(*r.Address) && r.Process != "" {
130-
process, err := strconv.ParseInt(r.Process, 10, 64)
131-
if err == nil {
132-
sockets[int(process)] = *r.Address
133-
}
95+
// if no master socket set, read from first valid socket
96+
sockets := make(map[int]string)
97+
for _, r := range runtimeAPIs {
98+
if misc.IsUnixSocketAddr(*r.Address) {
99+
socketsL := runtime_options.Socket(*r.Address)
100+
runtimeClient, err = runtime_api.New(ctx, mapsDir, socketsL, waitForRuntimeOption)
101+
if err == nil {
102+
muSocketsList.Lock()
103+
socketsList = sockets
104+
muSocketsList.Unlock()
105+
return runtimeClient
134106
}
107+
log.Warningf("Error setting up runtime client with socket: %s : %s", *r.Address, err.Error())
135108
}
136-
// no process specific settings found, Issue a warning and return empty runtime client
137-
if len(sockets) == 0 {
138-
log.Warning("Runtime API not configured, found multiple processes and no stats sockets bound to them.")
139-
return runtimeClient
140-
// use only found process specific sockets issue a warning if not all processes have a socket configured
141-
}
142-
if len(sockets) < int(globalConf.Nbproc) {
143-
log.Warning("Runtime API not configured properly, there are more processes then configured sockets")
144-
}
145-
146-
socketLst := runtime_options.Sockets(sockets)
147-
runtimeClient, err = runtime_api.New(ctx, mapsDir, socketLst, waitForRuntimeOption)
148-
if err == nil {
149-
return runtimeClient
150-
}
151-
log.Warningf("Error setting up runtime client with sockets: %v : %s", sockets, err.Error())
152109
}
110+
153111
if err != nil {
154112
log.Warning("Runtime API not configured, not using it: " + err.Error())
155113
} else {
@@ -162,40 +120,55 @@ func ConfigureRuntimeClient(ctx context.Context, confClient configuration.Config
162120
}
163121

164122
// ReconfigureRuntime check if runtime client need be reconfigured by comparing the current configuration with the old
165-
// one (i.e. runtimeAPIsOld) and returns a callback that ReloadAgent can use to reconfigure the runtime client.
166-
func ReconfigureRuntime(client clientnative.HAProxyClient, runtimeAPIsOld []*models.RuntimeAPI) (callbackNeeded bool, callback func(), err error) {
123+
// one and returns a callback that ReloadAgent can use to reconfigure the runtime client.
124+
func ReconfigureRuntime(client clientnative.HAProxyClient) (callbackNeeded bool, callback func(), err error) {
167125
cfg, err := client.Configuration()
168126
if err != nil {
169127
return false, nil, err
170128
}
171-
_, globalConf, err := cfg.GetGlobalConfiguration("")
172-
if err != nil {
173-
return false, nil, err
174-
}
175-
runtimeAPIsNew := globalConf.RuntimeAPIs
129+
176130
reconfigureRuntime := false
177-
if len(runtimeAPIsOld) != len(runtimeAPIsNew) {
131+
132+
// client Runtime is not reconfigured yet, so client.Runtime() return the "old" runtime
133+
oldRuntime, err := client.Runtime()
134+
// In case we have an error, we need to reconfigure
135+
if err != nil {
178136
reconfigureRuntime = true
179-
} else {
180-
for _, runtimeOld := range runtimeAPIsOld {
181-
if runtimeOld.Address == nil {
137+
}
138+
139+
if !reconfigureRuntime {
140+
// If we are not using stats socket (i.e. using master socket)
141+
// Return immediately and do not reconfigure
142+
// Do not try to compare the master socket path with stats socket paths
143+
if !oldRuntime.IsStatsSocket() {
144+
return false, nil, nil
145+
}
146+
147+
_, globalConf, err := cfg.GetGlobalConfiguration("")
148+
if err != nil {
149+
return false, nil, err
150+
}
151+
runtimeAPIsNew := globalConf.RuntimeAPIs
152+
153+
oldSocketPath := oldRuntime.SocketPath()
154+
155+
// Now check if the new configuration contains the "old" runtime socket we are using
156+
// If yes, no need to reconfigure, socket path still exists.
157+
// If not found, only then reconfigure
158+
// This, only if stats socket, not for master socket
159+
found := false
160+
for _, runtimeNew := range runtimeAPIsNew {
161+
if runtimeNew.Address == nil {
182162
continue
183163
}
184-
found := false
185-
for _, runtimeNew := range runtimeAPIsNew {
186-
if runtimeNew.Address == nil {
187-
continue
188-
}
189-
if *runtimeNew.Address == *runtimeOld.Address {
190-
found = true
191-
break
192-
}
193-
}
194-
if !found {
195-
reconfigureRuntime = true
164+
if *runtimeNew.Address == oldSocketPath {
165+
found = true
196166
break
197167
}
198168
}
169+
if !found {
170+
reconfigureRuntime = true
171+
}
199172
}
200173

201174
if reconfigureRuntime {

configuration/cluster_sync_helpers.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ func (c *ClusterSync) getNodeFacts() map[string]string {
3434
log.Errorf("unable to fetch processInfo: %s", err.Error())
3535
return facts
3636
}
37-
processInfos, err := runtime.GetInfo()
38-
if err != nil || len(processInfos) < 1 {
37+
processInfo, err := runtime.GetInfo()
38+
if err != nil {
3939
log.Error("unable to fetch processInfo")
4040
} else {
41-
if processInfos[0].Info != nil {
42-
facts["haproxy_version"] = processInfos[0].Info.Version
41+
if processInfo.Info != nil {
42+
facts["haproxy_version"] = processInfo.Info.Version
4343
} else {
4444
log.Error("empty process info")
4545
}

configure_data_plane.go

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1063,26 +1063,11 @@ func reloadConfigurationFile(client client_native.HAProxyClient, haproxyOptions
10631063

10641064
func startWatcher(ctx context.Context, client client_native.HAProxyClient, haproxyOptions dataplaneapi_config.HAProxyConfiguration, users *dataplaneapi_config.Users, reloadAgent *haproxy.ReloadAgent) error {
10651065
cb := func() {
1066-
configuration, err := client.Configuration()
1067-
if err != nil {
1068-
log.Warningf("Failed to get configuration: %s", err)
1069-
return
1070-
}
1071-
1072-
// save old runtime configuration to know if the runtime client must be configured after the new configuration is
1073-
// reloaded by HAProxy. Logic is done by cn.ReconfigureRuntime() function.
1074-
_, globalConf, err := configuration.GetGlobalConfiguration("")
1075-
if err != nil {
1076-
log.Warningf("Failed to get global configuration section: %s", err)
1077-
return
1078-
}
1079-
runtimeAPIsOld := globalConf.RuntimeAPIs
1080-
10811066
// reload configuration from config file.
10821067
reloadConfigurationFile(client, haproxyOptions, users)
10831068

10841069
// reload runtime client if necessary.
1085-
callbackNeeded, reconfigureFunc, err := cn.ReconfigureRuntime(client, runtimeAPIsOld)
1070+
callbackNeeded, reconfigureFunc, err := cn.ReconfigureRuntime(client)
10861071
if err != nil {
10871072
log.Warningf("Failed to check if native client need to be reloaded: %s", err)
10881073
return
@@ -1092,7 +1077,7 @@ func startWatcher(ctx context.Context, client client_native.HAProxyClient, hapro
10921077
}
10931078

10941079
// get the last configuration which has been updated by reloadConfigurationFile and increment version in config file.
1095-
configuration, err = client.Configuration()
1080+
configuration, err := client.Configuration()
10961081
if err != nil {
10971082
log.Warningf("Failed to get configuration: %s", err)
10981083
return

e2e/libs/version.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# auth_curl is going to return the response status code along with the body
1919
# these values can be easily read as following
2020
#
21-
# read -r SC BODY < <(auth_curl GET /v2/services/haproxy/runtime/info)
21+
# read -r SC BODY < <(auth_curl GET /v3/services/haproxy/runtime/info)
2222
# echo "Status Code: ${SC}"
2323
# echo "Body: ${BODY}"
2424
#

e2e/libs/version_spoe.bash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
# auth_curl is going to return the response status code along with the body
1919
# these values can be easily read as following
2020
#
21-
# read -r SC BODY < <(auth_curl GET /v2/services/haproxy/runtime/info)
21+
# read -r SC BODY < <(auth_curl GET /v3/services/haproxy/runtime/info)
2222
# echo "Status Code: ${SC}"
2323
# echo "Body: ${BODY}"
2424
#

e2e/run.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ if [[ "$major" -eq "2" && "$minor" -ge "7" || "$major" -gt "2" ]] ; then
5353
VARIANT="-master-socket"
5454
fi
5555

56+
5657
if [ ! -z $(docker ps -q -f name=${DOCKER_CONTAINER_NAME}) ]; then
5758
echo ">>> Skipping provisioning the e2e environment, ${DOCKER_CONTAINER_NAME} already present"
5859
else

0 commit comments

Comments
 (0)