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

Add --configmap to podman-remote kube play #18005

Merged
merged 1 commit into from
May 18, 2023
Merged
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
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")
Copy link
Member

@TomSweeneyRedHat TomSweeneyRedHat May 17, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit, but it probably ought to be "Kubernetes"

Suggested change
flags.StringSliceVar(&playOptions.ConfigMaps, configmapFlagName, []string{}, "`Pathname` of a YAML file containing a kubernetes configmap")
flags.StringSliceVar(&playOptions.ConfigMaps, configmapFlagName, []string{}, "`Pathname` of a YAML file containing a Kubernetes configmap")

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will fix in a follow up PR.

_ = 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")
umohnani8 marked this conversation as resolved.
Show resolved Hide resolved

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"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love, love, love all these removals!


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