Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
befcfc12
Commit
befcfc12
authored
5 years ago
by
Seth Hoenig
Browse files
Options
Download
Email Patches
Plain Diff
connect: enable setting tags on consul connect sidecar service in jobspec (#6415)
parent
0507d04f
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
api/services.go
+1
-0
api/services.go
command/agent/consul/client.go
+1
-0
command/agent/consul/client.go
command/agent/job_endpoint.go
+1
-0
command/agent/job_endpoint.go
command/agent/job_endpoint_test.go
+14
-0
command/agent/job_endpoint_test.go
jobspec/parse_service.go
+2
-1
jobspec/parse_service.go
jobspec/parse_test.go
+1
-0
jobspec/parse_test.go
jobspec/test-fixtures/tg-network.hcl
+1
-0
jobspec/test-fixtures/tg-network.hcl
nomad/structs/services.go
+5
-0
nomad/structs/services.go
nomad/structs/services_test.go
+1
-0
nomad/structs/services_test.go
with
27 additions
and
1 deletion
+27
-1
api/services.go
+
1
-
0
View file @
befcfc12
...
...
@@ -143,6 +143,7 @@ type ConsulConnect struct {
// ConsulSidecarService represents a Consul Connect SidecarService jobspec
// stanza.
type
ConsulSidecarService
struct
{
Tags
[]
string
Port
string
Proxy
*
ConsulProxy
}
...
...
This diff is collapsed.
Click to expand it.
command/agent/consul/client.go
+
1
-
0
View file @
befcfc12
...
...
@@ -1473,6 +1473,7 @@ func newConnect(serviceName string, nc *structs.ConsulConnect, networks structs.
// Advertise host IP:port
cc
.
SidecarService
=
&
api
.
AgentServiceRegistration
{
Tags
:
helper
.
CopySliceString
(
nc
.
SidecarService
.
Tags
),
Address
:
net
.
IP
,
Port
:
port
.
Value
,
...
...
This diff is collapsed.
Click to expand it.
command/agent/job_endpoint.go
+
1
-
0
View file @
befcfc12
...
...
@@ -1062,6 +1062,7 @@ func ApiConsulConnectToStructs(in *api.ConsulConnect) *structs.ConsulConnect {
if
in
.
SidecarService
!=
nil
{
out
.
SidecarService
=
&
structs
.
ConsulSidecarService
{
Tags
:
helper
.
CopySliceString
(
in
.
SidecarService
.
Tags
),
Port
:
in
.
SidecarService
.
Port
,
}
...
...
This diff is collapsed.
Click to expand it.
command/agent/job_endpoint_test.go
+
14
-
0
View file @
befcfc12
...
...
@@ -1537,6 +1537,13 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
TaskName
:
"task1"
,
},
},
Connect
:
&
api
.
ConsulConnect
{
Native
:
false
,
SidecarService
:
&
api
.
ConsulSidecarService
{
Tags
:
[]
string
{
"f"
,
"g"
},
Port
:
"9000"
,
},
},
},
},
Tasks
:
[]
*
api
.
Task
{
...
...
@@ -1877,6 +1884,13 @@ func TestJobs_ApiJobToStructsJob(t *testing.T) {
TaskName
:
"task1"
,
},
},
Connect
:
&
structs
.
ConsulConnect
{
Native
:
false
,
SidecarService
:
&
structs
.
ConsulSidecarService
{
Tags
:
[]
string
{
"f"
,
"g"
},
Port
:
"9000"
,
},
},
},
},
Tasks
:
[]
*
structs
.
Task
{
...
...
This diff is collapsed.
Click to expand it.
jobspec/parse_service.go
+
2
-
1
View file @
befcfc12
...
...
@@ -193,6 +193,7 @@ func parseSidecarService(o *ast.ObjectItem) (*api.ConsulSidecarService, error) {
valid
:=
[]
string
{
"port"
,
"proxy"
,
"tags"
,
}
if
err
:=
helper
.
CheckHCLKeys
(
o
.
Val
,
valid
);
err
!=
nil
{
...
...
@@ -216,7 +217,7 @@ func parseSidecarService(o *ast.ObjectItem) (*api.ConsulSidecarService, error) {
return
nil
,
err
}
if
err
:=
dec
.
Decode
(
m
);
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"
foo
: %v"
,
err
)
return
nil
,
fmt
.
Errorf
(
"
sidecar_service
: %v"
,
err
)
}
var
proxyList
*
ast
.
ObjectList
...
...
This diff is collapsed.
Click to expand it.
jobspec/parse_test.go
+
1
-
0
View file @
befcfc12
...
...
@@ -943,6 +943,7 @@ func TestParse(t *testing.T) {
PortLabel
:
"1234"
,
Connect
:
&
api
.
ConsulConnect
{
SidecarService
:
&
api
.
ConsulSidecarService
{
Tags
:
[]
string
{
"side1"
,
"side2"
},
Proxy
:
&
api
.
ConsulProxy
{
Upstreams
:
[]
*
api
.
ConsulUpstream
{
{
...
...
This diff is collapsed.
Click to expand it.
jobspec/test-fixtures/tg-network.hcl
+
1
-
0
View file @
befcfc12
...
...
@@ -21,6 +21,7 @@ job "foo" {
connect
{
sidecar_service
{
tags
=
[
"side1"
,
"side2"
]
proxy
{
local_service_port
=
8080
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/services.go
+
5
-
0
View file @
befcfc12
...
...
@@ -597,6 +597,10 @@ func (c *ConsulConnect) Validate() error {
// ConsulSidecarService represents a Consul Connect SidecarService jobspec
// stanza.
type
ConsulSidecarService
struct
{
// Tags are optional service tags that get registered with the sidecar service
// in Consul. If unset, the sidecar service inherits the parent service tags.
Tags
[]
string
// Port is the service's port that the sidecar will connect to. May be
// a port label or a literal port number.
Port
string
...
...
@@ -613,6 +617,7 @@ func (s *ConsulSidecarService) HasUpstreams() bool {
// Copy the stanza recursively. Returns nil if nil.
func
(
s
*
ConsulSidecarService
)
Copy
()
*
ConsulSidecarService
{
return
&
ConsulSidecarService
{
Tags
:
helper
.
CopySliceString
(
s
.
Tags
),
Port
:
s
.
Port
,
Proxy
:
s
.
Proxy
.
Copy
(),
}
...
...
This diff is collapsed.
Click to expand it.
nomad/structs/services_test.go
+
1
-
0
View file @
befcfc12
...
...
@@ -34,6 +34,7 @@ func TestConsulConnect_CopyEquals(t *testing.T) {
c
:=
&
ConsulConnect
{
SidecarService
:
&
ConsulSidecarService
{
Tags
:
[]
string
{
"tag1"
,
"tag2"
},
Port
:
"9001"
,
Proxy
:
&
ConsulProxy
{
LocalServiceAddress
:
"127.0.0.1"
,
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment