Skip to content

Commit

Permalink
Merge pull request containers#18005 from umohnani8/configmap
Browse files Browse the repository at this point in the history
Add --configmap to podman-remote kube play
  • Loading branch information
openshift-merge-robot authored May 18, 2023
2 parents abea786 + 5ff6fc5 commit a58ea23
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
8 changes: 4 additions & 4 deletions cmd/podman/kube/play.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,10 @@ func playFlags(cmd *cobra.Command) {
waitFlagName := "wait"
flags.BoolVarP(&playOptions.Wait, waitFlagName, "w", false, "Clean up all objects created when a SIGTERM is received or pods exit")

configmapFlagName := "configmap"
flags.StringSliceVar(&playOptions.ConfigMaps, configmapFlagName, []string{}, "`Pathname` of a YAML file containing a kubernetes configmap")
_ = cmd.RegisterFlagCompletionFunc(configmapFlagName, completion.AutocompleteDefault)

if !registry.IsRemote() {
certDirFlagName := "cert-dir"
flags.StringVar(&playOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys")
Expand All @@ -170,10 +174,6 @@ func playFlags(cmd *cobra.Command) {
flags.StringVar(&playOptions.SeccompProfileRoot, seccompProfileRootFlagName, defaultSeccompRoot, "Directory path for seccomp profiles")
_ = cmd.RegisterFlagCompletionFunc(seccompProfileRootFlagName, completion.AutocompleteDefault)

configmapFlagName := "configmap"
flags.StringSliceVar(&playOptions.ConfigMaps, configmapFlagName, []string{}, "`Pathname` of a YAML file containing a kubernetes configmap")
_ = cmd.RegisterFlagCompletionFunc(configmapFlagName, completion.AutocompleteDefault)

buildFlagName := "build"
flags.BoolVar(&playOptions.BuildCLI, buildFlagName, false, "Build all images in a YAML (given Containerfiles exist)")

Expand Down
21 changes: 21 additions & 0 deletions pkg/bindings/kube/kube.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package kube

import (
"bytes"
"context"
"io"
"net/http"
Expand Down Expand Up @@ -49,6 +50,26 @@ func PlayWithBody(ctx context.Context, body io.Reader, options *PlayOptions) (*e
params.Set("start", strconv.FormatBool(options.GetStart()))
}

// For the remote case, read any configMaps passed and append it to the main yaml content
if options.ConfigMaps != nil {
yamlBytes, err := io.ReadAll(body)
if err != nil {
return nil, err
}

for _, cm := range *options.ConfigMaps {
// Add kube yaml splitter
yamlBytes = append(yamlBytes, []byte("---\n")...)
cmBytes, err := os.ReadFile(cm)
if err != nil {
return nil, err
}
cmBytes = append(cmBytes, []byte("\n")...)
yamlBytes = append(yamlBytes, cmBytes...)
}
body = io.NopCloser(bytes.NewReader(yamlBytes))
}

header, err := auth.MakeXRegistryAuthHeader(&types.SystemContext{AuthFilePath: options.GetAuthfile()}, options.GetUsername(), options.GetPassword())
if err != nil {
return nil, err
Expand Down
12 changes: 2 additions & 10 deletions test/e2e/play_kube_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2386,7 +2386,6 @@ var _ = Describe("Podman play kube", func() {
})

It("podman play kube test env value from configmap", func() {
SkipIfRemote("configmap list is not supported as a param")
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
err := generateKubeYaml("configmap", cm, cmYamlPathname)
Expand All @@ -2407,7 +2406,6 @@ var _ = Describe("Podman play kube", func() {
})

It("podman play kube test env value from configmap and --replace should reuse the configmap volume", func() {
SkipIfRemote("configmap list is not supported as a param")
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
err := generateKubeYaml("configmap", cm, cmYamlPathname)
Expand All @@ -2433,7 +2431,6 @@ var _ = Describe("Podman play kube", func() {
})

It("podman play kube test required env value from configmap with missing key", func() {
SkipIfRemote("configmap list is not supported as a param")
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
err := generateKubeYaml("configmap", cm, cmYamlPathname)
Expand All @@ -2459,7 +2456,6 @@ var _ = Describe("Podman play kube", func() {
})

It("podman play kube test optional env value from configmap with missing key", func() {
SkipIfRemote("configmap list is not supported as a param")
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
err := generateKubeYaml("configmap", cm, cmYamlPathname)
Expand Down Expand Up @@ -2495,7 +2491,6 @@ var _ = Describe("Podman play kube", func() {
})

It("podman play kube test get all key-value pairs from configmap as envs", func() {
SkipIfRemote("configmap list is not supported as a param")
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO1", "foo1"), withConfigMapData("FOO2", "foo2"))
err := generateKubeYaml("configmap", cm, cmYamlPathname)
Expand Down Expand Up @@ -4408,8 +4403,6 @@ ENV OPENJ9_JAVA_OPTIONS=%q

Context("with configmap in multi-doc yaml and files", func() {
It("podman play kube uses env values from both sources", func() {
SkipIfRemote("--configmaps is not supported for remote")

fsCmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
fsCm := getConfigMap(withConfigMapName("fooFs"), withConfigMapData("FOO_FS", "fooFS"))
err := generateKubeYaml("configmap", fsCm, fsCmYamlPathname)
Expand Down Expand Up @@ -4446,8 +4439,6 @@ ENV OPENJ9_JAVA_OPTIONS=%q
})

It("podman play kube uses all env values from both sources", func() {
SkipIfRemote("--configmaps is not supported for remote")

fsCmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
fsCm := getConfigMap(withConfigMapName("fooFs"),
withConfigMapData("FOO_FS_1", "fooFS1"),
Expand Down Expand Up @@ -4491,7 +4482,8 @@ ENV OPENJ9_JAVA_OPTIONS=%q
})

It("podman play kube reports error when the same configmap name is present in both sources", func() {
SkipIfRemote("--configmaps is not supported for remote")
// We will never hit this error in the remote case as the configmap content is appended to the main yaml content
SkipIfRemote("--configmaps is appended to the main yaml for the remote case")

fsCmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
fsCm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "fooFS"))
Expand Down
2 changes: 0 additions & 2 deletions test/system/700-play.bats
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,6 @@ spec:
}

@test "podman kube play with configmaps" {
skip_if_remote "the configmap argument is supported only locally"

configmap_file=${PODMAN_TMPDIR}/play_kube_configmap_configmaps$(random_string 6).yaml
echo "
---
Expand Down

0 comments on commit a58ea23

Please sign in to comment.