Skip to content

Commit

Permalink
feat: support environment variables interpolation
Browse files Browse the repository at this point in the history
Signed-off-by: AhmedGrati <[email protected]>
  • Loading branch information
TessaIO committed Dec 28, 2023
1 parent 7dc7cbf commit 17a7127
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/domain/infra/abi/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,10 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, options
return nil, err
}

expandedContent := os.ExpandEnv(string(content))

// split yaml document
documentList, err := splitMultiDocYAML(content)
documentList, err := splitMultiDocYAML([]byte(expandedContent))
if err != nil {
return nil, err
}
Expand Down
27 changes: 27 additions & 0 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1236,6 +1236,17 @@ items:
restartPolicy: Never
`

var podWithEnvVariablesInterpolation = `
apiVersion: v1
kind: Pod
metadata:
name: foo
spec:
containers:
- name: bar
image: ${IMAGE}
`

var (
defaultCtrName = "testCtr"
defaultCtrCmd = []string{"top"}
Expand Down Expand Up @@ -6337,4 +6348,20 @@ spec:
Expect(execArr[len(execArr)-1]).To(Not(ContainSubstring(arr[len(arr)-1])))
})

It("support environment variables interpolation", func() {
os.Setenv("IMAGE", CITEST_IMAGE)

err := writeYaml(podWithEnvVariablesInterpolation, kubeYaml)
Expect(err).ToNot(HaveOccurred())

kube := podmanTest.Podman([]string{"kube", "play", kubeYaml})
kube.WaitWithDefaultTimeout()
Expect(kube).Should(ExitCleanly())

inspect := podmanTest.Podman([]string{"inspect", "foo-bar", "--format", "'{{ .ImageName }}'"})
inspect.WaitWithDefaultTimeout()

imageName := inspect.OutputToString()
Expect(imageName).To(ContainSubstring(CITEST_IMAGE))
})
})

0 comments on commit 17a7127

Please sign in to comment.