From 0ae8b6ba5966248174b2f05efa03bc199ca76e66 Mon Sep 17 00:00:00 2001 From: Peter Hornyack Date: Thu, 19 Dec 2019 14:53:59 -0800 Subject: [PATCH] Update subnet mask calculation for compatibility with future VNIC changes --- cluster/gce/windows/k8s-node-setup.psm1 | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cluster/gce/windows/k8s-node-setup.psm1 b/cluster/gce/windows/k8s-node-setup.psm1 index 061d848025c..90ba32618bc 100644 --- a/cluster/gce/windows/k8s-node-setup.psm1 +++ b/cluster/gce/windows/k8s-node-setup.psm1 @@ -457,8 +457,17 @@ function Get_MgmtSubnet { $addr = (Get-NetIPAddress ` -InterfaceAlias ${net_adapter}.ifAlias ` -AddressFamily IPv4).IPAddress - $mask = (Get-WmiObject Win32_NetworkAdapterConfiguration | - Where-Object InterfaceIndex -eq $(${net_adapter}.ifIndex)).IPSubnet[0] + # Get the adapter's mask from the registry rather than WMI or some other + # approach: this is compatible with Windows' forthcoming LWVNICs (lightweight + # VNICs). + # https://github.com/kubernetes-sigs/sig-windows-tools/pull/16/commits/c5b5c67d5da6c23ad870cb16146eaa58131caf29 + $adapter_registry = Get-Item ` + -Path ("HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\" + + "Parameters\Interfaces\$($net_adapter.InterfaceGuid)") + # In this command the value name is 'DhcpSubnetMask' for current network + # interfaces but could be different for "LWVNIC" interfaces. + $mask = ($adapter_registry.GetValueNames() -like "*SubnetMask" | + % { $adapter_registry.GetValue($_) }) $mgmt_subnet = ` (ConvertTo_DecimalIP ${addr}) -band (ConvertTo_DecimalIP ${mask}) $mgmt_subnet = ConvertTo_DottedDecimalIP ${mgmt_subnet}