summaryrefslogtreecommitdiff
path: root/cmd/podman/shared
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2019-04-12 11:03:20 -0700
committerGitHub <noreply@github.com>2019-04-12 11:03:20 -0700
commit89ffcf9df9d83bc8e0ea7c8004591fb0825117cf (patch)
treee6e12ffa729da39447fd673bd2141ede12a26fb3 /cmd/podman/shared
parent61fa40b25679f864db5b5b375d512a9f1264e31f (diff)
parent80b2c097fe333fd43634753b574d4b5bdf155b82 (diff)
downloadpodman-89ffcf9df9d83bc8e0ea7c8004591fb0825117cf.tar.gz
podman-89ffcf9df9d83bc8e0ea7c8004591fb0825117cf.tar.bz2
podman-89ffcf9df9d83bc8e0ea7c8004591fb0825117cf.zip
Merge pull request #2903 from baude/remotegenkube
podman-remote generate kube
Diffstat (limited to 'cmd/podman/shared')
-rw-r--r--cmd/podman/shared/container.go35
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
+}