diff --git a/pkg/cli/haproxy.go b/pkg/cli/haproxy.go index a78589d71bf7..cd3ff831cbc7 100644 --- a/pkg/cli/haproxy.go +++ b/pkg/cli/haproxy.go @@ -115,8 +115,10 @@ func nodeStatusesToNodeInfos(nodes *serverpb.NodesResponse) []haProxyNodeInfo { // TODO(knz): this logic is horrendously broken and // incorrect. Replace it. for j, arg := range status.Args { - if strings.Contains(arg, cliflags.ListenHTTPPort.Name) || - strings.Contains(arg, cliflags.ListenHTTPAddr.Name) { + if strings.HasPrefix(arg, "--"+cliflags.ListenHTTPPort.Name) || + strings.HasPrefix(arg, "--"+cliflags.ListenHTTPAddr.Name) || + strings.HasPrefix(arg, "-"+cliflags.ListenHTTPPort.Name) || + strings.HasPrefix(arg, "-"+cliflags.ListenHTTPAddr.Name) { _ = fs.Parse(status.Args[j:]) break } diff --git a/pkg/cli/haproxy_test.go b/pkg/cli/haproxy_test.go index 1789ba593ad8..023bdc931b1c 100644 --- a/pkg/cli/haproxy_test.go +++ b/pkg/cli/haproxy_test.go @@ -108,6 +108,21 @@ func TestNodeStatusToNodeInfoConversion(t *testing.T) { }, }, }, + // Check that --advertise-http-addr is not mistaken for --http-addr. + { + serverpb.NodesResponse{Nodes: []statuspb.NodeStatus{ + { + Desc: roachpb.NodeDescriptor{NodeID: 1}, + Args: []string{"--advertise-http-addr=node.example:9999", "--http-addr=node.example:5678"}, + }, + }}, + []haProxyNodeInfo{ + { + NodeID: 1, + CheckPort: "5678", + }, + }, + }, // Check that decommission{ing,ed} nodes are not considered for // generating the configuration. {