Skip to content

Commit c2f3670

Browse files
authored
[Windows] Fix agent initialization error by adjusting VMSwitch commands (#3169)
Set/Get-VMSwitch could return hostname resolution error in some environments. The root cause is the remote DNS name didn’t match hostname, then Set/Get-VMSwitch could return error once it needed to get hostname from DNS name. This issue can be fixed by adding hostname to configuration. e.g. Get-VMSwitch -ComputerName $(hostname) -Name %s Signed-off-by: Shuyang Xin <gavinx@vmware.com>
1 parent 4a9eee7 commit c2f3670

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

pkg/agent/util/net_windows.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func RemoveManagementInterface(networkName string) error {
177177
var err error
178178
var maxRetry = 3
179179
var i = 0
180-
cmd := fmt.Sprintf("Get-VMSwitch -Name %s | Set-VMSwitch -AllowManagementOS $false ", networkName)
180+
cmd := fmt.Sprintf("Get-VMSwitch -ComputerName $(hostname) -Name %s | Set-VMSwitch -ComputerName $(hostname) -AllowManagementOS $false ", networkName)
181181
// Retry the operation here because an error is returned at the first invocation.
182182
for i < maxRetry {
183183
_, err = ps.RunCommand(cmd)
@@ -398,7 +398,7 @@ func PrepareHNSNetwork(subnetCIDR *net.IPNet, nodeIPNet *net.IPNet, uplinkAdapte
398398
// EnableRSCOnVSwitch enables RSC in the vSwitch to reduce host CPU utilization and increase throughput for virtual
399399
// workloads by coalescing multiple TCP segments into fewer, but larger segments.
400400
func EnableRSCOnVSwitch(vSwitch string) error {
401-
cmd := fmt.Sprintf("Get-VMSwitch -Name %s | Select-Object -Property SoftwareRscEnabled | Format-Table -HideTableHeaders", vSwitch)
401+
cmd := fmt.Sprintf("Get-VMSwitch -ComputerName $(hostname) -Name %s | Select-Object -Property SoftwareRscEnabled | Format-Table -HideTableHeaders", vSwitch)
402402
stdout, err := ps.RunCommand(cmd)
403403
if err != nil {
404404
return err
@@ -416,7 +416,7 @@ func EnableRSCOnVSwitch(vSwitch string) error {
416416
klog.Infof("Receive Segment Coalescing (RSC) for vSwitch %s is already enabled", vSwitch)
417417
return nil
418418
}
419-
cmd = fmt.Sprintf("Set-VMSwitch -Name %s -EnableSoftwareRsc $True", vSwitch)
419+
cmd = fmt.Sprintf("Set-VMSwitch -ComputerName $(hostname) -Name %s -EnableSoftwareRsc $True", vSwitch)
420420
_, err = ps.RunCommand(cmd)
421421
if err != nil {
422422
return err

0 commit comments

Comments
 (0)