Skip to content

Commit da83051

Browse files
committed
MINOR: add integration flag for HAProxy master-worker mode
1 parent e169788 commit da83051

File tree

2 files changed

+46
-11
lines changed

2 files changed

+46
-11
lines changed

configuration/cluster_sync.go

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import (
2828
"fmt"
2929
"io/ioutil"
3030
"net/http"
31+
"os"
3132
"path"
3233
"strings"
3334
"time"
@@ -43,17 +44,18 @@ const DataplaneAPIType = "community"
4344

4445
//Node is structure required for connection to cluster
4546
type Node struct {
46-
Address string `json:"address"`
47-
APIBasePath string `json:"api_base_path"`
48-
APIPassword string `json:"api_password"`
49-
APIUser string `json:"api_user"`
50-
Certificate string `json:"certificate,omitempty"`
51-
Description string `json:"description,omitempty"`
52-
ID string `json:"id,omitempty"`
53-
Name string `json:"name"`
54-
Port int64 `json:"port,omitempty"`
55-
Status string `json:"status"`
56-
Type string `json:"type"`
47+
Address string `json:"address"`
48+
APIBasePath string `json:"api_base_path"`
49+
APIPassword string `json:"api_password"`
50+
APIUser string `json:"api_user"`
51+
Certificate string `json:"certificate,omitempty"`
52+
Description string `json:"description,omitempty"`
53+
ID string `json:"id,omitempty"`
54+
Name string `json:"name"`
55+
Port int64 `json:"port,omitempty"`
56+
Status string `json:"status"`
57+
Type string `json:"type"`
58+
Variables map[string]string `json:"variables"`
5759
}
5860

5961
//ClusterSync fetches certificates for joining cluster
@@ -281,6 +283,24 @@ func (c *ClusterSync) issueJoinRequest(url, port, basePath string, nodesPath str
281283
Status: "waiting_approval",
282284
Type: DataplaneAPIType,
283285
}
286+
nodeData.Variables = map[string]string{}
287+
288+
// report the dataplane_cmdline if started from within haproxy
289+
if c.cfg.HAProxy.MasterWorkerMode || os.Getenv("HAPROXY_MWORKER") == "1" {
290+
nodeData.Variables["dataplane_cmdline"] = c.cfg.Cmdline.String()
291+
}
292+
293+
processInfos, err := c.cli.Runtime.GetInfo()
294+
if err != nil || len(processInfos) < 1 {
295+
log.Error("unable to fetch processInfo")
296+
} else {
297+
if processInfos[0].Info != nil {
298+
nodeData.Variables["haproxy_version"] = processInfos[0].Info.Version
299+
} else {
300+
log.Error("empty process info")
301+
}
302+
}
303+
284304
bytesRepresentation, _ := json.Marshal(nodeData)
285305

286306
req, err := http.NewRequest("POST", url, bytes.NewBuffer(bytesRepresentation))

configuration/configuration.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,11 @@ package configuration
1717

1818
import (
1919
"encoding/json"
20+
"fmt"
2021
"io/ioutil"
22+
"os"
2123
"path/filepath"
24+
"strings"
2225

2326
"math/rand"
2427
"time"
@@ -51,6 +54,7 @@ type HAProxyConfiguration struct {
5154
UpdateMapFiles bool `long:"update-map-files" description:"Flag used for syncing map files with runtime maps values"`
5255
UpdateMapFilesPeriod int64 `long:"update-map-files-period" description:"Elapsed time in seconds between two maps syncing operations" default:"10"`
5356
ClusterTLSCertDir string `long:"cluster-tls-dir" description:"Path where cluster tls certificates will be stored. Defaults to same directory as dataplane configuration file"`
57+
MasterWorkerMode bool `long:"master-worker-mode" description:"Flag to enable helpers when running within HAProxy"`
5458
}
5559

5660
type APIConfiguration struct {
@@ -118,6 +122,7 @@ type Configuration struct {
118122
BootstrapKey AtomicString `yaml:"bootstrap_key"`
119123
Mode AtomicString `yaml:"mode" default:"single"`
120124
Status AtomicString `yaml:"status"`
125+
Cmdline AtomicString `yaml:"-"`
121126
}
122127

123128
//Get returns pointer to configuration
@@ -129,6 +134,16 @@ func Get() *Configuration {
129134
cfg.Notify.CertificateRefresh = NewChanNotify()
130135
cfg.Notify.Reload = NewChanNotify()
131136
cfg.Notify.Shutdown = NewChanNotify()
137+
138+
var sb strings.Builder
139+
for _, v := range os.Args {
140+
if !strings.HasPrefix(v, "-") && !strings.Contains(v, `\ `) && strings.ContainsAny(v, " ") {
141+
fmt.Fprintf(&sb, "\"%s\" ", v)
142+
}
143+
fmt.Fprintf(&sb, "%s ", v)
144+
}
145+
146+
cfg.Cmdline.Store(sb.String())
132147
}
133148
return cfg
134149
}

0 commit comments

Comments
 (0)