Skip to content

Commit 1caa401

Browse files
committed
MAJOR: update to new client native interfaces
1 parent 37bed62 commit 1caa401

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+556
-534
lines changed

adapters/adapters.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,18 +125,19 @@ func ApacheLogMiddleware(logger *log.ACLLogger) Adapter {
125125
}
126126
}
127127

128-
func ConfigVersionMiddleware(client *clientnative.HAProxyClient) Adapter {
128+
func ConfigVersionMiddleware(client clientnative.HAProxyClient) Adapter {
129129
return func(h http.Handler) http.Handler {
130130
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
131131
qs := r.URL.Query()
132132
tID := qs.Get("transaction_id")
133-
tr, _ := client.Configuration.Transaction.GetTransaction(tID)
133+
configuration := client.Configuration()
134+
tr, _ := configuration.GetTransaction(tID)
134135
var v int64
135136
var err error
136137
if tr != nil && tr.Status == models.TransactionStatusInProgress {
137-
v, err = client.Configuration.GetConfigurationVersion(tr.ID)
138+
v, err = configuration.GetConfigurationVersion(tr.ID)
138139
} else {
139-
v, err = client.Configuration.GetConfigurationVersion("")
140+
v, err = configuration.GetConfigurationVersion("")
140141
}
141142
if err == nil {
142143
configVersion = strconv.FormatInt(v, 10)

configuration/cluster_sync.go

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ type Node struct {
6666
type ClusterSync struct {
6767
cfg *Configuration
6868
certFetch chan struct{}
69-
cli *client_native.HAProxyClient
69+
cli client_native.HAProxyClient
7070
Context context.Context
7171
ReloadAgent haproxy.IReloadAgent
7272
}
@@ -76,7 +76,7 @@ var expectedResponseCodes = map[string]int{
7676
"PUT": 200,
7777
}
7878

79-
func (c *ClusterSync) Monitor(cfg *Configuration, cli *client_native.HAProxyClient) {
79+
func (c *ClusterSync) Monitor(cfg *Configuration, cli client_native.HAProxyClient) {
8080
c.cfg = cfg
8181
c.cli = cli
8282

@@ -144,7 +144,7 @@ func (c *ClusterSync) issueRefreshRequest(url, port, basePath string, nodesPath
144144
Status: cfg.Status.Load(),
145145
Type: DataplaneAPIType,
146146
}
147-
var json = jsoniter.ConfigCompatibleWithStandardLibrary
147+
json := jsoniter.ConfigCompatibleWithStandardLibrary
148148
bytesRepresentation, _ := json.Marshal(nodeData)
149149

150150
req, err := http.NewRequest("PATCH", url, bytes.NewBuffer(bytesRepresentation))
@@ -344,7 +344,7 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, registerPath
344344
}
345345
nodeData.Facts = c.getNodeFacts()
346346

347-
var json = jsoniter.ConfigCompatibleWithStandardLibrary
347+
json := jsoniter.ConfigCompatibleWithStandardLibrary
348348
bytesRepresentation, _ := json.Marshal(nodeData)
349349

350350
req, err := http.NewRequest(registerMethod, url, bytes.NewBuffer(bytesRepresentation))
@@ -375,22 +375,23 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, registerPath
375375
return err
376376
}
377377
if c.cfg.HAProxy.NodeIDFile != "" {
378+
configuration := c.cli.Configuration()
378379
// write id to file
379380
errFID := ioutil.WriteFile(c.cfg.HAProxy.NodeIDFile, []byte(responseData.ID), 0644) // nolint:gosec
380381
if errFID != nil {
381382
return errFID
382383
}
383-
version, errVersion := c.cli.Configuration.GetVersion("")
384+
version, errVersion := configuration.GetVersion("")
384385
if errVersion != nil || version < 1 {
385386
// silently fallback to 1
386387
version = 1
387388
}
388-
t, err1 := c.cli.Configuration.StartTransaction(version)
389+
t, err1 := configuration.StartTransaction(version)
389390
if err1 != nil {
390391
return err1
391392
}
392393
// write id to peers
393-
_, peerSections, errorGet := c.cli.Configuration.GetPeerSections(t.ID)
394+
_, peerSections, errorGet := configuration.GetPeerSections(t.ID)
394395
if errorGet != nil {
395396
return errorGet
396397
}
@@ -400,27 +401,27 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, registerPath
400401
dataplaneID = "localhost"
401402
}
402403
for _, section := range peerSections {
403-
_, peerEntries, err1 := c.cli.Configuration.GetPeerEntries(section.Name, t.ID)
404+
_, peerEntries, err1 := configuration.GetPeerEntries(section.Name, t.ID)
404405
if err1 != nil {
405406
return err1
406407
}
407408
for _, peer := range peerEntries {
408409
if peer.Name == dataplaneID {
409410
peerFound = true
410411
peer.Name = responseData.ID
411-
errEdit := c.cli.Configuration.EditPeerEntry(dataplaneID, section.Name, peer, t.ID, 0)
412+
errEdit := configuration.EditPeerEntry(dataplaneID, section.Name, peer, t.ID, 0)
412413
if errEdit != nil {
413-
_ = c.cli.Configuration.DeleteTransaction(t.ID)
414+
_ = configuration.DeleteTransaction(t.ID)
414415
return err
415416
}
416417
}
417418
}
418419
}
419420
if !peerFound {
420-
_ = c.cli.Configuration.DeleteTransaction(t.ID)
421+
_ = configuration.DeleteTransaction(t.ID)
421422
return fmt.Errorf("peer [%s] not found in HAProxy config", dataplaneID)
422423
}
423-
_, err = c.cli.Configuration.CommitTransaction(t.ID)
424+
_, err = configuration.CommitTransaction(t.ID)
424425
if err != nil {
425426
return err
426427
}
@@ -520,7 +521,7 @@ func (c *ClusterSync) fetchCert() {
520521
break
521522
}
522523
var responseData Node
523-
var json = jsoniter.ConfigCompatibleWithStandardLibrary
524+
json := jsoniter.ConfigCompatibleWithStandardLibrary
524525
err = json.Unmarshal(body, &responseData)
525526
if err != nil {
526527
c.activateFetchCert(err)

configuration/cluster_sync_helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func (c *ClusterSync) getNodeFacts() map[string]string {
2929
facts["dataplane_cmdline"] = c.cfg.Cmdline.String()
3030
}
3131

32-
processInfos, err := c.cli.Runtime.GetInfo()
32+
processInfos, err := c.cli.Runtime().GetInfo()
3333
if err != nil || len(processInfos) < 1 {
3434
log.Error("unable to fetch processInfo")
3535
} else {

configuration/map_sync.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func (ms *MapSync) Stop() {
4646

4747
// SyncAll sync maps file entries with runtime maps entries for all configured files.
4848
// Missing runtime entries are appended to the map file
49-
func (ms *MapSync) SyncAll(client client_native.IHAProxyClient) {
49+
func (ms *MapSync) SyncAll(client client_native.HAProxyClient) {
5050
haproxyOptions := Get().HAProxy
5151

5252
d := time.Duration(haproxyOptions.UpdateMapFilesPeriod)
@@ -55,7 +55,7 @@ func (ms *MapSync) SyncAll(client client_native.IHAProxyClient) {
5555
for {
5656
select {
5757
case <-ticker.C:
58-
maps, err := client.GetRuntime().ShowMaps()
58+
maps, err := client.Runtime().ShowMaps()
5959
if err != nil {
6060
log.Warning("show maps sync error: ", err.Error())
6161
continue
@@ -75,20 +75,20 @@ func (ms *MapSync) SyncAll(client client_native.IHAProxyClient) {
7575
}
7676

7777
// Sync syncs one map file to runtime entries
78-
func (ms *MapSync) Sync(mp *models.Map, client client_native.IHAProxyClient) (bool, error) {
78+
func (ms *MapSync) Sync(mp *models.Map, client client_native.HAProxyClient) (bool, error) {
7979
ms.mu.Lock()
8080
defer ms.mu.Unlock()
8181

8282
rawFile, err := os.Open(mp.File)
8383
if err != nil {
8484
return false, fmt.Errorf("error reading map file: %s %s", mp.File, err.Error())
8585
}
86-
fileEntries := client.GetRuntime().ParseMapEntriesFromFile(rawFile, false)
86+
fileEntries := client.Runtime().ParseMapEntriesFromFile(rawFile, false)
8787
sort.Slice(fileEntries, func(i, j int) bool { return fileEntries[i].Key < fileEntries[j].Key })
8888

8989
// runtime map entries
9090
id := fmt.Sprintf("#%s", mp.ID)
91-
runtimeEntries, err := client.GetRuntime().ShowMapEntries(id)
91+
runtimeEntries, err := client.Runtime().ShowMapEntries(id)
9292
if err != nil {
9393
return false, fmt.Errorf("getting runtime entries error: id: %s %s", id, err.Error())
9494
}

0 commit comments

Comments
 (0)