From a994cb531a9e7cd01091997b1daa34e4f7941881 Mon Sep 17 00:00:00 2001 From: Alin-Gheorghe Balutoiu Date: Thu, 22 Mar 2018 13:02:49 +0100 Subject: [PATCH] Add support for CNI on Windows Server 2016 RTM Currently the Windows Server 2016 RTM has no CNI support. With this commit, the Windows Server 2016 RTM will be able to use the CNI plugin for networking setup. This commit also moves some comments to the right place. Signed-off-by: Alin Balutoiu --- pkg/kubelet/dockershim/helpers_windows.go | 36 ++++++++--------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/pkg/kubelet/dockershim/helpers_windows.go b/pkg/kubelet/dockershim/helpers_windows.go index e614eed851b..0c54bea03d4 100644 --- a/pkg/kubelet/dockershim/helpers_windows.go +++ b/pkg/kubelet/dockershim/helpers_windows.go @@ -115,6 +115,17 @@ func (ds *dockerService) determinePodIPBySandboxID(sandboxID string) string { // Todo: Add a kernel version check for more validation if networkMode := os.Getenv("CONTAINER_NETWORK"); networkMode == "" { + // On Windows, every container that is created in a Sandbox, needs to invoke CNI plugin again for adding the Network, + // with the shared container name as NetNS info, + // This is passed down to the platform to replicate some necessary information to the new container + + // + // This place is chosen as a hack for now, since ds.getIP would end up calling CNI's addToNetwork + // That is why addToNetwork is required to be idempotent + + // Instead of relying on this call, an explicit call to addToNetwork should be + // done immediately after ContainerCreation, in case of Windows only. TBD Issue # to handle this + if r.HostConfig.Isolation == kubeletapis.HypervIsolationValue { // Hyper-V only supports one container per Pod yet and the container will have a different // IP address from sandbox. Return the first non-sandbox container IP as POD IP. @@ -127,18 +138,8 @@ func (ds *dockerService) determinePodIPBySandboxID(sandboxID string) string { ds.getIP(sandboxID, r) } } else { - // On Windows, every container that is created in a Sandbox, needs to invoke CNI plugin again for adding the Network, - // with the shared container name as NetNS info, - // This is passed down to the platform to replicate some necessary information to the new container - - // - // This place is chosen as a hack for now, since getContainerIP would end up calling CNI's addToNetwork - // That is why addToNetwork is required to be idempotent - - // Instead of relying on this call, an explicit call to addToNetwork should be - // done immediately after ContainerCreation, in case of Windows only. TBD Issue # to handle this - - if containerIP := getContainerIP(r); containerIP != "" { + // ds.getIP will call the CNI plugin to fetch the IP + if containerIP := ds.getIP(c.ID, r); containerIP != "" { return containerIP } } @@ -153,14 +154,3 @@ func getNetworkNamespace(c *dockertypes.ContainerJSON) (string, error) { // so returning the docker networkMode (which holds container: for network namespace here return string(c.HostConfig.NetworkMode), nil } - -func getContainerIP(container *dockertypes.ContainerJSON) string { - if container.NetworkSettings != nil { - for _, network := range container.NetworkSettings.Networks { - if network.IPAddress != "" { - return network.IPAddress - } - } - } - return "" -}