Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion cni/network/invoker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 0 additions & 6 deletions cni/network/multitenancy.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"net"
"net/http"
"os"
"strconv"
"strings"
"time"

Expand Down Expand Up @@ -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)

Expand Down
15 changes: 4 additions & 11 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, "")

Expand Down Expand Up @@ -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.
Expand All @@ -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")
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand All @@ -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))
Expand All @@ -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()))
Expand Down
2 changes: 1 addition & 1 deletion cni/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 7 additions & 3 deletions network/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package network

import (
"context"
"fmt"
"net"
"strings"

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 0 additions & 2 deletions network/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
package network

import (
"fmt"
"net"
"strings"

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions network/policy/policy_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}
Expand All @@ -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)
}
}

Expand Down