Skip to content

Commit

Permalink
[Windows] Fix agent initialization error by adjusting VMSwitch commands
Browse files Browse the repository at this point in the history
Set/Get-VMSwitch could return hostname resolution error in some environments.
This issue can be fixed by adding hostname to configuration.

Signed-off-by: Shuyang Xin <gavinx@vmware.com>
  • Loading branch information
XinShuYang committed Jan 4, 2022
1 parent 089a008 commit c45efd9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions pkg/agent/util/net_windows.go
Expand Up @@ -177,7 +177,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 @@ -398,7 +398,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 @@ -416,7 +416,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 c45efd9

Please sign in to comment.