mirror of
https://github.com/containers/podman.git
synced 2025-05-22 01:27:07 +08:00
Merge pull request #18005 from umohnani8/configmap
Add --configmap to podman-remote kube play
This commit is contained in:
@ -161,6 +161,10 @@ func playFlags(cmd *cobra.Command) {
|
|||||||
waitFlagName := "wait"
|
waitFlagName := "wait"
|
||||||
flags.BoolVarP(&playOptions.Wait, waitFlagName, "w", false, "Clean up all objects created when a SIGTERM is received or pods exit")
|
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() {
|
if !registry.IsRemote() {
|
||||||
certDirFlagName := "cert-dir"
|
certDirFlagName := "cert-dir"
|
||||||
flags.StringVar(&playOptions.CertDir, certDirFlagName, "", "`Pathname` of a directory containing TLS certificates and keys")
|
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")
|
flags.StringVar(&playOptions.SeccompProfileRoot, seccompProfileRootFlagName, defaultSeccompRoot, "Directory path for seccomp profiles")
|
||||||
_ = cmd.RegisterFlagCompletionFunc(seccompProfileRootFlagName, completion.AutocompleteDefault)
|
_ = 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"
|
buildFlagName := "build"
|
||||||
flags.BoolVar(&playOptions.BuildCLI, buildFlagName, false, "Build all images in a YAML (given Containerfiles exist)")
|
flags.BoolVar(&playOptions.BuildCLI, buildFlagName, false, "Build all images in a YAML (given Containerfiles exist)")
|
||||||
|
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package kube
|
package kube
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -49,6 +50,26 @@ func PlayWithBody(ctx context.Context, body io.Reader, options *PlayOptions) (*e
|
|||||||
params.Set("start", strconv.FormatBool(options.GetStart()))
|
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())
|
header, err := auth.MakeXRegistryAuthHeader(&types.SystemContext{AuthFilePath: options.GetAuthfile()}, options.GetUsername(), options.GetPassword())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
@ -2386,7 +2386,6 @@ var _ = Describe("Podman play kube", func() {
|
|||||||
})
|
})
|
||||||
|
|
||||||
It("podman play kube test env value from configmap", 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")
|
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
|
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
|
||||||
err := generateKubeYaml("configmap", cm, cmYamlPathname)
|
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() {
|
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")
|
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
|
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
|
||||||
err := generateKubeYaml("configmap", cm, cmYamlPathname)
|
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() {
|
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")
|
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
|
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
|
||||||
err := generateKubeYaml("configmap", cm, cmYamlPathname)
|
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() {
|
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")
|
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
|
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "foo"))
|
||||||
err := generateKubeYaml("configmap", cm, cmYamlPathname)
|
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() {
|
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")
|
cmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO1", "foo1"), withConfigMapData("FOO2", "foo2"))
|
cm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO1", "foo1"), withConfigMapData("FOO2", "foo2"))
|
||||||
err := generateKubeYaml("configmap", cm, cmYamlPathname)
|
err := generateKubeYaml("configmap", cm, cmYamlPathname)
|
||||||
@ -4408,8 +4403,6 @@ ENV OPENJ9_JAVA_OPTIONS=%q
|
|||||||
|
|
||||||
Context("with configmap in multi-doc yaml and files", func() {
|
Context("with configmap in multi-doc yaml and files", func() {
|
||||||
It("podman play kube uses env values from both sources", 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")
|
fsCmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
fsCm := getConfigMap(withConfigMapName("fooFs"), withConfigMapData("FOO_FS", "fooFS"))
|
fsCm := getConfigMap(withConfigMapName("fooFs"), withConfigMapData("FOO_FS", "fooFS"))
|
||||||
err := generateKubeYaml("configmap", fsCm, fsCmYamlPathname)
|
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() {
|
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")
|
fsCmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
fsCm := getConfigMap(withConfigMapName("fooFs"),
|
fsCm := getConfigMap(withConfigMapName("fooFs"),
|
||||||
withConfigMapData("FOO_FS_1", "fooFS1"),
|
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() {
|
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")
|
fsCmYamlPathname := filepath.Join(podmanTest.TempDir, "foo-cm.yaml")
|
||||||
fsCm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "fooFS"))
|
fsCm := getConfigMap(withConfigMapName("foo"), withConfigMapData("FOO", "fooFS"))
|
||||||
|
@ -653,8 +653,6 @@ spec:
|
|||||||
}
|
}
|
||||||
|
|
||||||
@test "podman kube play with configmaps" {
|
@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
|
configmap_file=${PODMAN_TMPDIR}/play_kube_configmap_configmaps$(random_string 6).yaml
|
||||||
echo "
|
echo "
|
||||||
---
|
---
|
||||||
|
Reference in New Issue
Block a user