diff --git a/cni/network/invoker.go b/cni/network/invoker.go index 81af1975e5..36021a6385 100644 --- a/cni/network/invoker.go +++ b/cni/network/invoker.go @@ -13,7 +13,6 @@ import ( // This interface can be used to call into external binaries, like the azure-vnet-ipam binary, // or simply act as a client to an external ipam, such as azure-cns. type IPAMInvoker interface { - // Add returns two results, one IPv4, the other IPv6. Add(IPAMAddConfig) (IPAMAddResult, error) diff --git a/cni/network/multitenancy.go b/cni/network/multitenancy.go index 1b9047237c..b1c7cc9330 100644 --- a/cni/network/multitenancy.go +++ b/cni/network/multitenancy.go @@ -9,7 +9,6 @@ import ( "net" "net/http" "os" - "strconv" "strings" "time" @@ -262,17 +261,12 @@ func convertToCniResult(networkConfig *cns.GetNetworkContainerResponse, ifName s } } - var sb strings.Builder - sb.WriteString("Adding cnetAddressspace routes ") for _, ipRouteSubnet := range networkConfig.CnetAddressSpace { - sb.WriteString(ipRouteSubnet.IPAddress + "/" + strconv.Itoa((int)(ipRouteSubnet.PrefixLength)) + ", ") routeIPnet := net.IPNet{IP: net.ParseIP(ipRouteSubnet.IPAddress), Mask: net.CIDRMask(int(ipRouteSubnet.PrefixLength), 32)} gwIP := net.ParseIP(ipconfig.GatewayIPAddress) result.Routes = append(result.Routes, &cniTypes.Route{Dst: routeIPnet, GW: gwIP}) } - log.Printf(sb.String()) - iface := &cniTypesCurr.Interface{Name: ifName} result.Interfaces = append(result.Interfaces, iface) diff --git a/cni/network/network.go b/cni/network/network.go index 1fb210ceac..9ac535e79c 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -334,8 +334,6 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error { return err } - log.Printf("[cni-net] Read network configuration %+v.", nwCfg) - iptables.DisableIPTableLock = nwCfg.DisableIPTableLock plugin.setCNIReportDetails(nwCfg, CNI_ADD, "") @@ -376,7 +374,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error { res.Print() } - log.Printf("[cni-net] ADD command completed for pod %v with result:%+v err:%v.", k8sPodName, ipamAddResult.ipv4Result, err) + log.Printf("[cni-net] ADD command completed for pod %v with IPs:%+v err:%v.", k8sPodName, ipamAddResult.ipv4Result.IPs, err) }() // Parse Pod arguments. @@ -401,7 +399,6 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error { return plugin.Errorf(errMsg) } - log.Printf("Execution mode :%s", nwCfg.ExecutionMode) if nwCfg.ExecutionMode == string(util.Baremetal) { var res *nnscontracts.ConfigureContainerNetworkingResponse log.Printf("Baremetal mode. Calling vnet agent for ADD") @@ -754,8 +751,7 @@ func (plugin *NetPlugin) createEndpointInternal(opt *createEndpointInternalOpt) } // Create the endpoint. - telemetry.SendCNIEvent(plugin.tb, fmt.Sprintf("[cni-net] Creating endpoint %+v.", epInfo)) - log.Printf("[cni-net] Creating endpoint %v.", epInfo.Id) + telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("[cni-net] Creating endpoint %s.", epInfo.PrettyString())) err = plugin.nm.CreateEndpoint(cnsclient, opt.nwInfo.Id, &epInfo) if err != nil { err = plugin.Errorf("Failed to create endpoint: %v", err) @@ -883,8 +879,6 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error { return err } - log.Printf("[cni-net] Read network configuration %+v.", nwCfg) - // Parse Pod arguments. if k8sPodName, k8sNamespace, err = plugin.getPodInfo(args.Args); err != nil { log.Printf("[cni-net] Failed to get POD info due to error: %v", err) @@ -946,7 +940,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error { // Query the network. if nwInfo, err = plugin.nm.GetNetworkInfo(networkID); err != nil { if !nwCfg.MultiTenancy { - log.Printf("[cni-net] Failed to query network: %v", err) + log.Printf("[cni-net] Failed to query network:%s: %v", networkID, err) // Log the error but return success if the network is not found. // if cni hits this, mostly state file would be missing and it can be reboot scenario where // container runtime tries to delete and create pods which existed before reboot. @@ -962,7 +956,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error { if !nwCfg.MultiTenancy { // attempt to release address associated with this Endpoint id // This is to ensure clean up is done even in failure cases - log.Printf("[cni-net] Failed to query endpoint: %v", err) + log.Printf("[cni-net] Failed to query endpoint %s: %v", endpointID, err) telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("Release ip by ContainerID (endpoint not found):%v", args.ContainerID)) if err = plugin.ipamInvoker.Delete(nil, nwCfg, args, nwInfo.Options); err != nil { return plugin.RetriableError(fmt.Errorf("failed to release address(no endpoint): %w", err)) @@ -986,7 +980,6 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error { } if !nwCfg.MultiTenancy { - log.Printf("epinfo:%+v", epInfo) // Call into IPAM plugin to release the endpoint's addresses. for _, address := range epInfo.IPAddresses { telemetry.LogAndSendEvent(plugin.tb, fmt.Sprintf("Release ip:%s", address.IP.String())) diff --git a/cni/plugin.go b/cni/plugin.go index 4318db53b0..bfefdf9f79 100644 --- a/cni/plugin.go +++ b/cni/plugin.go @@ -95,7 +95,7 @@ func (plugin *Plugin) DelegateAdd(pluginName string, nwCfg *NetworkConfig) (*cni var result *cniTypesCurr.Result var err error - log.Printf("[cni] Calling plugin %v ADD nwCfg:%+v.", pluginName, nwCfg) + log.Printf("[cni] Calling plugin %v ADD", pluginName) defer func() { log.Printf("[cni] Plugin %v returned result:%+v, err:%v.", pluginName, result, err) }() os.Setenv(Cmd, CmdAdd) diff --git a/network/endpoint.go b/network/endpoint.go index c664321be7..b48cdf0262 100644 --- a/network/endpoint.go +++ b/network/endpoint.go @@ -5,6 +5,7 @@ package network import ( "context" + "fmt" "net" "strings" @@ -99,12 +100,17 @@ type apipaClient interface { CreateHostNCApipaEndpoint(ctx context.Context, networkContainerID string) (string, error) } +func (epInfo *EndpointInfo) PrettyString() string { + return fmt.Sprintf("Id:%s ContainerID:%s NetNsPath:%s IfName:%s IfIndex:%d MacAddr:%s IPAddrs:%v Gateways:%v", + epInfo.Id, epInfo.ContainerID, epInfo.NetNsPath, epInfo.IfName, epInfo.IfIndex, epInfo.MacAddress.String(), epInfo.IPAddresses, + epInfo.Gateways) +} + // NewEndpoint creates a new endpoint in the network. func (nw *network) newEndpoint(cli apipaClient, nl netlink.NetlinkInterface, plc platform.ExecClient, epInfo *EndpointInfo) (*endpoint, error) { var ep *endpoint var err error - log.Printf("[net] Creating endpoint %+v in network %v.", epInfo, nw.Id) defer func() { if err != nil { log.Printf("[net] Failed to create endpoint %v, err:%v.", epInfo.Id, err) @@ -157,8 +163,6 @@ func (nw *network) deleteEndpoint(nl netlink.NetlinkInterface, plc platform.Exec // GetEndpoint returns the endpoint with the given ID. func (nw *network) getEndpoint(endpointId string) (*endpoint, error) { - log.Printf("Trying to retrieve endpoint id %v", endpointId) - ep := nw.Endpoints[endpointId] if ep == nil { diff --git a/network/manager.go b/network/manager.go index 0a647a20ca..96d636e696 100644 --- a/network/manager.go +++ b/network/manager.go @@ -524,8 +524,6 @@ func (nm *networkManager) GetNumberOfEndpoints(ifName string, networkId string) } } - log.Printf("Get number of endpoints for ifname %v network %v", ifName, networkId) - if nm.ExternalInterfaces != nil { extIf := nm.ExternalInterfaces[ifName] if extIf != nil && extIf.Networks != nil { diff --git a/network/network.go b/network/network.go index bdb5528ff4..269b0a5064 100644 --- a/network/network.go +++ b/network/network.go @@ -4,6 +4,7 @@ package network import ( + "fmt" "net" "strings" @@ -89,6 +90,11 @@ type DNSInfo struct { Options []string } +func (nwInfo *NetworkInfo) PrettyString() string { + return fmt.Sprintf("Id:%s MasterIfName:%s AdapterName:%s Mode:%s Subnets:%v podsubnet:%v Enablesnatonhost:%t", nwInfo.Id, nwInfo.MasterIfName, + nwInfo.AdapterName, nwInfo.Mode, nwInfo.Subnets, nwInfo.PodSubnet, nwInfo.EnableSnatOnHost) +} + // NewExternalInterface adds a host interface to the list of available external interfaces. func (nm *networkManager) newExternalInterface(ifName string, subnet string) error { // Check whether the external interface is already configured. @@ -156,7 +162,7 @@ func (nm *networkManager) newNetwork(nwInfo *NetworkInfo) (*network, error) { var nw *network var err error - log.Printf("[net] Creating network %+v.", nwInfo) + log.Printf("[net] Creating network %s.", nwInfo.PrettyString()) defer func() { if err != nil { log.Printf("[net] Failed to create network %v, err:%v.", nwInfo.Id, err) diff --git a/network/policy/policy_windows.go b/network/policy/policy_windows.go index 0782637dd8..ee5500d459 100644 --- a/network/policy/policy_windows.go +++ b/network/policy/policy_windows.go @@ -506,7 +506,7 @@ func GetHcnEndpointPolicies(policyType CNIPolicyType, policies []Policy, epInfoD if !(isOutboundNatPolicy && enableMultiTenancy && !enableSnatForDns) { hcnEndPointPolicies = append(hcnEndPointPolicies, endpointPolicy) - log.Printf("Successfully set the policy: %+v", endpointPolicy) + log.Printf("Successfully retrieve endpoint policy: %s", endpointPolicy.Type) } } } @@ -520,7 +520,7 @@ func GetHcnEndpointPolicies(policyType CNIPolicyType, policies []Policy, epInfoD } hcnEndPointPolicies = append(hcnEndPointPolicies, natPolicy) - log.Printf("Successfully set the policy: %+v", natPolicy) + log.Printf("Successfully retrieve natInfo policy: %s", natPolicy.Type) } }