mirror of https://github.com/status-im/consul.git
Fixup to support unix domain socket via command line (#10758)
Missed the need to add support for unix domain socket config via api/command line. This is a variant of the problems described in it is easy to drop one. Signed-off-by: Mark Anderson <manderson@hashicorp.com>
This commit is contained in:
parent
525bc2d763
commit
d3cebbd32c
|
@ -0,0 +1,3 @@
|
||||||
|
```release-note:feature
|
||||||
|
connect: add support for unix domain socket config via API/CLI
|
||||||
|
```
|
|
@ -256,6 +256,7 @@ func buildAgentService(s *structs.NodeService, dc string) api.AgentService {
|
||||||
Meta: s.Meta,
|
Meta: s.Meta,
|
||||||
Port: s.Port,
|
Port: s.Port,
|
||||||
Address: s.Address,
|
Address: s.Address,
|
||||||
|
SocketPath: s.SocketPath,
|
||||||
TaggedAddresses: taggedAddrs,
|
TaggedAddresses: taggedAddrs,
|
||||||
EnableTagOverride: s.EnableTagOverride,
|
EnableTagOverride: s.EnableTagOverride,
|
||||||
CreateIndex: s.CreateIndex,
|
CreateIndex: s.CreateIndex,
|
||||||
|
|
|
@ -263,6 +263,7 @@ type AgentServiceRegistration struct {
|
||||||
Tags []string `json:",omitempty"`
|
Tags []string `json:",omitempty"`
|
||||||
Port int `json:",omitempty"`
|
Port int `json:",omitempty"`
|
||||||
Address string `json:",omitempty"`
|
Address string `json:",omitempty"`
|
||||||
|
SocketPath string `json:",omitempty"`
|
||||||
TaggedAddresses map[string]ServiceAddress `json:",omitempty"`
|
TaggedAddresses map[string]ServiceAddress `json:",omitempty"`
|
||||||
EnableTagOverride bool `json:",omitempty"`
|
EnableTagOverride bool `json:",omitempty"`
|
||||||
Meta map[string]string `json:",omitempty"`
|
Meta map[string]string `json:",omitempty"`
|
||||||
|
|
|
@ -626,6 +626,46 @@ func TestAPI_AgentServiceAddress(t *testing.T) {
|
||||||
t.Fatalf("err: %v", err)
|
t.Fatalf("err: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
func TestAPI_AgentServiceSocket(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
c, s := makeClient(t)
|
||||||
|
defer s.Stop()
|
||||||
|
|
||||||
|
agent := c.Agent()
|
||||||
|
|
||||||
|
reg1 := &AgentServiceRegistration{
|
||||||
|
Name: "foo1",
|
||||||
|
Port: 8000,
|
||||||
|
Address: "192.168.0.42",
|
||||||
|
}
|
||||||
|
reg2 := &AgentServiceRegistration{
|
||||||
|
Name: "foo2",
|
||||||
|
SocketPath: "/tmp/foo2.sock",
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := agent.ServiceRegister(reg1); err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
if err := agent.ServiceRegister(reg2); err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
services, err := agent.Services()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("err: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
require.Contains(t, services, "foo1", "missing service foo1")
|
||||||
|
require.Contains(t, services, "foo2", "missing service foo2")
|
||||||
|
|
||||||
|
require.Equal(t, "192.168.0.42", services["foo1"].Address,
|
||||||
|
"missing Address field in service foo1: %v", services["foo1"])
|
||||||
|
|
||||||
|
require.Equal(t, "", services["foo2"].Address,
|
||||||
|
"unexpected Address field in service foo1: %v", services["foo2"])
|
||||||
|
require.Equal(t, "/tmp/foo2.sock", services["foo2"].SocketPath,
|
||||||
|
"missing SocketPath field in service foo1: %v", services["foo2"])
|
||||||
|
}
|
||||||
|
|
||||||
func TestAPI_AgentEnableTagOverride(t *testing.T) {
|
func TestAPI_AgentEnableTagOverride(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
|
@ -782,6 +782,7 @@ func TestAPI_CatalogNodeServiceList(t *testing.T) {
|
||||||
|
|
||||||
if proxySvc == nil {
|
if proxySvc == nil {
|
||||||
r.Fatalf("Missing proxy service: %v", info.Services)
|
r.Fatalf("Missing proxy service: %v", info.Services)
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if !reflect.DeepEqual(proxyReg.Service.Proxy, proxySvc.Proxy) {
|
if !reflect.DeepEqual(proxyReg.Service.Proxy, proxySvc.Proxy) {
|
||||||
|
|
|
@ -28,6 +28,7 @@ type cmd struct {
|
||||||
flagName string
|
flagName string
|
||||||
flagAddress string
|
flagAddress string
|
||||||
flagPort int
|
flagPort int
|
||||||
|
flagSocketPath string
|
||||||
flagTags []string
|
flagTags []string
|
||||||
flagMeta map[string]string
|
flagMeta map[string]string
|
||||||
flagTaggedAddresses map[string]string
|
flagTaggedAddresses map[string]string
|
||||||
|
@ -44,6 +45,8 @@ func (c *cmd) init() {
|
||||||
"Address of the service to register for arg-based registration.")
|
"Address of the service to register for arg-based registration.")
|
||||||
c.flags.IntVar(&c.flagPort, "port", 0,
|
c.flags.IntVar(&c.flagPort, "port", 0,
|
||||||
"Port of the service to register for arg-based registration.")
|
"Port of the service to register for arg-based registration.")
|
||||||
|
c.flags.StringVar(&c.flagSocketPath, "socket", "",
|
||||||
|
"Path to the Unix domain socket to register for arg-based registration (conflicts with address and port).")
|
||||||
c.flags.Var((*flags.FlagMapValue)(&c.flagMeta), "meta",
|
c.flags.Var((*flags.FlagMapValue)(&c.flagMeta), "meta",
|
||||||
"Metadata to set on the service, formatted as key=value. This flag "+
|
"Metadata to set on the service, formatted as key=value. This flag "+
|
||||||
"may be specified multiple times to set multiple meta fields.")
|
"may be specified multiple times to set multiple meta fields.")
|
||||||
|
@ -86,6 +89,7 @@ func (c *cmd) Run(args []string) int {
|
||||||
Name: c.flagName,
|
Name: c.flagName,
|
||||||
Address: c.flagAddress,
|
Address: c.flagAddress,
|
||||||
Port: c.flagPort,
|
Port: c.flagPort,
|
||||||
|
SocketPath: c.flagSocketPath,
|
||||||
Tags: c.flagTags,
|
Tags: c.flagTags,
|
||||||
Meta: c.flagMeta,
|
Meta: c.flagMeta,
|
||||||
TaggedAddresses: taggedAddrs,
|
TaggedAddresses: taggedAddrs,
|
||||||
|
|
|
@ -74,6 +74,8 @@ Please refer to that documentation for full details.
|
||||||
|
|
||||||
- `-port` - The port of the service.
|
- `-port` - The port of the service.
|
||||||
|
|
||||||
|
- `-socket` - The Unix Domain socket of the service. Conflicts with address and port flags.
|
||||||
|
|
||||||
- `-meta key=value` - Specify arbitrary KV metadata to associate with the
|
- `-meta key=value` - Specify arbitrary KV metadata to associate with the
|
||||||
service instance. This can be specified multiple times.
|
service instance. This can be specified multiple times.
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue