Skip to content

Commit

Permalink
Merge pull request #3682 from telepresenceio/thallgren/env-value-expa…
Browse files Browse the repository at this point in the history
…nsion

Ensure that environment variable values are expanded correctly.
  • Loading branch information
thallgren authored Sep 3, 2024
2 parents d997d8c + b0c0fbb commit bd0affe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
6 changes: 6 additions & 0 deletions cmd/traffic/cmd/manager/mutator/agent_injector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1700,6 +1700,10 @@ func TestTrafficAgentInjector(t *testing.T) {
Name: "SECRET_NAME",
Value: "default-secret-name",
},
{
Name: "BOTH_NAMES",
Value: "$(TOKEN_VOLUME) and $(SECRET_NAME)",
},
},
Ports: []core.ContainerPort{
{
Expand Down Expand Up @@ -1735,6 +1739,8 @@ func TestTrafficAgentInjector(t *testing.T) {
value: default-token-vol
- name: _TEL_APP_A_SECRET_NAME
value: default-secret-name
- name: _TEL_APP_A_BOTH_NAMES
value: $(_TEL_APP_A_TOKEN_VOLUME) and $(_TEL_APP_A_SECRET_NAME)
- name: _TEL_AGENT_POD_IP
valueFrom:
fieldRef:
Expand Down
8 changes: 7 additions & 1 deletion pkg/agentconfig/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package agentconfig
import (
"context"
"encoding/json"
"regexp"
"strconv"
"strings"

Expand Down Expand Up @@ -434,9 +435,14 @@ func prefixInterpolated(str, pfx string) string {
return bd.String()
}

var envRxReplace = regexp.MustCompile(`\$\(([^)]+)\)`)

func appendAppContainerEnv(app *core.Container, cc *Container, es []core.EnvVar) []core.EnvVar {
pfx := EnvPrefixApp + cc.EnvPrefix
pfxReplace := "$(" + pfx + "$1)"
for _, e := range app.Env {
e.Name = EnvPrefixApp + cc.EnvPrefix + e.Name
e.Name = pfx + e.Name
e.Value = envRxReplace.ReplaceAllString(e.Value, pfxReplace)
es = append(es, e)
}
return es
Expand Down

0 comments on commit bd0affe

Please sign in to comment.