diff options
author | baude <bbaude@redhat.com> | 2019-04-07 13:38:58 -0500 |
---|---|---|
committer | baude <bbaude@redhat.com> | 2019-04-12 12:05:09 -0500 |
commit | 80b2c097fe333fd43634753b574d4b5bdf155b82 (patch) | |
tree | bfb3e032c0b6b4e7f08d087fa00d3919cdf62751 /cmd/podman/shared/container.go | |
parent | 4596c39655f7ff5e741adbc97aaa49bb3a9d453e (diff) | |
download | podman-80b2c097fe333fd43634753b574d4b5bdf155b82.tar.gz podman-80b2c097fe333fd43634753b574d4b5bdf155b82.tar.bz2 podman-80b2c097fe333fd43634753b574d4b5bdf155b82.zip |
podman-remote generate kube
Allow the ability to generate kube YAML from the podman remote-client.
Signed-off-by: baude <bbaude@redhat.com>
Diffstat (limited to 'cmd/podman/shared/container.go')
-rw-r--r-- | cmd/podman/shared/container.go | 35 |
1 files changed, 35 insertions, 0 deletions
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 +} |