Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Podman play kube adds _pod suffix if container is named like pod. #12722

Closed
hikhvar opened this issue Dec 30, 2021 · 7 comments · Fixed by #12726
Closed

Podman play kube adds _pod suffix if container is named like pod. #12722

hikhvar opened this issue Dec 30, 2021 · 7 comments · Fixed by #12726
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.

Comments

@hikhvar
Copy link
Contributor

hikhvar commented Dec 30, 2021

BUG REPORT

/kind bug

Description

I wanted to create a pod via podman play kube with the name nginx and a single container also named nginx. I got the warning a container exists with the same name ("nginx") as the pod in your YAML file; changing pod name to nginx_pod and the resulting pod had the name nginx_pod. I expected the pod to be named nginx. If I name the pod fancy in the YAML, I get a pod named fancy.
The created containers however are named nginx_pod-nginx and fancy-nginx. There is no container named nginx in my system.

Steps to reproduce the issue:

  1. Create the file pod.yaml:
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
  1. Apply it via podman play kube pod.yaml

Describe the results you received:
I get a pod named nginx_pod:

root@dev-vps:~# podman pod ps 
POD ID        NAME        STATUS      CREATED        INFRA ID      # OF CONTAINERS
8750d3ad45a4  nginx_pod   Running     9 seconds ago  982c66dbd233  2
root@dev-vps:~# podman ps -a
CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS             PORTS       NAMES
982c66dbd233  k8s.gcr.io/pause:3.5                                  13 seconds ago  Up 11 seconds ago              8750d3ad45a4-infra
6ab1519f1e71  docker.io/library/nginx:1.14.2  nginx -g daemon o...  11 seconds ago  Up 11 seconds ago              nginx_pod-nginx

Describe the results you expected:
I expect a pod named nginx and a container named nginx-nginx.

Like in this example:

root@dev-vps:~# cat example-pod.yaml 
apiVersion: v1
kind: Pod
metadata:
  name: fancy
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
root@dev-vps:~# podman play kube example-pod.yaml 
Pod:
c388d9d2d86dde65b75b8e623d5609d728adcf3cbd7ff49274bfee6af246ec7b
Container:
79ea1bb19360b897b42213e61fc5e6e5bd2f07feb8be349bc7e091c52ccc4cee

root@dev-vps:~# podman pod ps
POD ID        NAME        STATUS      CREATED        INFRA ID      # OF CONTAINERS
c388d9d2d86d  fancy       Running     7 seconds ago  8e97b14e4813  2
8750d3ad45a4  nginx_pod   Running     3 minutes ago  982c66dbd233  2
root@dev-vps:~# podman ps -a
CONTAINER ID  IMAGE                           COMMAND               CREATED         STATUS            PORTS       NAMES
982c66dbd233  k8s.gcr.io/pause:3.5                                  3 minutes ago   Up 3 minutes ago              8750d3ad45a4-infra
6ab1519f1e71  docker.io/library/nginx:1.14.2  nginx -g daemon o...  3 minutes ago   Up 3 minutes ago              nginx_pod-nginx
8e97b14e4813  k8s.gcr.io/pause:3.5                                  10 seconds ago  Up 9 seconds ago              c388d9d2d86d-infra
79ea1bb19360  docker.io/library/nginx:1.14.2  nginx -g daemon o...  9 seconds ago   Up 9 seconds ago              fancy-nginx

Additional information you deem important (e.g. issue happens only occasionally):

Output of podman version:

podman version
Version:      3.4.2
API Version:  3.4.2
Go Version:   go1.16.6
Built:        Thu Jan  1 00:00:00 1970
OS/Arch:      linux/amd64

Output of podman info --debug:

