Merge pull request #2019 from baude/kubeserviceinline

generate service object inline
This commit is contained in:
OpenShift Merge Robot
2018-12-18 12:13:59 -08:00
committed by GitHub
2 changed files with 64 additions and 25 deletions

View File

@ -17,7 +17,7 @@ var (
containerKubeFlags = []cli.Flag{ containerKubeFlags = []cli.Flag{
cli.BoolFlag{ cli.BoolFlag{
Name: "service, s", Name: "service, s",
Usage: "only generate YAML for kubernetes service object", Usage: "generate YAML for kubernetes service object",
}, },
} }
containerKubeDescription = "Generate Kubernetes Pod YAML" containerKubeDescription = "Generate Kubernetes Pod YAML"
@ -36,13 +36,14 @@ var (
// generateKubeYAMLCmdgenerates or replays kube // generateKubeYAMLCmdgenerates or replays kube
func generateKubeYAMLCmd(c *cli.Context) error { func generateKubeYAMLCmd(c *cli.Context) error {
var ( var (
podYAML *v1.Pod podYAML *v1.Pod
container *libpod.Container container *libpod.Container
err error err error
output []byte output []byte
pod *libpod.Pod pod *libpod.Pod
mashalledBytes []byte marshalledPod []byte
servicePorts []v1.ServicePort marshalledService []byte
servicePorts []v1.ServicePort
) )
if rootless.IsRootless() { if rootless.IsRootless() {
@ -79,11 +80,13 @@ func generateKubeYAMLCmd(c *cli.Context) error {
if c.Bool("service") { if c.Bool("service") {
serviceYAML := libpod.GenerateKubeServiceFromV1Pod(podYAML, servicePorts) serviceYAML := libpod.GenerateKubeServiceFromV1Pod(podYAML, servicePorts)
mashalledBytes, err = yaml.Marshal(serviceYAML) marshalledService, err = yaml.Marshal(serviceYAML)
} else { if err != nil {
// Marshall the results return err
mashalledBytes, err = yaml.Marshal(podYAML) }
} }
// Marshall the results
marshalledPod, err = yaml.Marshal(podYAML)
if err != nil { if err != nil {
return err return err
} }
@ -96,7 +99,11 @@ func generateKubeYAMLCmd(c *cli.Context) error {
# Created with podman-%s # Created with podman-%s
` `
output = append(output, []byte(fmt.Sprintf(header, podmanVersion.Version))...) output = append(output, []byte(fmt.Sprintf(header, podmanVersion.Version))...)
output = append(output, mashalledBytes...) output = append(output, marshalledPod...)
if c.Bool("service") {
output = append(output, []byte("---\n")...)
output = append(output, marshalledService...)
}
// Output the v1.Pod with the v1.Container // Output the v1.Pod with the v1.Container
fmt.Println(string(output)) fmt.Println(string(output))

View File

@ -22,7 +22,7 @@ random port is assigned by Podman in the specification.
# OPTIONS: # OPTIONS:
**s** **--service** **s** **--service**
Generate a service file for the resulting Pod YAML. Generate a Kubernetes service object in addition to the Pods.
## Examples ## ## Examples ##
@ -82,31 +82,63 @@ spec:
status: {} status: {}
``` ```
Create Kubernetes service YAML for a container called `some-mariabdb` Create Kubernetes Pod YAML for a pod called `demoweb` and include a service.
``` ```
$ sudo podman generate kube -s some-mariadb $ sudo podman generate kube -s demoweb
# Generation of Kubenetes YAML is still under development! # Generation of Kubernetes YAML is still under development!
# #
# Save the output of this file and use kubectl create -f to import # Save the output of this file and use kubectl create -f to import
# it into Kubernetes. # it into Kubernetes.
# #
# Created with podman-0.11.2-dev # Created with podman-0.12.2-dev
apiVersion: v1
kind: Pod
metadata:
creationTimestamp: 2018-12-18T15:16:06Z
labels:
app: demoweb
name: demoweb-libpod
spec:
containers:
- command:
- python3
- /root/code/graph.py
env:
- name: PATH
value: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
- name: TERM
value: xterm
- name: HOSTNAME
- name: container
value: podman
image: quay.io/baude/demoweb:latest
name: practicalarchimedes
resources: {}
securityContext:
allowPrivilegeEscalation: true
capabilities: {}
privileged: false
readOnlyRootFilesystem: false
tty: true
workingDir: /root/code
status: {}
---
apiVersion: v1 apiVersion: v1
kind: Service kind: Service
metadata: metadata:
creationTimestamp: 2018-12-03T19:08:24Z creationTimestamp: 2018-12-18T15:16:06Z
labels: labels:
app: some-mariadb app: demoweb
name: some-mariadb-libpod name: demoweb-libpod
spec: spec:
ports: ports:
- name: "3306" - name: "8050"
nodePort: 30929 nodePort: 31269
port: 3306 port: 8050
protocol: TCP protocol: TCP
targetPort: 0 targetPort: 0
selector: selector:
app: some-mariadb app: demoweb
type: NodePort type: NodePort
status: status:
loadBalancer: {} loadBalancer: {}