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

[NO TESTS NEEDED] Allow podman play kube to read yaml file from stdin #9420

Merged
merged 1 commit into from
Feb 22, 2021
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
9 changes: 7 additions & 2 deletions cmd/podman/play/kube.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ var (
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.`

kubeCmd = &cobra.Command{
Use: "kube [options] KUBEFILE",
Use: "kube [options] KUBEFILE|-",
Short: "Play a pod based on Kubernetes YAML.",
Long: kubeDescription,
RunE: kube,
Args: cobra.ExactArgs(1),
ValidArgsFunction: common.AutocompleteDefaultOneArg,
Example: `podman play kube nginx.yml
cat nginx.yml | podman play kube -
Copy link
Member

Choose a reason for hiding this comment

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

great example!

podman play kube --creds user:password --seccomp-profile-root /custom/path apache.yml`,
}
)
Expand Down Expand Up @@ -119,7 +120,11 @@ func kube(cmd *cobra.Command, args []string) error {
kubeOptions.Password = creds.Password
}

report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), args[0], kubeOptions.PlayKubeOptions)
yamlfile := args[0]
if yamlfile == "-" {
yamlfile = "/dev/stdin"
}
report, err := registry.ContainerEngine().PlayKube(registry.GetContext(), yamlfile, kubeOptions.PlayKubeOptions)
if err != nil {
return err
}
Expand Down
12 changes: 8 additions & 4 deletions docs/source/markdown/podman-play-kube.1.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@
podman-play-kube - Create pods and containers based on Kubernetes YAML

## SYNOPSIS
**podman play kube** [*options*] *file*__.yml__
**podman play kube** [*options*] *file.yml|-*
Copy link
Member

Choose a reason for hiding this comment

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

IDK, but I think we want to keep the underscores?

Copy link
Member

Choose a reason for hiding this comment

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

OOOPS, I'll trust @edsantiago's earlier comment.


## DESCRIPTION
**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.
**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.

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

Expand Down Expand Up @@ -82,6 +80,12 @@ $ podman play kube demo.yml
52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6
```

Recreate the pod and containers as described in a file `demo.yml` sent to stdin
```
$ cat demo.yml | podman play kube -
52182811df2b1e73f36476003a66ec872101ea59034ac0d4d3a7b40903b955a6
```

Provide `configmap-foo.yml` and `configmap-bar.yml` as sources for environment variables within the containers.
```
$ podman play kube demo.yml --configmap configmap-foo.yml,configmap-bar.yml
Expand Down
29 changes: 23 additions & 6 deletions test/e2e/test.yaml → test/system/700-play.bats
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
# Save the output of this file and use kubectl create -f to import
# it into Kubernetes.
#!/usr/bin/env bats -*- bats -*-
#
# Created with podman-1.6.2
# Test podman play
#

load helpers

testYaml="
apiVersion: v1
kind: Pod
metadata:
labels:
app: test
name: test
name: test_pod
spec:
containers:
- command:
Expand All @@ -20,7 +24,7 @@ spec:
value: xterm
- name: container
value: podman
image: docker.io/library/fedora:latest
image: quay.io/libpod/alpine:latest
name: test
resources: {}
securityContext:
Expand All @@ -31,7 +35,20 @@ spec:
capabilities: {}
privileged: false
seLinuxOptions:
level: "s0:c1,c2"
level: "s0:c1,c2"
readOnlyRootFilesystem: false
workingDir: /
status: {}
"

@test "podman play with stdin" {
echo "$testYaml" > $PODMAN_TMPDIR/test.yaml
run_podman play kube - < $PODMAN_TMPDIR/test.yaml
run_podman pod rm -f test_pod
}

@test "podman play" {
echo "$testYaml" > $PODMAN_TMPDIR/test.yaml
run_podman play kube $PODMAN_TMPDIR/test.yaml
run_podman pod rm -f test_pod
}