Skip to content

Commit

Permalink
fix: add node pool attribute to interpretable values in task env (#24052
Browse files Browse the repository at this point in the history
)
  • Loading branch information
mismithhisler authored Sep 24, 2024
1 parent 389545b commit 338487c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions .changelog/24052.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
task: adds node.pool attribute to interpretable values in task env
```
2 changes: 2 additions & 0 deletions client/taskenv/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ const (
nodeRegionKey = "node.region"
nodeNameKey = "node.unique.name"
nodeClassKey = "node.class"
nodePoolKey = "node.pool"

// Prefixes used for lookups.
nodeAttributePrefix = "attr."
Expand Down Expand Up @@ -855,6 +856,7 @@ func (b *Builder) setNode(n *structs.Node) *Builder {
b.nodeAttrs[nodeNameKey] = n.Name
b.nodeAttrs[nodeClassKey] = n.NodeClass
b.nodeAttrs[nodeDcKey] = n.Datacenter
b.nodeAttrs[nodePoolKey] = n.NodePool
b.datacenter = n.Datacenter
b.cgroupParent = n.CgroupParent

Expand Down
6 changes: 4 additions & 2 deletions client/taskenv/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const (
attrVal = "amd64"
nodeName = "test node"
nodeClass = "test class"
nodePool = "test pool"

// Environment variable values that tests can rely on
envOneKey = "NOMAD_IP"
Expand All @@ -56,6 +57,7 @@ func testEnvBuilder() *Builder {
}
n.Name = nodeName
n.NodeClass = nodeClass
n.NodePool = nodePool

task := mock.Job().TaskGroups[0].Tasks[0]
task.Env = map[string]string{
Expand Down Expand Up @@ -108,8 +110,8 @@ func TestEnvironment_ParseAndReplace_Attr(t *testing.T) {
func TestEnvironment_ParseAndReplace_Node(t *testing.T) {
ci.Parallel(t)

input := []string{fmt.Sprintf("${%v}", nodeNameKey), fmt.Sprintf("${%v}", nodeClassKey)}
exp := []string{nodeName, nodeClass}
input := []string{fmt.Sprintf("${%v}", nodeNameKey), fmt.Sprintf("${%v}", nodeClassKey), fmt.Sprintf("${%v}", nodePoolKey)}
exp := []string{nodeName, nodeClass, nodePool}
env := testEnvBuilder()
act := env.Build().ParseAndReplace(input)

Expand Down

0 comments on commit 338487c

Please sign in to comment.