@@ -66,7 +66,7 @@ type Node struct {
66
66
type ClusterSync struct {
67
67
cfg * Configuration
68
68
certFetch chan struct {}
69
- cli * client_native.HAProxyClient
69
+ cli client_native.HAProxyClient
70
70
Context context.Context
71
71
ReloadAgent haproxy.IReloadAgent
72
72
}
@@ -76,7 +76,7 @@ var expectedResponseCodes = map[string]int{
76
76
"PUT" : 200 ,
77
77
}
78
78
79
- func (c * ClusterSync ) Monitor (cfg * Configuration , cli * client_native.HAProxyClient ) {
79
+ func (c * ClusterSync ) Monitor (cfg * Configuration , cli client_native.HAProxyClient ) {
80
80
c .cfg = cfg
81
81
c .cli = cli
82
82
@@ -144,7 +144,7 @@ func (c *ClusterSync) issueRefreshRequest(url, port, basePath string, nodesPath
144
144
Status : cfg .Status .Load (),
145
145
Type : DataplaneAPIType ,
146
146
}
147
- var json = jsoniter .ConfigCompatibleWithStandardLibrary
147
+ json : = jsoniter .ConfigCompatibleWithStandardLibrary
148
148
bytesRepresentation , _ := json .Marshal (nodeData )
149
149
150
150
req , err := http .NewRequest ("PATCH" , url , bytes .NewBuffer (bytesRepresentation ))
@@ -344,7 +344,7 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, registerPath
344
344
}
345
345
nodeData .Facts = c .getNodeFacts ()
346
346
347
- var json = jsoniter .ConfigCompatibleWithStandardLibrary
347
+ json : = jsoniter .ConfigCompatibleWithStandardLibrary
348
348
bytesRepresentation , _ := json .Marshal (nodeData )
349
349
350
350
req , err := http .NewRequest (registerMethod , url , bytes .NewBuffer (bytesRepresentation ))
@@ -375,22 +375,23 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, registerPath
375
375
return err
376
376
}
377
377
if c .cfg .HAProxy .NodeIDFile != "" {
378
+ configuration := c .cli .Configuration ()
378
379
// write id to file
379
380
errFID := ioutil .WriteFile (c .cfg .HAProxy .NodeIDFile , []byte (responseData .ID ), 0644 ) // nolint:gosec
380
381
if errFID != nil {
381
382
return errFID
382
383
}
383
- version , errVersion := c . cli . Configuration .GetVersion ("" )
384
+ version , errVersion := configuration .GetVersion ("" )
384
385
if errVersion != nil || version < 1 {
385
386
// silently fallback to 1
386
387
version = 1
387
388
}
388
- t , err1 := c . cli . Configuration .StartTransaction (version )
389
+ t , err1 := configuration .StartTransaction (version )
389
390
if err1 != nil {
390
391
return err1
391
392
}
392
393
// write id to peers
393
- _ , peerSections , errorGet := c . cli . Configuration .GetPeerSections (t .ID )
394
+ _ , peerSections , errorGet := configuration .GetPeerSections (t .ID )
394
395
if errorGet != nil {
395
396
return errorGet
396
397
}
@@ -400,27 +401,27 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, registerPath
400
401
dataplaneID = "localhost"
401
402
}
402
403
for _ , section := range peerSections {
403
- _ , peerEntries , err1 := c . cli . Configuration .GetPeerEntries (section .Name , t .ID )
404
+ _ , peerEntries , err1 := configuration .GetPeerEntries (section .Name , t .ID )
404
405
if err1 != nil {
405
406
return err1
406
407
}
407
408
for _ , peer := range peerEntries {
408
409
if peer .Name == dataplaneID {
409
410
peerFound = true
410
411
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 )
412
413
if errEdit != nil {
413
- _ = c . cli . Configuration .DeleteTransaction (t .ID )
414
+ _ = configuration .DeleteTransaction (t .ID )
414
415
return err
415
416
}
416
417
}
417
418
}
418
419
}
419
420
if ! peerFound {
420
- _ = c . cli . Configuration .DeleteTransaction (t .ID )
421
+ _ = configuration .DeleteTransaction (t .ID )
421
422
return fmt .Errorf ("peer [%s] not found in HAProxy config" , dataplaneID )
422
423
}
423
- _ , err = c . cli . Configuration .CommitTransaction (t .ID )
424
+ _ , err = configuration .CommitTransaction (t .ID )
424
425
if err != nil {
425
426
return err
426
427
}
@@ -520,7 +521,7 @@ func (c *ClusterSync) fetchCert() {
520
521
break
521
522
}
522
523
var responseData Node
523
- var json = jsoniter .ConfigCompatibleWithStandardLibrary
524
+ json : = jsoniter .ConfigCompatibleWithStandardLibrary
524
525
err = json .Unmarshal (body , & responseData )
525
526
if err != nil {
526
527
c .activateFetchCert (err )
0 commit comments