From 77d19f847a7488ccaccae769cf6b27f880ebe07b Mon Sep 17 00:00:00 2001 From: Alban Bedel Date: Mon, 30 Mar 2020 02:53:43 +0200 Subject: If possible use the pod name when creating a network When creating a network we pass down a name which end up in the K8S_POD_NAME argument to cni plugins. Currently this name is always filled with the container name, so for pods it is the name of the infra container, not really what one would expect. This mess up with the dnsname plugin as it doesn't receive the pod name in K8S_POD_NAME. To fix this pass the pod name when the container is part of a pod, otherwise use the container name like before. Signed-off-by: Alban Bedel --- v2: Only call GetPod() when a pod id is set --- libpod/networking_linux.go | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'libpod') diff --git a/libpod/networking_linux.go b/libpod/networking_linux.go index c3a90f481..83344ebbe 100644 --- a/libpod/networking_linux.go +++ b/libpod/networking_linux.go @@ -101,7 +101,19 @@ func (r *Runtime) configureNetNS(ctr *Container, ctrNS ns.NetNS) ([]*cnitypes.Re requestedMAC = ctr.config.StaticMAC } - podNetwork := r.getPodNetwork(ctr.ID(), ctr.Name(), ctrNS.Path(), ctr.config.Networks, ctr.config.PortMappings, requestedIP, requestedMAC) + // If we are in a pod use the pod name for the network, otherwise the container name + var podName string + if ctr.PodID() != "" { + pod, err := r.GetPod(ctr.PodID()) + if err == nil { + podName = pod.Name() + } + } + if podName == "" { + podName = ctr.Name() + } + + podNetwork := r.getPodNetwork(ctr.ID(), podName, ctrNS.Path(), ctr.config.Networks, ctr.config.PortMappings, requestedIP, requestedMAC) results, err := r.netPlugin.SetUpPod(podNetwork) if err != nil { -- cgit v1.2.3-54-g00ecf