Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support environment variables interpolation #21098

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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))
})
})