Skip to content

Commit

Permalink
Fixed env expansion in proto instance mapping (#787)
Browse files Browse the repository at this point in the history
  • Loading branch information
fkorotkov authored Sep 11, 2024
1 parent a025250 commit 5d2397e
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 5 deletions.
5 changes: 1 addition & 4 deletions pkg/parser/instance/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,7 @@ func NewProtoParser(
case field.IsMap():
fieldInstance := instance.proto.NewField(field)

mappingRetriever := func(env map[string]string) (map[string]string, error) {
return node.GetStringMapping()
}

mappingRetriever := node.GetStringMappingWithExpansion
if field.Name() == "docker_arguments" {
mappingRetriever = node.GetMapOrListOfMapsWithExpansion
}
Expand Down
13 changes: 13 additions & 0 deletions pkg/parser/node/accessor.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ func (node *Node) GetSliceOfExpandedStrings(env map[string]string) ([]string, er
return result, nil
}

func (node *Node) GetStringMappingWithExpansion(env map[string]string) (map[string]string, error) {
result, err := node.GetStringMapping()
if err != nil {
return nil, err
}

for key, value := range result {
result[key] = expander.ExpandEnvironmentVariables(value, env)
}

return result, nil
}

func (node *Node) GetStringMapping() (map[string]string, error) {
result := make(map[string]string)

Expand Down
12 changes: 11 additions & 1 deletion pkg/parser/testdata/proto-instance-volumes.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
"name": "clone"
}
],
"environment": {
"NAME": "test-name"
},
"instance": {
"@type": "type.googleapis.com/org.cirruslabs.ci.services.cirruscigrpc.PersistentWorkerInstance",
"isolation": {
Expand All @@ -22,6 +25,9 @@
}
]
}
},
"labels": {
"name": "test-name"
}
},
"metadata": {
Expand All @@ -44,7 +50,8 @@
}
],
"environment": {
"CIRRUS_OS": "linux"
"CIRRUS_OS": "linux",
"NAME": "test-name"
},
"instance": {
"@type": "type.googleapis.com/org.cirruslabs.ci.services.cirruscigrpc.PersistentWorkerInstance",
Expand All @@ -61,6 +68,9 @@
}
]
}
},
"labels": {
"name": "test-name"
}
},
"localGroupId": "1",
Expand Down
5 changes: 5 additions & 0 deletions pkg/parser/testdata/proto-instance-volumes.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
env:
NAME: test-name

aliases: &worker_body
labels:
name: $NAME
isolation:
container:
image: alpine:latest
Expand Down

0 comments on commit 5d2397e

Please sign in to comment.