Skip to content

Commit 13e3904

Browse files
authored
Merge pull request kubernetes#86453 from pjh/lwvnic
Update Windows subnet mask calculation for compatibility with future VNIC changes
2 parents 9fa1e00 + 0ae8b6b commit 13e3904

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

cluster/gce/windows/k8s-node-setup.psm1

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -457,8 +457,17 @@ function Get_MgmtSubnet {
457457
$addr = (Get-NetIPAddress `
458458
-InterfaceAlias ${net_adapter}.ifAlias `
459459
-AddressFamily IPv4).IPAddress
460-
$mask = (Get-WmiObject Win32_NetworkAdapterConfiguration |
461-
Where-Object InterfaceIndex -eq $(${net_adapter}.ifIndex)).IPSubnet[0]
460+
# Get the adapter's mask from the registry rather than WMI or some other
461+
# approach: this is compatible with Windows' forthcoming LWVNICs (lightweight
462+
# VNICs).
463+
# https://github.com/kubernetes-sigs/sig-windows-tools/pull/16/commits/c5b5c67d5da6c23ad870cb16146eaa58131caf29
464+
$adapter_registry = Get-Item `
465+
-Path ("HKLM:\SYSTEM\CurrentControlSet\Services\Tcpip\" +
466+
"Parameters\Interfaces\$($net_adapter.InterfaceGuid)")
467+
# In this command the value name is 'DhcpSubnetMask' for current network
468+
# interfaces but could be different for "LWVNIC" interfaces.
469+
$mask = ($adapter_registry.GetValueNames() -like "*SubnetMask" |
470+
% { $adapter_registry.GetValue($_) })
462471
$mgmt_subnet = `
463472
(ConvertTo_DecimalIP ${addr}) -band (ConvertTo_DecimalIP ${mask})
464473
$mgmt_subnet = ConvertTo_DottedDecimalIP ${mgmt_subnet}

0 commit comments

Comments
 (0)