Closed zhouzijiang closed 5 years ago
@tiewei @vhosakot please review it, thanks again
Thanks for submitting reviews, the logic here sound, do you mind adding some test cases ?
ok, I will add some test cases. In fact, we have run contiv with this feature in our k8s cluster for about a year
@tiewei I have added some test cases
very good
Description of the changes
Type of fix: Bug Fix
Please describe:
when kubelet creates a pod, it will call RunPodSandbox function:
when the container runtime is docker in kubelet, it has the following steps: 1.1 create the sandbox container(it will be in the new network namespace) 1.2 start the sandbox container 1.3 kubelet forks and execs binary contivk8s and pass CNI_NETNS like '/proc/37544/ns/net' 1.4 contivk8s pass '/proc/37544/ns/net' to netplugin 1.5 netplugin get the new network namespace from '/proc/37544/ns/net' 1.6 netplugin execs command like 'nsenter -t 37544 -n ip address add 192.168.1.1/24 dev eth0'
when the container runtime is containerd or other in kubelet, it has the following steps: 2.1 containerd saves the current network namespace 2.2 containerd calls unshare to move it to a new network namespace 2.3 containerd creates file like '/var/run/netns/cni-eb58672e-a27e-ac5d-73dd-7ebb56282818' and bind mounts it to the new network namespace 2.4 containerd restores itself to the original network namespace 2.5 now there are no processes in the new network namespace, and we can only access the new network namespace by file '/var/run/netns/cni-eb58672e-a27e-ac5d-73dd-7ebb56282818' 2.6 containerd forks and execs binary contivk8s and pass CNI_NETNS like '/var/run/netns/cni-eb58672e-a27e-ac5d-73dd-7ebb56282818' 2.7 contivk8s pass '/var/run/netns/cni-eb58672e-a27e-ac5d-73dd-7ebb56282818' to netplugin 2.8 netplugin can not parse '/var/run/netns/cni-eb58672e-a27e-ac5d-73dd-7ebb56282818' and return error
So, our solution is changing step 2.7:
TODO