Skip to content

Commit

Permalink
Merge pull request #26 from rcgeorge23/ISSUE-25-split-on-first-equals
Browse files Browse the repository at this point in the history
ISSUE-25: Splits env variable string on first occurrence of equals character
  • Loading branch information
joyrex2001 authored Oct 5, 2022
2 parents 1adb945 + d262d99 commit 8ab19d6
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 5 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.DS_Store
.vscode
.settings
Expand All @@ -7,4 +8,4 @@
coverage.out
_archive
dist/
target/
target/
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
## Build kubedock ## ----------------------------------------------------------
####################

FROM docker.io/golang:1.17 AS kubedock
FROM docker.io/golang:1.18 AS kubedock

ARG CODE=github.com/joyrex2001/kubedock

Expand Down
6 changes: 3 additions & 3 deletions internal/model/types/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ const (
func (co *Container) GetEnvVar() []corev1.EnvVar {
env := []corev1.EnvVar{}
for _, e := range co.Env {
f := strings.Split(e, "=")
if len(f) != 2 {
key, value, found := strings.Cut(e, "=")
if !found {
klog.Errorf("could not parse env %s", e)
continue
}
env = append(env, corev1.EnvVar{Name: f[0], Value: f[1]})
env = append(env, corev1.EnvVar{Name: key, Value: value})
}
return env
}
Expand Down
14 changes: 14 additions & 0 deletions internal/model/types/container_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,20 @@ func TestGetEnvVar(t *testing.T) {
{Name: "rc768", Value: "Space Manbow"},
},
},
{
in: &Container{Env: []string{
"NO_EQUALS=123",
"EQUALS_AT_END=456=",
"EQUALS_IN_MIDDLE=abc123=aabbcc",
"MULTIPLE_EQUALS=abc123==aa=bb=cc==",
}},
out: []corev1.EnvVar{
{Name: "NO_EQUALS", Value: "123"},
{Name: "EQUALS_AT_END", Value: "456="},
{Name: "EQUALS_IN_MIDDLE", Value: "abc123=aabbcc"},
{Name: "MULTIPLE_EQUALS", Value: "abc123==aa=bb=cc=="},
},
},
}
for i, tst := range tests {
res := tst.in.GetEnvVar()
Expand Down

0 comments on commit 8ab19d6

Please sign in to comment.