diff --git a/.changelog/12881.txt b/.changelog/12881.txt new file mode 100644 index 000000000..a2c5d90a5 --- /dev/null +++ b/.changelog/12881.txt @@ -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. +``` \ No newline at end of file diff --git a/agent/structs/structs.go b/agent/structs/structs.go index 467c94274..b229e5ac9 100644 --- a/agent/structs/structs.go +++ b/agent/structs/structs.go @@ -1335,8 +1335,7 @@ func (s *NodeService) Validate() error { } if s.Port == 0 && s.SocketPath == "" { - result = multierror.Append(result, fmt.Errorf( - "Port or SocketPath must be set for a Connect proxy")) + result = multierror.Append(result, fmt.Errorf("Port or SocketPath must be set for a %s", s.Kind)) } 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 } diff --git a/agent/structs/structs_test.go b/agent/structs/structs_test.go index 94aa103be..2164b1099 100644 --- a/agent/structs/structs_test.go +++ b/agent/structs/structs_test.go @@ -678,6 +678,10 @@ func TestStructs_NodeService_ValidateTerminatingGateway(t *testing.T) { func(x *NodeService) { x.Proxy.Upstreams = []Upstream{{}} }, "Proxy.Upstreams configuration is invalid", }, + "port": { + func(x *NodeService) { x.Port = 0 }, + "Port must be non-zero", + }, } for name, tc := range cases { @@ -845,7 +849,7 @@ func TestStructs_NodeService_ValidateConnectProxy(t *testing.T) { { "connect-proxy: no port set", 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) { ns := &NodeService{ ID: "node1",