Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Nomad
Commits
c58efbce
Commit
c58efbce
authored
8 years ago
by
Michael Schurter
Committed by
GitHub
8 years ago
Browse files
Options
Download
Plain Diff
Merge pull request #2494 from hashicorp/b-2491-task-env
Don't take a reference a var in a loop
parents
635215db
7f2bbe70
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
CHANGELOG.md
+1
-0
CHANGELOG.md
client/driver/env/env.go
+3
-3
client/driver/env/env.go
client/driver/env/env_test.go
+31
-4
client/driver/env/env_test.go
with
35 additions
and
7 deletions
+35
-7
CHANGELOG.md
+
1
-
0
View file @
c58efbce
...
...
@@ -10,6 +10,7 @@ BUG FIXES:
*
api: Fix TLS in logs and fs commands/APIs [GH-2290]
*
cli/plan: Fix diff alignment and remove no change DC output [GH-2465]
*
client: Fix panic when restarting non-running tasks [GH-2480]
*
client: Fix env vars when multiple tasks and ports present [GH-2491]
*
client: Fix
`user`
attribute disregarding membership of non-main group
[GH-2461]
*
client/vault: Stop Vault token renewal on task exit [GH-2495]
...
...
This diff is collapsed.
Click to expand it.
client/driver/env/env.go
+
3
-
3
View file @
c58efbce
...
...
@@ -203,12 +203,12 @@ func (t *TaskEnvironment) Build() *TaskEnvironment {
continue
}
for
_
,
nw
:=
range
resources
.
Networks
{
ports
:=
make
([]
*
structs
.
Port
,
0
,
len
(
nw
.
ReservedPorts
)
+
len
(
nw
.
DynamicPorts
))
ports
:=
make
([]
structs
.
Port
,
0
,
len
(
nw
.
ReservedPorts
)
+
len
(
nw
.
DynamicPorts
))
for
_
,
port
:=
range
nw
.
ReservedPorts
{
ports
=
append
(
ports
,
&
port
)
ports
=
append
(
ports
,
port
)
}
for
_
,
port
:=
range
nw
.
DynamicPorts
{
ports
=
append
(
ports
,
&
port
)
ports
=
append
(
ports
,
port
)
}
for
_
,
p
:=
range
ports
{
key
:=
fmt
.
Sprintf
(
"%s%s_%s"
,
AddrPrefix
,
taskName
,
p
.
Label
)
...
...
This diff is collapsed.
Click to expand it.
client/driver/env/env_test.go
+
31
-
4
View file @
c58efbce
...
...
@@ -138,7 +138,24 @@ func TestEnvironment_ReplaceEnv_Mixed(t *testing.T) {
func
TestEnvironment_AsList
(
t
*
testing
.
T
)
{
n
:=
mock
.
Node
()
a
:=
mock
.
Alloc
()
a
.
Resources
.
Networks
[
0
]
.
ReservedPorts
=
append
(
a
.
Resources
.
Networks
[
0
]
.
ReservedPorts
,
structs
.
Port
{
Label
:
"ssh"
,
Value
:
22
},
structs
.
Port
{
Label
:
"other"
,
Value
:
1234
},
)
a
.
TaskResources
[
"web"
]
.
Networks
[
0
]
.
DynamicPorts
[
0
]
.
Value
=
2000
a
.
TaskResources
[
"ssh"
]
=
&
structs
.
Resources
{
Networks
:
[]
*
structs
.
NetworkResource
{
{
Device
:
"eth0"
,
IP
:
"192.168.0.100"
,
MBits
:
50
,
ReservedPorts
:
[]
structs
.
Port
{
{
Label
:
"ssh"
,
Value
:
22
},
{
Label
:
"other"
,
Value
:
1234
},
},
},
},
}
env
:=
NewTaskEnvironment
(
n
)
.
SetNetworks
(
networks
)
.
SetPortMap
(
portMap
)
.
...
...
@@ -165,13 +182,23 @@ func TestEnvironment_AsList(t *testing.T) {
"NOMAD_IP_web_main=192.168.0.100"
,
"NOMAD_IP_web_http=192.168.0.100"
,
"NOMAD_TASK_NAME=taskA"
,
"NOMAD_ADDR_ssh_other=192.168.0.100:1234"
,
"NOMAD_ADDR_ssh_ssh=192.168.0.100:22"
,
"NOMAD_IP_ssh_other=192.168.0.100"
,
"NOMAD_IP_ssh_ssh=192.168.0.100"
,
"NOMAD_PORT_ssh_other=1234"
,
"NOMAD_PORT_ssh_ssh=22"
,
fmt
.
Sprintf
(
"NOMAD_ALLOC_ID=%s"
,
a
.
ID
),
}
allocID
:=
fmt
.
Sprintf
(
"NOMAD_ALLOC_ID=%s"
,
a
.
ID
)
exp
=
append
(
exp
,
allocID
)
sort
.
Strings
(
act
)
sort
.
Strings
(
exp
)
if
!
reflect
.
DeepEqual
(
act
,
exp
)
{
t
.
Fatalf
(
"env.List() returned %v;
\n
want:
\n
%v"
,
strings
.
Join
(
act
,
"
\n
"
),
strings
.
Join
(
exp
,
"
\n
"
))
if
len
(
act
)
!=
len
(
exp
)
{
t
.
Fatalf
(
"wat: %d != %d"
,
len
(
act
),
len
(
exp
))
}
for
i
:=
range
act
{
if
act
[
i
]
!=
exp
[
i
]
{
t
.
Errorf
(
"%d %q != %q"
,
i
,
act
[
i
],
exp
[
i
])
}
}
}
...
...
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
Menu
Projects
Groups
Snippets
Help