Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
  • Loading branch information
paulyufan2 committed Sep 27, 2023
1 parent a5caa30 commit 1d159b5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
5 changes: 4 additions & 1 deletion network/endpoint_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"net"
"strings"

zaplog "github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/netio"
"github.com/Azure/azure-container-networking/netlink"
"github.com/Azure/azure-container-networking/network/policy"
Expand All @@ -18,6 +19,8 @@ import (
"go.uber.org/zap"
)

var platformLogger = zaplog.CNILogger.With(zap.String("component", "platform-windows"))

const (
// hcnSchemaVersionMajor indicates major version number for hcn schema
hcnSchemaVersionMajor = 2
Expand Down Expand Up @@ -183,7 +186,7 @@ func (nw *network) addIPv6NeighborEntryForGateway(epInfo *EndpointInfo) error {
// run powershell cmd to set neighbor entry for gw ip to 12-34-56-78-9a-bc
cmd := fmt.Sprintf("New-NetNeighbor -IPAddress %s -InterfaceAlias \"%s (%s)\" -LinkLayerAddress \"%s\"",
nw.Subnets[1].Gateway.String(), containerIfNamePrefix, epInfo.Id, defaultGwMac)
if out, err = platform.ExecutePowershellCommand(cmd); err != nil {
if out, err = platform.ExecutePowershellCommand(cmd, platformLogger); err != nil {
logger.Error("Adding ipv6 gw neigh entry failed", zap.Any("out", out), zap.Error(err))
return err
}
Expand Down
18 changes: 11 additions & 7 deletions platform/os_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func GetOSInfo() string {

func GetProcessSupport() error {
cmd := fmt.Sprintf("Get-Process -Id %v", os.Getpid())
_, err := ExecutePowershellCommand(cmd)
_, err := ExecutePowershellCommand(cmd, nil)
return err
}

Expand Down Expand Up @@ -154,13 +154,17 @@ func KillProcessByName(processName string) {
}

// ExecutePowershellCommand executes powershell command
func ExecutePowershellCommand(command string) (string, error) {
func ExecutePowershellCommand(command string, logger *zap.Logger) (string, error) {
ps, err := exec.LookPath("powershell.exe")
if err != nil {
return "", fmt.Errorf("Failed to find powershell executable")
}

log.Printf("[Azure-Utils] %s", command)
if logger != nil {
logger.Info("[Azure-Utils]", zap.String("command", command))
} else {
log.Printf("[Azure-Utils] %s", command)
}

cmd := exec.Command(ps, command)
var stdout bytes.Buffer
Expand All @@ -179,20 +183,20 @@ func ExecutePowershellCommand(command string) (string, error) {
// SetSdnRemoteArpMacAddress sets the regkey for SDNRemoteArpMacAddress needed for multitenancy
func SetSdnRemoteArpMacAddress() error {
if sdnRemoteArpMacAddressSet == false {
result, err := ExecutePowershellCommand(GetSdnRemoteArpMacAddressCommand)
result, err := ExecutePowershellCommand(GetSdnRemoteArpMacAddressCommand, nil)
if err != nil {
return err
}

// Set the reg key if not already set or has incorrect value
if result != SDNRemoteArpMacAddress {
if _, err = ExecutePowershellCommand(SetSdnRemoteArpMacAddressCommand); err != nil {
if _, err = ExecutePowershellCommand(SetSdnRemoteArpMacAddressCommand, nil); err != nil {
log.Printf("Failed to set SDNRemoteArpMacAddress due to error %s", err.Error())
return err
}

log.Printf("[Azure CNS] SDNRemoteArpMacAddress regKey set successfully. Restarting hns service.")
if _, err := ExecutePowershellCommand(RestartHnsServiceCommand); err != nil {
if _, err := ExecutePowershellCommand(RestartHnsServiceCommand, nil); err != nil {
log.Printf("Failed to Restart HNS Service due to error %s", err.Error())
return err
}
Expand Down Expand Up @@ -273,7 +277,7 @@ func GetOSDetails() (map[string]string, error) {
func GetProcessNameByID(pidstr string) (string, error) {
pidstr = strings.Trim(pidstr, "\r\n")
cmd := fmt.Sprintf("Get-Process -Id %s|Format-List", pidstr)
out, err := ExecutePowershellCommand(cmd)
out, err := ExecutePowershellCommand(cmd, nil)
if err != nil {
log.Printf("Process is not running. Output:%v, Error %v", out, err)
return "", err
Expand Down

0 comments on commit 1d159b5

Please sign in to comment.