Skip to content

Commit

Permalink
Fix agent initialization error by adjusting VMSwitch commands (#3238)
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
XinShuYang committed Jan 28, 2022
1 parent ac23819 commit 8df6730
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/agent/util/net_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func RemoveManagementInterface(networkName string) error {
var err error
var maxRetry = 3
var i = 0
cmd := fmt.Sprintf("Get-VMSwitch -Name %s | Set-VMSwitch -AllowManagementOS $false ", networkName)
cmd := fmt.Sprintf("Get-VMSwitch -ComputerName $(hostname) -Name %s | Set-VMSwitch -ComputerName $(hostname) -AllowManagementOS $false ", networkName)
// Retry the operation here because an error is returned at the first invocation.
for i < maxRetry {
_, err = ps.RunCommand(cmd)
Expand Down Expand Up @@ -379,7 +379,7 @@ func PrepareHNSNetwork(subnetCIDR *net.IPNet, nodeIPNet *net.IPNet, uplinkAdapte
// EnableRSCOnVSwitch enables RSC in the vSwitch to reduce host CPU utilization and increase throughput for virtual
// workloads by coalescing multiple TCP segments into fewer, but larger segments.
func EnableRSCOnVSwitch(vSwitch string) error {
cmd := fmt.Sprintf("Get-VMSwitch -Name %s | Select-Object -Property SoftwareRscEnabled | Format-Table -HideTableHeaders", vSwitch)
cmd := fmt.Sprintf("Get-VMSwitch -ComputerName $(hostname) -Name %s | Select-Object -Property SoftwareRscEnabled | Format-Table -HideTableHeaders", vSwitch)
stdout, err := ps.RunCommand(cmd)
if err != nil {
return err
Expand All @@ -397,7 +397,7 @@ func EnableRSCOnVSwitch(vSwitch string) error {
klog.Infof("Receive Segment Coalescing (RSC) for vSwitch %s is already enabled", vSwitch)
return nil
}
cmd = fmt.Sprintf("Set-VMSwitch -Name %s -EnableSoftwareRsc $True", vSwitch)
cmd = fmt.Sprintf("Set-VMSwitch -ComputerName $(hostname) -Name %s -EnableSoftwareRsc $True", vSwitch)
_, err = ps.RunCommand(cmd)
if err != nil {
return err
Expand Down

0 comments on commit 8df6730

Please sign in to comment.