Skip to content

Commit 6fbf73e

Browse files
Merge pull request #9420 from rhatdan/kube
[NO TESTS NEEDED] Allow podman play kube to read yaml file from stdin
2 parents 5da7c69 + f06dd45 commit 6fbf73e

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

cmd/podman/play/kube.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,14 @@ var (
3535
It creates the pod and containers described in the YAML. The containers within the pod are then started and the ID of the new Pod is output.`
3636

3737
kubeCmd = &cobra.Command{
38-
Use: "kube [options] KUBEFILE",
38+
Use: "kube [options] KUBEFILE|-",
3939
Short: "Play a pod based on Kubernetes YAML.",
4040
Long: kubeDescription,
4141
RunE: kube,
4242
Args: cobra.ExactArgs(1),
4343
ValidArgsFunction: common.AutocompleteDefaultOneArg,
4444
Example: `podman play kube nginx.yml
45+
cat nginx.yml | podman play kube -
4546
podman play kube --creds user:password --seccomp-profile-root /custom/path apache.yml`,
4647
}
4748
)
@@ -119,7 +120,11 @@ func kube(cmd *cobra.Command, args []string) error {
119120
kubeOptions.Password = creds.Password
120121
}
121122

122-
report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), args[0], kubeOptions.PlayKubeOptions)
123+
yamlfile := args[0]
124+
if yamlfile == "-" {
125+
yamlfile = "/dev/stdin"
126+
}
127+
report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), yamlfile, kubeOptions.PlayKubeOptions)
123128
if err != nil {
124129
return err
125130
}

docs/source/markdown/podman-play-kube.1.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
podman-play-kube - Create pods and containers based on Kubernetes YAML
55

66
## SYNOPSIS
7-
**podman play kube** [*options*] *file*__.yml__
7+
**podman play kube** [*options*] *file.yml|-*
88

99
## DESCRIPTION
10-
**podman play kube** will read in a structured file of Kubernetes YAML. It will then recreate
11-
the pod and containers described in the YAML. The containers within the pod are then started and
12-
the ID of the new Pod is output.
10+
**podman play kube** will read in a structured file of Kubernetes YAML. It will then recreate the pod and containers described in the YAML. The containers within the pod are then started and the ID of the new Pod is output. If the yaml file is specified as "-" then `podman play kube` with read the yaml file from stdin.
1311

1412
Ideally the input file would be one created by Podman (see podman-generate-kube(1)). This would guarantee a smooth import and expected results.
1513

@@ -82,6 +80,12 @@ $ podman play kube demo.yml
8280
52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6
8381
```
8482

83+
Recreate the pod and containers as described in a file `demo.yml` sent to stdin
84+
```
85+
$ cat demo.yml | podman play kube -
86+
52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6
87+
```
88+
8589
Provide `configmap-foo.yml` and `configmap-bar.yml` as sources for environment variables within the containers.
8690
```
8791
$ podman play kube demo.yml --configmap configmap-foo.yml,configmap-bar.yml

test/e2e/test.yaml renamed to test/system/700-play.bats

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
1-
# Save the output of this file and use kubectl create -f to import
2-
# it into Kubernetes.
1+
#!/usr/bin/env bats -*- bats -*-
32
#
4-
# Created with podman-1.6.2
3+
# Test podman play
4+
#
5+
6+
load helpers
7+
8+
testYaml="
59
apiVersion: v1
610
kind: Pod
711
metadata:
812
labels:
913
app: test
10-
name: test
14+
name: test_pod
1115
spec:
1216
containers:
1317
- command:
@@ -20,7 +24,7 @@ spec:
2024
value: xterm
2125
- name: container
2226
value: podman
23-
image: docker.io/library/fedora:latest
27+
image: quay.io/libpod/alpine:latest
2428
name: test
2529
resources: {}
2630
securityContext:
@@ -31,7 +35,20 @@ spec:
3135
capabilities: {}
3236
privileged: false
3337
seLinuxOptions:
34-
level: "s0:c1,c2"
38+
level: "s0:c1,c2"
3539
readOnlyRootFilesystem: false
3640
workingDir: /
3741
status: {}
42+
"
43+
44+
@test "podman play with stdin" {
45+
echo "$testYaml" > $PODMAN_TMPDIR/test.yaml
46+
run_podman play kube - < $PODMAN_TMPDIR/test.yaml
47+
run_podman pod rm -f test_pod
48+
}
49+
50+
@test "podman play" {
51+
echo "$testYaml" > $PODMAN_TMPDIR/test.yaml
52+
run_podman play kube $PODMAN_TMPDIR/test.yaml
53+
run_podman pod rm -f test_pod
54+
}

0 commit comments

Comments
 (0)