Skip to content

Commit c16147c

Browse files
oktalzmjuraga
authored andcommitted
CLEANUP/MINOR: cluster: add more readability to join function
Signed-off-by: Zlatko Bratkovic <[email protected]>
1 parent d662e88 commit c16147c

File tree

2 files changed

+44
-18
lines changed

2 files changed

+44
-18
lines changed

configuration/cluster_sync.go

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import (
2929
"fmt"
3030
"io/ioutil"
3131
"net/http"
32-
"os"
3332
"path"
3433
"strconv"
3534
"strings"
@@ -342,23 +341,7 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, registerPath
342341
Status: "waiting_approval",
343342
Type: DataplaneAPIType,
344343
}
345-
nodeData.Variables = map[string]string{}
346-
347-
// report the dataplane_cmdline if started from within haproxy
348-
if c.cfg.HAProxy.MasterWorkerMode || os.Getenv("HAPROXY_MWORKER") == "1" {
349-
nodeData.Variables["dataplane_cmdline"] = c.cfg.Cmdline.String()
350-
}
351-
352-
processInfos, err := c.cli.Runtime.GetInfo()
353-
if err != nil || len(processInfos) < 1 {
354-
log.Error("unable to fetch processInfo")
355-
} else {
356-
if processInfos[0].Info != nil {
357-
nodeData.Variables["haproxy_version"] = processInfos[0].Info.Version
358-
} else {
359-
log.Error("empty process info")
360-
}
361-
}
344+
nodeData.Variables = c.getNodeVariables()
362345

363346
bytesRepresentation, _ := json.Marshal(nodeData)
364347

configuration/cluster_sync_helpers.go

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2019 HAProxy Technologies
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
16+
package configuration
17+
18+
import (
19+
"os"
20+
21+
"github.com/haproxytech/dataplaneapi/log"
22+
)
23+
24+
func (c *ClusterSync) getNodeVariables() map[string]string {
25+
variables := map[string]string{}
26+
27+
// report the dataplane_cmdline if started from within haproxy
28+
if c.cfg.HAProxy.MasterWorkerMode || os.Getenv("HAPROXY_MWORKER") == "1" {
29+
variables["dataplane_cmdline"] = c.cfg.Cmdline.String()
30+
}
31+
32+
processInfos, err := c.cli.Runtime.GetInfo()
33+
if err != nil || len(processInfos) < 1 {
34+
log.Error("unable to fetch processInfo")
35+
} else {
36+
if processInfos[0].Info != nil {
37+
variables["haproxy_version"] = processInfos[0].Info.Version
38+
} else {
39+
log.Error("empty process info")
40+
}
41+
}
42+
return variables
43+
}

0 commit comments

Comments
 (0)