mirror of https://github.com/status-im/consul.git
Validate port on mesh service registration (#12881)
Add validation to ensure connect native services have a port or socketpath specified on catalog registration. This was the only missing piece to ensure all mesh services are validated for a port (or socketpath) specification on catalog registration.
This commit is contained in:
parent
c6ff4ba7d8
commit
0c855fab98
|
@ -0,0 +1,4 @@
|
||||||
|
```release-note:enhancement
|
||||||
|
connect: add validation to ensure connect native services have a port or socketpath specified on catalog registration.
|
||||||
|
This was the only missing piece to ensure all mesh services are validated for a port (or socketpath) specification on catalog registration.
|
||||||
|
```
|
|
@ -1335,8 +1335,7 @@ func (s *NodeService) Validate() error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Port == 0 && s.SocketPath == "" {
|
if s.Port == 0 && s.SocketPath == "" {
|
||||||
result = multierror.Append(result, fmt.Errorf(
|
result = multierror.Append(result, fmt.Errorf("Port or SocketPath must be set for a %s", s.Kind))
|
||||||
"Port or SocketPath must be set for a Connect proxy"))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if s.Connect.Native {
|
if s.Connect.Native {
|
||||||
|
@ -1484,6 +1483,11 @@ func (s *NodeService) Validate() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.Connect.Native && s.Port == 0 && s.SocketPath == "" {
|
||||||
|
result = multierror.Append(result, fmt.Errorf(
|
||||||
|
"Port or SocketPath must be set for a Connect native service."))
|
||||||
|
}
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -678,6 +678,10 @@ func TestStructs_NodeService_ValidateTerminatingGateway(t *testing.T) {
|
||||||
func(x *NodeService) { x.Proxy.Upstreams = []Upstream{{}} },
|
func(x *NodeService) { x.Proxy.Upstreams = []Upstream{{}} },
|
||||||
"Proxy.Upstreams configuration is invalid",
|
"Proxy.Upstreams configuration is invalid",
|
||||||
},
|
},
|
||||||
|
"port": {
|
||||||
|
func(x *NodeService) { x.Port = 0 },
|
||||||
|
"Port must be non-zero",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, tc := range cases {
|
for name, tc := range cases {
|
||||||
|
@ -845,7 +849,7 @@ func TestStructs_NodeService_ValidateConnectProxy(t *testing.T) {
|
||||||
{
|
{
|
||||||
"connect-proxy: no port set",
|
"connect-proxy: no port set",
|
||||||
func(x *NodeService) { x.Port = 0 },
|
func(x *NodeService) { x.Port = 0 },
|
||||||
"port or socketpath must",
|
fmt.Sprintf("Port or SocketPath must be set for a %s", ServiceKindConnectProxy),
|
||||||
},
|
},
|
||||||
|
|
||||||
{
|
{
|
||||||
|
@ -1285,6 +1289,15 @@ func TestStructs_NodeService_ValidateSidecarService(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStructs_NodeService_ConnectNativeEmptyPortError(t *testing.T) {
|
||||||
|
ns := TestNodeService(t)
|
||||||
|
ns.Connect.Native = true
|
||||||
|
ns.Port = 0
|
||||||
|
err := ns.Validate()
|
||||||
|
assert.Error(t, err)
|
||||||
|
assert.Contains(t, err.Error(), "Port or SocketPath must be set for a Connect native service.")
|
||||||
|
}
|
||||||
|
|
||||||
func TestStructs_NodeService_IsSame(t *testing.T) {
|
func TestStructs_NodeService_IsSame(t *testing.T) {
|
||||||
ns := &NodeService{
|
ns := &NodeService{
|
||||||
ID: "node1",
|
ID: "node1",
|
||||||
|
|
Loading…
Reference in New Issue