diff --git a/cmd/podman/kube/play.go b/cmd/podman/kube/play.go index 663c89de21..77ffd009a8 100644 --- a/cmd/podman/kube/play.go +++ b/cmd/podman/kube/play.go @@ -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") @@ -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)") diff --git a/pkg/bindings/kube/kube.go b/pkg/bindings/kube/kube.go index 731a35ed00..fefbe1a2f5 100644 --- a/pkg/bindings/kube/kube.go +++ b/pkg/bindings/kube/kube.go @@ -1,6 +1,7 @@ package kube import ( + "bytes" "context" "io" "net/http" @@ -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 diff --git a/test/e2e/play_kube_test.go b/test/e2e/play_kube_test.go index 563e9f5cfc..7d4077a2fc 100644 --- a/test/e2e/play_kube_test.go +++ b/test/e2e/play_kube_test.go @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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) @@ -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"), @@ -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")) diff --git a/test/system/700-play.bats b/test/system/700-play.bats index ad1e0ba646..6c686ac597 100644 --- a/test/system/700-play.bats +++ b/test/system/700-play.bats @@ -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 " ---