podman info --debug
host:
  arch: amd64
  buildahVersion: 1.23.1
  cgroupControllers:
  - cpuset
  - cpu
  - cpuacct
  - blkio
  - memory
  - devices
  - freezer
  - net_cls
  - perf_event
  - net_prio
  - hugetlb
  - pids
  - rdma
  cgroupManager: systemd
  cgroupVersion: v1
  conmon:
    package: 'conmon: /usr/libexec/podman/conmon'
    path: /usr/libexec/podman/conmon
    version: 'conmon version 2.0.30, commit: '
  cpus: 1
  distribution:
    codename: focal
    distribution: ubuntu
    version: "20.04"
  eventLogger: journald
  hostname: dev-vps
  idMappings:
    gidmap: null
    uidmap: null
  kernel: 5.4.0-90-generic
  linkmode: dynamic
  logDriver: journald
  memFree: 160804864
  memTotal: 2033893376
  ociRuntime:
    name: crun
    package: 'crun: /usr/bin/crun'
    path: /usr/bin/crun
    version: |-
      crun version UNKNOWN
      commit: ea1fe3938eefa14eb707f1d22adff4db670645d6
      spec: 1.0.0
      +SYSTEMD +SELINUX +APPARMOR +CAP +SECCOMP +EBPF +CRIU +YAJL
  os: linux
  remoteSocket:
    path: /run/podman/podman.sock
  security:
    apparmorEnabled: true
    capabilities: CAP_CHOWN,CAP_DAC_OVERRIDE,CAP_FOWNER,CAP_FSETID,CAP_KILL,CAP_NET_BIND_SERVICE,CAP_SETFCAP,CAP_SETGID,CAP_SETPCAP,CAP_SETUID,CAP_SYS_CHROOT
    rootless: false
    seccompEnabled: true
    seccompProfilePath: /usr/share/containers/seccomp.json
    selinuxEnabled: false
  serviceIsRemote: false
  slirp4netns:
    executable: /usr/bin/slirp4netns
    package: 'slirp4netns: /usr/bin/slirp4netns'
    version: |-
      slirp4netns version 1.1.8
      commit: unknown
      libslirp: 4.3.1-git
      SLIRP_CONFIG_VERSION_MAX: 3
      libseccomp: 2.4.3
  swapFree: 0
  swapTotal: 0
  uptime: 48m 16.18s
plugins:
  log:
  - k8s-file
  - none
  - journald
  network:
  - bridge
  - macvlan
  volume:
  - local
registries:
  search:
  - docker.io
  - quay.io
store:
  configFile: /etc/containers/storage.conf
  containerStore:
    number: 4
    paused: 0
    running: 4
    stopped: 0
  graphDriverName: overlay
  graphOptions:
    overlay.mountopt: nodev,metacopy=on
  graphRoot: /var/lib/containers/storage
  graphStatus:
    Backing Filesystem: extfs
    Native Overlay Diff: "false"
    Supports d_type: "true"
    Using metacopy: "true"
  imageStore:
    number: 2
  runRoot: /run/containers/storage
  volumePath: /var/lib/containers/storage/volumes
version:
  APIVersion: 3.4.2
  Built: 0
  BuiltTime: Thu Jan  1 00:00:00 1970
  GitCommit: ""
  GoVersion: go1.16.6
  OsArch: linux/amd64
  Version: 3.4.2

Package info (e.g. output of rpm -q podman or apt list podman):

apt list podman
Listing... Done
podman/unknown,now 100:3.4.2-1 amd64 [installed]
podman/unknown 100:3.4.2-1 arm64
podman/unknown 100:3.4.2-1 armhf
podman/unknown 100:3.4.2-1 s390x

