summaryrefslogtreecommitdiff
path: root/libpod/rootless_cni_linux.go
diff options
context:
space:
mode:
authorOpenShift Merge Robot <openshift-merge-robot@users.noreply.github.com>2020-10-31 11:12:05 +0100
committerGitHub <noreply@github.com>2020-10-31 11:12:05 +0100
commit5a53c6e5c97afe4c4add1d649b6f9d68204a8918 (patch)
tree3db189d698634e27a7a756b5f8ca5cb81a87c2f5 /libpod/rootless_cni_linux.go
parentb6ab2df9d11a736c7781f200ff39c886f41e172d (diff)
parent2704dfbb7a3fc079a74e9c8edf1acd7be24db035 (diff)
downloadpodman-5a53c6e5c97afe4c4add1d649b6f9d68204a8918.tar.gz
podman-5a53c6e5c97afe4c4add1d649b6f9d68204a8918.tar.bz2
podman-5a53c6e5c97afe4c4add1d649b6f9d68204a8918.zip
Merge pull request #8203 from Luap99/fix-8194
Fix dnsname when joining a different network namespace in a pod
Diffstat (limited to 'libpod/rootless_cni_linux.go')
-rw-r--r--libpod/rootless_cni_linux.go16
1 files changed, 10 insertions, 6 deletions
diff --git a/libpod/rootless_cni_linux.go b/libpod/rootless_cni_linux.go
index 21e43ebd0..3d4ff6e86 100644
--- a/libpod/rootless_cni_linux.go
+++ b/libpod/rootless_cni_linux.go
@@ -53,7 +53,7 @@ func AllocRootlessCNI(ctx context.Context, c *Container) (ns.NetNS, []*cnitypes.
if err != nil {
return nil, nil, err
}
- k8sPodName := getPodOrContainerName(c) // passed to CNI as K8S_POD_NAME
+ k8sPodName := getCNIPodName(c) // passed to CNI as K8S_POD_NAME
cniResults := make([]*cnitypes.Result, len(c.config.Networks))
for i, nw := range c.config.Networks {
cniRes, err := rootlessCNIInfraCallAlloc(infra, c.ID(), nw, k8sPodName)
@@ -115,12 +115,16 @@ func getRootlessCNIInfraLock(r *Runtime) (lockfile.Locker, error) {
return lockfile.GetLockfile(fname)
}
-func getPodOrContainerName(c *Container) string {
- pod, err := c.runtime.GetPod(c.PodID())
- if err != nil || pod.config.Name == "" {
- return c.Name()
+// getCNIPodName return the pod name (hostname) used by CNI and the dnsname plugin.
+// If we are in the pod network namespace use the pod name otherwise the container name
+func getCNIPodName(c *Container) string {
+ if c.config.NetMode.IsPod() || c.IsInfra() {
+ pod, err := c.runtime.GetPod(c.PodID())
+ if err == nil {
+ return pod.Name()
+ }
}
- return pod.config.Name
+ return c.Name()
}
func rootlessCNIInfraCallAlloc(infra *Container, id, nw, k8sPodName string) (*cnitypes.Result, error) {