From 80b2c097fe333fd43634753b574d4b5bdf155b82 Mon Sep 17 00:00:00 2001 From: baude Date: Sun, 7 Apr 2019 13:38:58 -0500 Subject: podman-remote generate kube Allow the ability to generate kube YAML from the podman remote-client. Signed-off-by: baude --- cmd/podman/shared/container.go | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'cmd/podman/shared') diff --git a/cmd/podman/shared/container.go b/cmd/podman/shared/container.go index 7bef62355..e14276bdf 100644 --- a/cmd/podman/shared/container.go +++ b/cmd/podman/shared/container.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + v1 "k8s.io/api/core/v1" "os" "path/filepath" "regexp" @@ -938,3 +939,37 @@ func envSliceToMap(env []string) map[string]string { } return m } + +// GenerateKube generates kubernetes yaml based on a pod or container +func GenerateKube(name string, service bool, r *libpod.Runtime) (*v1.Pod, *v1.Service, error) { + var ( + pod *libpod.Pod + podYAML *v1.Pod + err error + container *libpod.Container + servicePorts []v1.ServicePort + serviceYAML v1.Service + ) + // Get the container in question + container, err = r.LookupContainer(name) + if err != nil { + pod, err = r.LookupPod(name) + if err != nil { + return nil, nil, err + } + podYAML, servicePorts, err = pod.GenerateForKube() + } else { + if len(container.Dependencies()) > 0 { + return nil, nil, errors.Wrapf(libpod.ErrNotImplemented, "containers with dependencies") + } + podYAML, err = container.GenerateForKube() + } + if err != nil { + return nil, nil, err + } + + if service { + serviceYAML = libpod.GenerateKubeServiceFromV1Pod(podYAML, servicePorts) + } + return podYAML, &serviceYAML, nil +} -- cgit v1.2.3-54-g00ecf