mirror of https://github.com/status-im/consul.git
agent: change connect command paths to be slices, not strings
This matches other executable configuration and allows us to cleanly separate executable from arguments without trying to emulate shell parsing.
This commit is contained in:
parent
7355a614fe
commit
aaa2431350
|
@ -63,7 +63,7 @@ func TestAgent_Services(t *testing.T) {
|
|||
// Add a managed proxy for that service
|
||||
prxy1 := &structs.ConnectManagedProxy{
|
||||
ExecMode: structs.ProxyExecModeScript,
|
||||
Command: "proxy.sh",
|
||||
Command: []string{"proxy.sh"},
|
||||
Config: map[string]interface{}{
|
||||
"bind_port": 1234,
|
||||
"foo": "bar",
|
||||
|
@ -1404,7 +1404,7 @@ func TestAgent_RegisterService_ManagedConnectProxy(t *testing.T) {
|
|||
Connect: &api.AgentServiceConnect{
|
||||
Proxy: &api.AgentServiceConnectProxy{
|
||||
ExecMode: "script",
|
||||
Command: "proxy.sh",
|
||||
Command: []string{"proxy.sh"},
|
||||
Config: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
},
|
||||
|
@ -2354,7 +2354,7 @@ func TestAgentConnectProxyConfig_Blocking(t *testing.T) {
|
|||
TargetServiceName: "test",
|
||||
ContentHash: "84346af2031659c9",
|
||||
ExecMode: "daemon",
|
||||
Command: "consul connect proxy",
|
||||
Command: nil,
|
||||
Config: map[string]interface{}{
|
||||
"upstreams": []interface{}{
|
||||
map[string]interface{}{
|
||||
|
|
|
@ -2333,7 +2333,7 @@ func TestAgent_AddProxy(t *testing.T) {
|
|||
desc: "basic proxy adding, unregistered service",
|
||||
proxy: &structs.ConnectManagedProxy{
|
||||
ExecMode: structs.ProxyExecModeDaemon,
|
||||
Command: "consul connect proxy",
|
||||
Command: []string{"consul", "connect", "proxy"},
|
||||
Config: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
},
|
||||
|
@ -2346,7 +2346,7 @@ func TestAgent_AddProxy(t *testing.T) {
|
|||
desc: "basic proxy adding, unregistered service",
|
||||
proxy: &structs.ConnectManagedProxy{
|
||||
ExecMode: structs.ProxyExecModeDaemon,
|
||||
Command: "consul connect proxy",
|
||||
Command: []string{"consul", "connect", "proxy"},
|
||||
Config: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
},
|
||||
|
@ -2392,6 +2392,7 @@ func TestAgent_RemoveProxy(t *testing.T) {
|
|||
// Add a proxy for web
|
||||
pReg := &structs.ConnectManagedProxy{
|
||||
TargetServiceID: "web",
|
||||
Command: []string{"foo"},
|
||||
}
|
||||
require.NoError(a.AddProxy(pReg, false))
|
||||
|
||||
|
|
|
@ -532,13 +532,13 @@ func (b *Builder) Build() (rt RuntimeConfig, err error) {
|
|||
}
|
||||
|
||||
proxyDefaultExecMode := ""
|
||||
proxyDefaultDaemonCommand := ""
|
||||
proxyDefaultScriptCommand := ""
|
||||
var proxyDefaultDaemonCommand []string
|
||||
var proxyDefaultScriptCommand []string
|
||||
proxyDefaultConfig := make(map[string]interface{})
|
||||
if c.Connect != nil && c.Connect.ProxyDefaults != nil {
|
||||
proxyDefaultExecMode = b.stringVal(c.Connect.ProxyDefaults.ExecMode)
|
||||
proxyDefaultDaemonCommand = b.stringVal(c.Connect.ProxyDefaults.DaemonCommand)
|
||||
proxyDefaultScriptCommand = b.stringVal(c.Connect.ProxyDefaults.ScriptCommand)
|
||||
proxyDefaultDaemonCommand = c.Connect.ProxyDefaults.DaemonCommand
|
||||
proxyDefaultScriptCommand = c.Connect.ProxyDefaults.ScriptCommand
|
||||
proxyDefaultConfig = c.Connect.ProxyDefaults.Config
|
||||
}
|
||||
|
||||
|
@ -1051,7 +1051,7 @@ func (b *Builder) serviceConnectVal(v *ServiceConnect) *structs.ServiceDefinitio
|
|||
if v.Proxy != nil {
|
||||
proxy = &structs.ServiceDefinitionConnectProxy{
|
||||
ExecMode: b.stringVal(v.Proxy.ExecMode),
|
||||
Command: b.stringVal(v.Proxy.Command),
|
||||
Command: v.Proxy.Command,
|
||||
Config: v.Proxy.Config,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -359,7 +359,7 @@ type ServiceConnect struct {
|
|||
}
|
||||
|
||||
type ServiceConnectProxy struct {
|
||||
Command *string `json:"command,omitempty" hcl:"command" mapstructure:"command"`
|
||||
Command []string `json:"command,omitempty" hcl:"command" mapstructure:"command"`
|
||||
ExecMode *string `json:"exec_mode,omitempty" hcl:"exec_mode" mapstructure:"exec_mode"`
|
||||
Config map[string]interface{} `json:"config,omitempty" hcl:"config" mapstructure:"config"`
|
||||
}
|
||||
|
@ -386,10 +386,10 @@ type ConnectProxyDefaults struct {
|
|||
ExecMode *string `json:"exec_mode,omitempty" hcl:"exec_mode" mapstructure:"exec_mode"`
|
||||
// DaemonCommand is used to start proxy in exec_mode = daemon if not specified
|
||||
// at registration time.
|
||||
DaemonCommand *string `json:"daemon_command,omitempty" hcl:"daemon_command" mapstructure:"daemon_command"`
|
||||
DaemonCommand []string `json:"daemon_command,omitempty" hcl:"daemon_command" mapstructure:"daemon_command"`
|
||||
// ScriptCommand is used to start proxy in exec_mode = script if not specified
|
||||
// at registration time.
|
||||
ScriptCommand *string `json:"script_command,omitempty" hcl:"script_command" mapstructure:"script_command"`
|
||||
ScriptCommand []string `json:"script_command,omitempty" hcl:"script_command" mapstructure:"script_command"`
|
||||
// Config is merged into an Config specified at registration time.
|
||||
Config map[string]interface{} `json:"config,omitempty" hcl:"config" mapstructure:"config"`
|
||||
}
|
||||
|
|
|
@ -637,11 +637,11 @@ type RuntimeConfig struct {
|
|||
|
||||
// ConnectProxyDefaultDaemonCommand is used to start proxy in exec_mode =
|
||||
// daemon if not specified at registration time.
|
||||
ConnectProxyDefaultDaemonCommand string
|
||||
ConnectProxyDefaultDaemonCommand []string
|
||||
|
||||
// ConnectProxyDefaultScriptCommand is used to start proxy in exec_mode =
|
||||
// script if not specified at registration time.
|
||||
ConnectProxyDefaultScriptCommand string
|
||||
ConnectProxyDefaultScriptCommand []string
|
||||
|
||||
// ConnectProxyDefaultConfig is merged with any config specified at
|
||||
// registration time to allow global control of defaults.
|
||||
|
|
|
@ -2364,8 +2364,8 @@ func TestFullConfig(t *testing.T) {
|
|||
"bind_min_port": 2000,
|
||||
"bind_max_port": 3000,
|
||||
"exec_mode": "script",
|
||||
"daemon_command": "consul connect proxy",
|
||||
"script_command": "proxyctl.sh",
|
||||
"daemon_command": ["consul", "connect", "proxy"],
|
||||
"script_command": ["proxyctl.sh"],
|
||||
"config": {
|
||||
"foo": "bar",
|
||||
"connect_timeout_ms": 1000,
|
||||
|
@ -2637,7 +2637,7 @@ func TestFullConfig(t *testing.T) {
|
|||
"connect": {
|
||||
"proxy": {
|
||||
"exec_mode": "daemon",
|
||||
"command": "awesome-proxy",
|
||||
"command": ["awesome-proxy"],
|
||||
"config": {
|
||||
"foo": "qux"
|
||||
}
|
||||
|
@ -2826,13 +2826,13 @@ func TestFullConfig(t *testing.T) {
|
|||
bind_min_port = 2000
|
||||
bind_max_port = 3000
|
||||
exec_mode = "script"
|
||||
daemon_command = "consul connect proxy"
|
||||
script_command = "proxyctl.sh"
|
||||
daemon_command = ["consul", "connect", "proxy"]
|
||||
script_command = ["proxyctl.sh"]
|
||||
config = {
|
||||
foo = "bar"
|
||||
# hack float since json parses numbers as float and we have to
|
||||
# assert against the same thing
|
||||
connect_timeout_ms = 1000.0
|
||||
connect_timeout_ms = 1000.0
|
||||
pedantic_mode = true
|
||||
}
|
||||
}
|
||||
|
@ -3101,7 +3101,7 @@ func TestFullConfig(t *testing.T) {
|
|||
connect {
|
||||
proxy {
|
||||
exec_mode = "daemon"
|
||||
command = "awesome-proxy"
|
||||
command = ["awesome-proxy"]
|
||||
config = {
|
||||
foo = "qux"
|
||||
}
|
||||
|
@ -3426,8 +3426,8 @@ func TestFullConfig(t *testing.T) {
|
|||
"hyMy9Oxn": "XeBp4Sis",
|
||||
},
|
||||
ConnectProxyDefaultExecMode: "script",
|
||||
ConnectProxyDefaultDaemonCommand: "consul connect proxy",
|
||||
ConnectProxyDefaultScriptCommand: "proxyctl.sh",
|
||||
ConnectProxyDefaultDaemonCommand: []string{"consul", "connect", "proxy"},
|
||||
ConnectProxyDefaultScriptCommand: []string{"proxyctl.sh"},
|
||||
ConnectProxyDefaultConfig: map[string]interface{}{
|
||||
"foo": "bar",
|
||||
"connect_timeout_ms": float64(1000),
|
||||
|
@ -3608,7 +3608,7 @@ func TestFullConfig(t *testing.T) {
|
|||
Connect: &structs.ServiceDefinitionConnect{
|
||||
Proxy: &structs.ServiceDefinitionConnectProxy{
|
||||
ExecMode: "daemon",
|
||||
Command: "awesome-proxy",
|
||||
Command: []string{"awesome-proxy"},
|
||||
Config: map[string]interface{}{
|
||||
"foo": "qux",
|
||||
},
|
||||
|
@ -4109,9 +4109,9 @@ func TestSanitize(t *testing.T) {
|
|||
"ConnectProxyBindMaxPort": 0,
|
||||
"ConnectProxyBindMinPort": 0,
|
||||
"ConnectProxyDefaultConfig": {},
|
||||
"ConnectProxyDefaultDaemonCommand": "",
|
||||
"ConnectProxyDefaultDaemonCommand": [],
|
||||
"ConnectProxyDefaultExecMode": "",
|
||||
"ConnectProxyDefaultScriptCommand": "",
|
||||
"ConnectProxyDefaultScriptCommand": [],
|
||||
"ConsulCoordinateUpdateBatchSize": 0,
|
||||
"ConsulCoordinateUpdateMaxBatches": 0,
|
||||
"ConsulCoordinateUpdatePeriod": "15s",
|
||||
|
|
|
@ -64,7 +64,7 @@ type ConnectManagedProxy struct {
|
|||
// Command is the command to execute. Empty defaults to self-invoking the same
|
||||
// consul binary with proxy subcomand for ProxyExecModeDaemon and is an error
|
||||
// for ProxyExecModeScript.
|
||||
Command string
|
||||
Command []string
|
||||
|
||||
// Config is the arbitrary configuration data provided with the registration.
|
||||
Config map[string]interface{}
|
||||
|
|
|
@ -110,7 +110,7 @@ type ServiceDefinitionConnect struct {
|
|||
// registration. Note this is duplicated in config.ServiceConnectProxy and needs
|
||||
// to be kept in sync.
|
||||
type ServiceDefinitionConnectProxy struct {
|
||||
Command string
|
||||
Command []string
|
||||
ExecMode string
|
||||
Config map[string]interface{}
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ type AgentServiceConnect struct {
|
|||
// service.
|
||||
type AgentServiceConnectProxy struct {
|
||||
ExecMode ProxyExecMode
|
||||
Command string
|
||||
Command []string
|
||||
Config map[string]interface{}
|
||||
}
|
||||
|
||||
|
@ -225,7 +225,7 @@ type ConnectProxyConfig struct {
|
|||
TargetServiceName string
|
||||
ContentHash string
|
||||
ExecMode ProxyExecMode
|
||||
Command string
|
||||
Command []string
|
||||
Config map[string]interface{}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue