diff options
Diffstat (limited to 'cmd/podman')
-rw-r--r-- | cmd/podman/commands.go | 7 | ||||
-rw-r--r-- | cmd/podman/generate.go | 7 | ||||
-rw-r--r-- | cmd/podman/generate_kube.go | 40 | ||||
-rw-r--r-- | cmd/podman/main.go | 1 | ||||
-rw-r--r-- | cmd/podman/shared/container.go | 35 | ||||
-rw-r--r-- | cmd/podman/varlink/io.podman.varlink | 11 |
6 files changed, 58 insertions, 43 deletions
diff --git a/cmd/podman/commands.go b/cmd/podman/commands.go index 9fea1494b..6156fc2f8 100644 --- a/cmd/podman/commands.go +++ b/cmd/podman/commands.go @@ -13,7 +13,6 @@ func getMainCommands() []*cobra.Command { rootCommands := []*cobra.Command{ _commitCommand, _execCommand, - _generateCommand, _playCommand, _loginCommand, _logoutCommand, @@ -71,12 +70,6 @@ func getContainerSubCommands() []*cobra.Command { } } -func getGenerateSubCommands() []*cobra.Command { - return []*cobra.Command{ - _containerKubeCommand, - } -} - // Commands that the local client implements func getPlaySubCommands() []*cobra.Command { return []*cobra.Command{ diff --git a/cmd/podman/generate.go b/cmd/podman/generate.go index 197fd26a6..a0637ecb2 100644 --- a/cmd/podman/generate.go +++ b/cmd/podman/generate.go @@ -14,10 +14,15 @@ var ( Long: generateDescription, RunE: commandRunE(), } + + // Commands that are universally implemented + generateCommands = []*cobra.Command{ + _containerKubeCommand, + } ) func init() { generateCommand.Command = _generateCommand - generateCommand.AddCommand(getGenerateSubCommands()...) + generateCommand.AddCommand(generateCommands...) generateCommand.SetUsageTemplate(UsageTemplate()) } diff --git a/cmd/podman/generate_kube.go b/cmd/podman/generate_kube.go index c58372899..30818403b 100644 --- a/cmd/podman/generate_kube.go +++ b/cmd/podman/generate_kube.go @@ -3,13 +3,11 @@ package main import ( "fmt" "github.com/containers/libpod/cmd/podman/cliconfig" - "github.com/containers/libpod/cmd/podman/libpodruntime" - "github.com/containers/libpod/libpod" + "github.com/containers/libpod/pkg/adapter" podmanVersion "github.com/containers/libpod/version" "github.com/ghodss/yaml" "github.com/pkg/errors" "github.com/spf13/cobra" - "k8s.io/api/core/v1" ) var ( @@ -42,14 +40,12 @@ func init() { func generateKubeYAMLCmd(c *cliconfig.GenerateKubeValues) error { var ( - podYAML *v1.Pod - container *libpod.Container - err error - output []byte - pod *libpod.Pod + //podYAML *v1.Pod + err error + output []byte + //pod *libpod.Pod marshalledPod []byte marshalledService []byte - servicePorts []v1.ServicePort ) args := c.InputArgs @@ -57,43 +53,27 @@ func generateKubeYAMLCmd(c *cliconfig.GenerateKubeValues) error { return errors.Errorf("you must provide exactly one container|pod ID or name") } - runtime, err := libpodruntime.GetRuntime(&c.PodmanCommand) + runtime, err := adapter.GetRuntime(&c.PodmanCommand) if err != nil { return errors.Wrapf(err, "could not get runtime") } defer runtime.Shutdown(false) - // Get the container in question - container, err = runtime.LookupContainer(args[0]) + podYAML, serviceYAML, err := runtime.GenerateKube(c) if err != nil { - pod, err = runtime.LookupPod(args[0]) - if err != nil { - return err - } - podYAML, servicePorts, err = pod.GenerateForKube() - } else { - if len(container.Dependencies()) > 0 { - return errors.Wrapf(libpod.ErrNotImplemented, "containers with dependencies") - } - podYAML, err = container.GenerateForKube() + return err } + // Marshall the results + marshalledPod, err = yaml.Marshal(podYAML) if err != nil { return err } - if c.Service { - serviceYAML := libpod.GenerateKubeServiceFromV1Pod(podYAML, servicePorts) marshalledService, err = yaml.Marshal(serviceYAML) if err != nil { return err } } - // Marshall the results - marshalledPod, err = yaml.Marshal(podYAML) - if err != nil { - return err - } - header := `# Generation of Kubernetes YAML is still under development! # # Save the output of this file and use kubectl create -f to import diff --git a/cmd/podman/main.go b/cmd/podman/main.go index 35a94b3db..e8c3e14ea 100644 --- a/cmd/podman/main.go +++ b/cmd/podman/main.go @@ -36,6 +36,7 @@ var mainCommands = []*cobra.Command{ _createCommand, _eventsCommand, _exportCommand, + _generateCommand, _historyCommand, &_imagesCommand, _importCommand, 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 +} diff --git a/cmd/podman/varlink/io.podman.varlink b/cmd/podman/varlink/io.podman.varlink index c6997cd3f..b5295273a 100644 --- a/cmd/podman/varlink/io.podman.varlink +++ b/cmd/podman/varlink/io.podman.varlink @@ -98,6 +98,11 @@ type ImageSearchFilter ( star_count: int ) +type KubePodService ( + pod: string, + service: string +) + type Container ( id: string, image: string, @@ -1124,11 +1129,7 @@ method ImagesPrune(all: bool) -> (pruned: []string) # GenerateKube generates a Kubernetes v1 Pod description of a Podman container or pod # and its containers. The description is in YAML. See also [ReplayKube](ReplayKube). -# method GenerateKube() -> (notimplemented: NotImplemented) - -# GenerateKubeService generates a Kubernetes v1 Service description of a Podman container or pod -# and its containers. The description is in YAML. See also [GenerateKube](GenerateKube). -# method GenerateKubeService() -> (notimplemented: NotImplemented) +method GenerateKube(name: string, service: bool) -> (pod: KubePodService) # ReplayKube recreates a pod and its containers based on a Kubernetes v1 Pod description (in YAML) # like that created by GenerateKube. See also [GenerateKube](GenerateKube). |