Skip to content

Commit 3a2a602

Browse files
committed
telco-ran: Pre-create /run/netns bindmount so it propagates to the container-mount-namespace
This closes a race between running `ip netns add` inside the container-mount-namespace namespace and running it outside of the container-mount-namespace namespace. The cause of the race is that the /run/netns/ bindmount created by `ip netns add` is created with rshared properties, so the external call would shadow the internal call any time the internal call occurs first. Forcing the call to happen on the outside ensures any subsequent internal calls will simply reuse the existing bindmount (as intended). Signed-off-by: Jim Ramsay <jramsay@redhat.com>
1 parent d269bbe commit 3a2a602

5 files changed

Lines changed: 55 additions & 0 deletions

File tree

telco-ran/configuration/extra-manifests-builder/01-container-mount-ns-and-kubelet-conf/container-mount-namespace.service

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,14 @@ ExecStartPre=bash -c "findmnt ${RUNTIME_DIRECTORY} || mount --make-unbindable --
1111
ExecStartPre=touch ${BIND_POINT}
1212
ExecStart=unshare --mount=${BIND_POINT} --propagation slave mount --make-rshared /
1313
ExecStop=umount -R ${RUNTIME_DIRECTORY}
14+
15+
# Initialize /run/netns as a shared mount point to prevent shadowing race condition
16+
# This must happen before CRI-O starts to ensure all namespace bind mounts have
17+
# the correct parent mount. Without this, 'ip netns add' (called later by network
18+
# components) would create the mount point and shadow any earlier namespace mounts
19+
# created by CRI-O's pinns, causing pods to fail with 'setns: Invalid argument'.
20+
# Creating and deleting a netns retains the side-effect of creating the
21+
# /run/netns mountpoint (but base exit code solely on whether the mountpoint is
22+
# present)
23+
# Reference: OCPBUGS-83562
24+
ExecStartPost=bash -c "ip netns add kubensmnt && ip netns delete kubensmnt || mountpoint -q /run/netns"

telco-ran/configuration/kube-compare-reference/machine-config/kubelet-configuration-and-container-mount-hiding/01-container-mount-ns-and-kubelet-conf-master.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ spec:
3636
ExecStartPre=touch ${BIND_POINT}
3737
ExecStart=unshare --mount=${BIND_POINT} --propagation slave mount --make-rshared /
3838
ExecStop=umount -R ${RUNTIME_DIRECTORY}
39+
40+
# Initialize /run/netns as a shared mount point to prevent shadowing race condition
41+
# This must happen before CRI-O starts to ensure all namespace bind mounts have
42+
# the correct parent mount. Without this, 'ip netns add' (called later by network
43+
# components) would create the mount point and shadow any earlier namespace mounts
44+
# created by CRI-O's pinns, causing pods to fail with 'setns: Invalid argument'.
45+
# Creating and deleting a netns retains the side-effect of creating the
46+
# /run/netns mountpoint (but base exit code solely on whether the mountpoint is
47+
# present)
48+
# Reference: OCPBUGS-83562
49+
ExecStartPost=bash -c "ip netns add kubensmnt && ip netns delete kubensmnt || mountpoint -q /run/netns"
3950
name: container-mount-namespace.service
4051
- dropins:
4152
- contents: |

telco-ran/configuration/kube-compare-reference/machine-config/kubelet-configuration-and-container-mount-hiding/01-container-mount-ns-and-kubelet-conf-worker.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ spec:
3636
ExecStartPre=touch ${BIND_POINT}
3737
ExecStart=unshare --mount=${BIND_POINT} --propagation slave mount --make-rshared /
3838
ExecStop=umount -R ${RUNTIME_DIRECTORY}
39+
40+
# Initialize /run/netns as a shared mount point to prevent shadowing race condition
41+
# This must happen before CRI-O starts to ensure all namespace bind mounts have
42+
# the correct parent mount. Without this, 'ip netns add' (called later by network
43+
# components) would create the mount point and shadow any earlier namespace mounts
44+
# created by CRI-O's pinns, causing pods to fail with 'setns: Invalid argument'.
45+
# Creating and deleting a netns retains the side-effect of creating the
46+
# /run/netns mountpoint (but base exit code solely on whether the mountpoint is
47+
# present)
48+
# Reference: OCPBUGS-83562
49+
ExecStartPost=bash -c "ip netns add kubensmnt && ip netns delete kubensmnt || mountpoint -q /run/netns"
3950
name: container-mount-namespace.service
4051
- dropins:
4152
- contents: |

telco-ran/configuration/source-crs/extra-manifest/01-container-mount-ns-and-kubelet-conf-master.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ spec:
3636
ExecStartPre=touch ${BIND_POINT}
3737
ExecStart=unshare --mount=${BIND_POINT} --propagation slave mount --make-rshared /
3838
ExecStop=umount -R ${RUNTIME_DIRECTORY}
39+
40+
# Initialize /run/netns as a shared mount point to prevent shadowing race condition
41+
# This must happen before CRI-O starts to ensure all namespace bind mounts have
42+
# the correct parent mount. Without this, 'ip netns add' (called later by network
43+
# components) would create the mount point and shadow any earlier namespace mounts
44+
# created by CRI-O's pinns, causing pods to fail with 'setns: Invalid argument'.
45+
# Creating and deleting a netns retains the side-effect of creating the
46+
# /run/netns mountpoint (but base exit code solely on whether the mountpoint is
47+
# present)
48+
# Reference: OCPBUGS-83562
49+
ExecStartPost=bash -c "ip netns add kubensmnt && ip netns delete kubensmnt || mountpoint -q /run/netns"
3950
name: container-mount-namespace.service
4051
- dropins:
4152
- contents: |

telco-ran/configuration/source-crs/extra-manifest/01-container-mount-ns-and-kubelet-conf-worker.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,17 @@ spec:
3636
ExecStartPre=touch ${BIND_POINT}
3737
ExecStart=unshare --mount=${BIND_POINT} --propagation slave mount --make-rshared /
3838
ExecStop=umount -R ${RUNTIME_DIRECTORY}
39+
40+
# Initialize /run/netns as a shared mount point to prevent shadowing race condition
41+
# This must happen before CRI-O starts to ensure all namespace bind mounts have
42+
# the correct parent mount. Without this, 'ip netns add' (called later by network
43+
# components) would create the mount point and shadow any earlier namespace mounts
44+
# created by CRI-O's pinns, causing pods to fail with 'setns: Invalid argument'.
45+
# Creating and deleting a netns retains the side-effect of creating the
46+
# /run/netns mountpoint (but base exit code solely on whether the mountpoint is
47+
# present)
48+
# Reference: OCPBUGS-83562
49+
ExecStartPost=bash -c "ip netns add kubensmnt && ip netns delete kubensmnt || mountpoint -q /run/netns"
3950
name: container-mount-namespace.service
4051
- dropins:
4152
- contents: |

0 commit comments

Comments
 (0)