Merge pull request #18005 from umohnani8/configmap

Add --configmap to podman-remote kube play
This commit is contained in:
OpenShift Merge Robot
2023-05-18 11:03:04 -04:00
committed by GitHub
4 changed files with 27 additions and 16 deletions

View File

@ -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)")

View File

@ -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

View File

@ -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"))

View File

@ -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 "
---