Have you tested with the latest version of Podman and have you checked the Podman Troubleshooting Guide? (https://github.com/containers/podman/blob/master/troubleshooting.md)

Yes

@openshift-ci openshift-ci bot added the kind/bug Categorizes issue or PR as related to a bug. label Dec 30, 2021
@mheon
Copy link
Member

mheon commented Dec 30, 2021

This is expected.

Podman maintains the invariant that all pod and container names must be globally unique. This is baked very deep into the code, and while I'd like to change it, it would be a major investment of time and I don't see us doing it for at least a year (and a potential Podman 5.0).

@hikhvar
Copy link
Contributor Author

hikhvar commented Dec 31, 2021

Since the final container name of every container in a pod will be <POD NAME>-<CONTAINER NAME> isn't that invariant already maintained? In general I find that invariant as a user confusing. Why can't I choose the same name for two objects with a different kind?

@rhatdan
Copy link
Member

rhatdan commented Dec 31, 2021

I think @mheon answered your question. But as he says, it is not likely to be fixed for a long time.

@mheon
Copy link
Member

mheon commented Dec 31, 2021

The containers are not named pod name-container name - they are just named by the container name, right now, which is why the pod name must change.

@hikhvar
Copy link
Contributor Author

hikhvar commented Dec 31, 2021

Maybe we are talking about different names. I don't see any container named nginx container before and after podman play kube.

# cat -p /tmp/example.yaml                                                                                                         
apiVersion: v1
kind: Pod
metadata:
  name: nginx
spec:
  containers:
  - name: nginx
    image: nginx:1.14.2
    ports:
    - containerPort: 80
 
# podman ps -a                                                                                                                     
CONTAINER ID  IMAGE       COMMAND     CREATED     STATUS      PORTS       NAMES

# podman play kube /tmp/example.yaml                                                                                              
Pod:
263c448069cc50bdadf943deddcd708258bad65a96494c3e72f88626271f3150
Container:
57e99ef11ffec0f4b4a109535fcaeffa76eb4e33f646a86ed2a843cc3c790349

# podman ps -a                                                                                                              
CONTAINER ID  IMAGE                           COMMAND               CREATED        STATUS            PORTS       NAMES
016c54507100  k8s.gcr.io/pause:3.5                                  6 seconds ago  Up 4 seconds ago              263c448069cc-infra
57e99ef11ffe  docker.io/library/nginx:1.14.2  nginx -g daemon o...  4 seconds ago  Up 4 seconds ago              nginx_pod-nginx

# podman inspect  nginx_pod                                                                                                     
[
    {
        "Id": "263c448069cc50bdadf943deddcd708258bad65a96494c3e72f88626271f3150",
        "Name": "nginx_pod",
        "Created": "2021-12-31T16:19:31.589952885+01:00",
        "State": "Running",
        "Hostname": "nginx_pod",
        "CreateCgroup": false,
        "CgroupParent": "user.slice",
        "CreateInfra": true,
        "InfraContainerID": "016c545071008110ff101a562a4c3a8fd3617e7d887805f115f4173ba4b76000",
        "InfraConfig": {
            "PortBindings": {},
            "HostNetwork": true,
            "StaticIP": "",
            "StaticMAC": "",
            "NoManageResolvConf": false,
            "DNSServer": null,
            "DNSSearch": null,
            "DNSOption": null,
            "NoManageHosts": false,
            "HostAdd": null,
            "Networks": null,
            "NetworkOptions": null,
            "pid_ns": "private",
            "userns": "host"
        },
        "SharedNamespaces": [
            "uts",
            "ipc",
            "net"
        ],
        "NumContainers": 2,
        "Containers": [
            {
                "Id": "016c545071008110ff101a562a4c3a8fd3617e7d887805f115f4173ba4b76000",
                "Name": "263c448069cc-infra",
                "State": "running"
            },
            {
                "Id": "57e99ef11ffec0f4b4a109535fcaeffa76eb4e33f646a86ed2a843cc3c790349",
                "Name": "nginx_pod-nginx",
                "State": "running"
            }
        ]
    }
]

@mheon
Copy link
Member

mheon commented Dec 31, 2021

Interesting. @baude Did we add renaming for containers at some point?

@hikhvar
Copy link
Contributor Author

hikhvar commented Jan 1, 2022

I made a PR removing the renaming. In my research I found this code line, enforcing that the name of a container in a pod will never be equal to the pod name: https://github.com/containers/podman/blob/main/pkg/specgen/generate/kube/kube.go#L140

hikhvar added a commit to hikhvar/podman that referenced this issue Jan 6, 2022
We enforce the naming scheme "<podname>-<containername>" here [1].
Therefore we must not rename the pod in case of a naming conflict
between pod name and container name. Not renaming the pod increases the
usability for the user and easies scripting based on the name. Otherwise
a user must set some label to reliable find a pod after creation. Or
have to implement the renaming logic in the script.

[1] https://github.com/containers/podman/blob/main/pkg/specgen/generate/kube/kube.go#L140

Fixes containers#12722

Signed-off-by: Christoph Petrausch <[email protected]>
@github-actions github-actions bot added the locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments. label Sep 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 21, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
kind/bug Categorizes issue or PR as related to a bug. locked - please file new issue/PR Assist humans wanting to comment on an old issue or PR with locked comments.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants