Commit Graph

54 Commits

Author SHA1 Message Date
Eduardo Vega 72f4f389f0 Adds support to preserve auto update labels in generate and play kube
In the case of generate kube the auto-update labels will be converted into kube annotations and for play kube they will be converted back to labels since that's what podman understands

Signed-off-by: Eduardo Vega <edvegavalerio@gmail.com>
2021-05-06 21:21:43 -06:00
zhangguanzhang 3bf0fbf6f6 Fixes generate kube incorrect when bind-mounting "/" and "/root"
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
2021-04-26 23:47:39 +08:00
Eduardo Vega 61cb6d61dd Add support for play/generate kube volumes
Signed-off-by: Eduardo Vega <edvegavalerio@gmail.com>
2021-04-09 14:01:13 -06:00
Jordan Williams 1e255b6df9
Generate Kubernetes PersistentVolumeClaims from named volumes
Fixes #5788

This commit adds support for named volumes in podman-generate-kube.
Named volumes are output in the YAML as PersistentVolumeClaims.
To avoid naming conflicts, the volume name is suffixed with "-pvc".
This commit adds a corresponding suffix for host path mounts.
Host path volumes are suffixed with "-host".

Signed-off-by: Jordan Williams <jordan@jwillikers.com>
2021-03-19 13:52:35 -05:00
Paul Holzinger 57e8c66322 Do not leak libpod package into the remote client
Some packages used by the remote client imported the libpod package.
This is not wanted because it adds unnecessary bloat to the client and
also causes problems with platform specific code(linux only), see #9710.

The solution is to move the used functions/variables into extra packages
which do not import libpod.

This change shrinks the remote client size more than 6MB compared to the
current master.

[NO TESTS NEEDED]
I have no idea how to test this properly but with #9710 the cross
compile should fail.

Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
2021-03-15 14:02:04 +01:00
Daniel J Walsh 0e36e65eaa
Allow users to generate a kubernetes yaml off non running containers
Currently if you attempt to create a kube.yaml file off of a non running
container where the container runs as a specific User, the creation
fails because the storage container is not mounted. Podman is supposed to
read the /etc/passwd entry inside of the container but since the
container is not mounted, the c.State.Mountpoint == "".  Podman
incorrectly attempts to read /etc/passwd on the host, and fails if the
specified user is not in the hosts /etc/passwd.

This PR mounts the storage container, if it was not mounted so the read
succeeds.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2021-03-08 06:14:08 -05:00
Valentin Rothberg 5dded6fae7 bump go module to v3
We missed bumping the go module, so let's do it now :)

* Automated go code with github.com/sirkon/go-imports-rename
* Manually via `vgrep podman/v2` the rest

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-22 09:03:51 +01:00
Valentin Rothberg 48c612cf66 generate kube: support --privileged
Do not play with capabilities for privileged containers where all
capabilities will be set implicitly.

Also, avoid the device check when running privileged since all of /dev/*
will be mounted in any case.

Fixes: #8897
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-09 17:40:35 +01:00
Valentin Rothberg c995b54607 generate kube: handle entrypoint
The spec of a Kube Container has a `Command` and `Args`.  While both are
slices, the `Command` is the counterpart of the entrypoint of a libpod
container.  Kube is also happily accepting the arguments to as following
items in the slice but it's cleaner to move those to `Args`.

Fixes: #9211
Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2021-02-04 12:34:35 +01:00
Milivoje Legenovic cdbbc6120b podman generate kube ignores --network=host
Signed-off-by: Milivoje Legenovic <m.legenovic@gmail.com>
2021-01-30 09:08:36 +01:00
baude ca0dd76bf3 Honor custom DNS in play|generate kube
when creating kubernetes yaml from containers and pods, we should honor
any custom dns settings the user provided. in the case of generate kube,
these would be provided by --dns, --dns-search, and --dns-opt. if
multiple containers are involved in the generate, the options will be
cumulative and unique with the exception of dns-opt.

when replaying a kube file that has kubernetes dns information, we now
also add that information to the pod creation.

the options for dnspolicy is not enabled as there seemed to be no direct
correlation between kubernetes and podman.

Fixes: #9132

Signed-off-by: baude <bbaude@redhat.com>
2021-01-29 08:49:45 -06:00
Josh Soref 4fa1fce930 Spelling
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com>
2020-12-22 13:34:31 -05:00
baude 749ee2a10e generate kube on multiple containers
add the ability to add multiple containers into a single k8s pod
instead of just one.

also fixed some bugs in the resulting yaml where an empty service
description was being added on error causing the k8s validation to fail.

Signed-off-by: baude <bbaude@redhat.com>
2020-12-07 11:34:39 -06:00
Jordan Christiansen 0357964906 Centralize cores and period/quota conversion code
Signed-off-by: Jordan Christiansen <xordspar0@gmail.com>
2020-10-31 10:07:11 -05:00
Andy Librian 34a33d614e
Add support for resource cpu limit to generate kube
fixes #7855

Signed-off-by: Andy Librian <andylibrian@gmail.com>
2020-10-09 05:54:16 +07:00
Andy Librian 62607e7f27
Add TODO for adding CPU limit support
Signed-off-by: Andy Librian <andylibrian@gmail.com>
2020-10-05 12:50:39 +07:00
Andy Librian d6258eb6c2
Add support for resource memory limit to generate kube
addresses #7855

Signed-off-by: Andy Librian <andylibrian@gmail.com>
2020-10-04 21:17:00 +07:00
zhangguanzhang f0ccac199b handle the play kube and generate kube for with restartPolicy
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
2020-09-18 13:28:22 +08:00
OpenShift Merge Robot d1798d0383
Merge pull request #7591 from haircommander/play-kube-process-namespace
play/generate: support shareProcessNamespace
2020-09-11 05:56:35 -04:00
Peter Hunt b80b95eea0 play/generate: support shareProcessNamespace
this is an option that allows a user to specify whether to share PID namespace in the pod
for play kube and generate kube

associated test added

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2020-09-10 17:22:55 -04:00
Parker Van Roy aaf18e0cbe allowed underscores to remain in name for YAML
Signed-off-by: Parker Van Roy <pvanroy@redhat.com>
2020-09-10 15:27:11 -04:00
zhangguanzhang a2bb7bd36b fix podman generate kube with HostAliases
Signed-off-by: zhangguanzhang <zhangguanzhang@qq.com>
2020-08-27 17:32:51 +08:00
Daniel J Walsh a5e37ad280
Switch all references to github.com/containers/libpod -> podman
Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-07-28 08:23:45 -04:00
Valentin Rothberg 8489dc4345 move go module to v2
With the advent of Podman 2.0.0 we crossed the magical barrier of go
modules.  While we were able to continue importing all packages inside
of the project, the project could not be vendored anymore from the
outside.

Move the go module to new major version and change all imports to
`github.com/containers/libpod/v2`.  The renaming of the imports
was done via `gomove` [1].

[1] https://github.com/KSubedi/gomove

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-07-06 15:50:12 +02:00
Daniel J Walsh 200cfa41a4
Turn on More linters
- misspell
    - prealloc
    - unparam
    - nakedret

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-06-15 07:05:56 -04:00
Valentin Rothberg f269be3a31 add {generate,play} kube
Add the `podman generate kube` and `podman play kube` command.  The code
has largely been copied from Podman v1 but restructured to not leak the
K8s core API into the (remote) client.

Both commands are added in the same commit to allow for enabling the
tests at the same time.

Move some exports from `cmd/podman/common` to the appropriate places in
the backend to avoid circular dependencies.

Move definitions of label annotations to `libpod/define` and set the
security-opt labels in the frontend to make kube tests pass.

Implement rest endpoints, bindings and the tunnel interface.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-05-06 17:08:22 +02:00
Qi Wang 17bab33bd2 fix security-opt generate kube
fix #4950
add selinux options from --security-opt of the container to generate kube result

Signed-off-by: Qi Wang <qiwan@redhat.com>
2020-03-03 11:21:14 -05:00
OpenShift Merge Robot 796ae87b1a
Merge pull request #4850 from vrothberg/fix-linting
Fix linting
2020-01-13 21:03:21 +01:00
Valentin Rothberg 67165b7675 make lint: enable gocritic
`gocritic` is a powerful linter that helps in preventing certain kinds
of errors as well as enforcing a coding style.

Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
2020-01-13 14:27:02 +01:00
Daniel J Walsh 4093b2c011
Add codespell to validate spelling mistakes in code.
Fix all errors found by codespell

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2020-01-11 06:32:19 -05:00
Dmitry Smirnov 8d928d525f codespell: spelling corrections
Signed-off-by: Dmitry Smirnov <onlyjob@member.fsf.org>
2019-11-13 08:15:00 +11:00
Daniel J Walsh a6108f1c19
Add support for RunAsUser and RunAsGroup
Currently podman generate kube does not generate the correct RunAsUser and RunAsGroup
options in the yaml file.  This patch fixes this.

This patch also make `podman play kube` use the RunAdUser and RunAsGroup options if
they are specified in the yaml file.

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
2019-11-06 10:35:37 -05:00
Peter Hunt 834107c82e Add capability functionality to play kube
Take capabilities written in a kube and add to a container
adapt test suite and write cap-add/drop tests

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-08-01 15:47:45 -04:00
Peter Hunt 3acfcb3062 Deduplicate capabilities in generate kube
capabilities that were added and dropped were several times duplicated. Fix this

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-08-01 14:12:36 -04:00
baude db826d5d75 golangci-lint round #3
this is the third round of preparing to use the golangci-lint on our
code base.

Signed-off-by: baude <bbaude@redhat.com>
2019-07-21 14:22:39 -05:00
baude a78c885397 golangci-lint pass number 2
clean up and prepare to migrate to the golangci-linter

Signed-off-by: baude <bbaude@redhat.com>
2019-07-11 09:13:06 -05:00
baude 1d36501f96 code cleanup
clean up code identified as problematic by golands inspection

Signed-off-by: baude <bbaude@redhat.com>
2019-07-08 09:18:11 -05:00
Peter Hunt aeabc45cce Improve parsing of mounts
Specifically, we were needlessly doing a double lookup to find which config mounts were user volumes. Improve this by refactoring a bit of code from inspect

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-07-02 15:18:44 -04:00
Peter Hunt db2cc36033 Deduplicate volumes
for containers that share volumes, so the pod section doesn't list copies

Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-07-02 14:08:09 -04:00
Peter Hunt aa9de67452 Pass along volumes to pod yaml
Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-07-01 16:58:53 -04:00
Peter Hunt 1307e96d5e Configure container volumes for generate kube
Signed-off-by: Peter Hunt <pehunt@redhat.com>
2019-07-01 16:07:25 -04:00
OpenShift Merge Robot c9078936dd
Merge pull request #3419 from baude/removelibpodfrommainphase1
remove libpod from main
2019-06-26 02:36:06 +02:00
baude dd81a44ccf remove libpod from main
the compilation demands of having libpod in main is a burden for the
remote client compilations.  to combat this, we should move the use of
libpod structs, vars, constants, and functions into the adapter code
where it will only be compiled by the local client.

this should result in cleaner code organization and smaller binaries. it
should also help if we ever need to compile the remote client on
non-Linux operating systems natively (not cross-compiled).

Signed-off-by: baude <bbaude@redhat.com>
2019-06-25 13:51:24 -05:00
Matthew Heon ebf48ff459 Only include ports in one container in Kube YAML
This likely broke when we made containers able to detect that
they shared a network namespace and grab ports from the
dependency container - prior to that, we could grab ports without
concern for conflict, only the infra container had them. Now, all
containers in a pod will return the same ports, so we have to
work around this.

Fixes #3408

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-06-24 14:27:47 -04:00
Matthew Heon 968bcbc86b Remove unused return statement in kube volume code
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-05-21 23:08:39 -04:00
Matthew Heon 03824e04fd Fix a 'generate kube' bug on ctrs with named volumes
Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-05-21 13:52:55 -04:00
Matthew Heon f7951c8776 Use GetContainer instead of LookupContainer for full ID
All IDs in libpod are stored as a full container ID. We can get a
container by full ID faster with GetContainer (which directly
retrieves) than LookupContainer (which finds a match, then
retrieves). No reason to use Lookup when we have full IDs present
and available.

Signed-off-by: Matthew Heon <matthew.heon@pm.me>
2019-04-12 10:59:00 -04:00
baude dd74467fd8 show container ports of network namespace
in cases where a container is part of a network namespace, we should
show the network namespace's ports when dealing with ports. this
impacts ps, kube, and port.

fixes: #846

Signed-off-by: baude <bbaude@redhat.com>
2019-02-13 13:51:23 -06:00
baude 440dd8c2ed lock and sync container before checking mountpoint
when checking for a container's mountpoint, you must lock and sync
the container or the result may be "".

Fixes: #2304

Signed-off-by: baude <bbaude@redhat.com>
2019-02-11 09:20:30 -06:00
baude 9b03cacc87 Add Play
podman play kube adds the ability for the user to recreate pods and containers
from a Kubernetes YAML file in libpod.

Signed-off-by: baude <bbaude@redhat.com>
2018-12-19 14:20:55 -06:00