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
4 changes: 2 additions & 2 deletions cni/ipam/ipam.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ func (plugin *ipamPlugin) Get(args *cniSkel.CmdArgs) error {
func (plugin *ipamPlugin) Delete(args *cniSkel.CmdArgs) error {
var err error

logger.Info("[cni-ipam] Processing DEL command",
logger.Info("Processing DEL command",
zap.String("ContainerId", args.ContainerID),
zap.String("Netns", args.Netns),
zap.String("IfName", args.IfName),
Expand All @@ -291,7 +291,7 @@ func (plugin *ipamPlugin) Delete(args *cniSkel.CmdArgs) error {
zap.ByteString("StdinData", args.StdinData))

defer func() {
logger.Info("[cni-ipam] DEL command completed",
logger.Info("DEL command completed",
zap.Error(err))
}()

Expand Down
56 changes: 28 additions & 28 deletions cni/network/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func (plugin *NetPlugin) Start(config *common.PluginConfig) error {
// Initialize base plugin.
err := plugin.Initialize(config)
if err != nil {
logger.Error("[cni-net] Failed to initialize base plugin", zap.Error(err))
logger.Error("Failed to initialize base plugin", zap.Error(err))
return err
}

Expand Down Expand Up @@ -330,7 +330,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {

startTime := time.Now()

logger.Info("[cni-net] Processing ADD command",
logger.Info("Processing ADD command",
zap.String("containerId", args.ContainerID),
zap.String("netNS", args.Netns),
zap.String("ifName", args.IfName),
Expand Down Expand Up @@ -389,7 +389,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
res.Print()
}

logger.Info("[cni-net] ADD command completed for pod %v with IPs:%+v err:%v.",
logger.Info("ADD command completed for",
zap.String("pod", k8sPodName),
zap.Any("IPs", ipamAddResult.ipv4Result.IPs),
zap.Error(err))
Expand Down Expand Up @@ -497,7 +497,7 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
// Issue link: https://github.com/kubernetes/kubernetes/issues/57253

if nwInfoErr == nil {
logger.Info("[cni-net] Found network with subnet",
logger.Info("Found network with subnet",
zap.String("network", networkID),
zap.String("subnet", nwInfo.Subnets[0].Prefix.String()))
nwInfo.IPAMType = nwCfg.IPAM.Type
Expand Down Expand Up @@ -545,14 +545,14 @@ func (plugin *NetPlugin) Add(args *cniSkel.CmdArgs) error {
// Create network
if nwInfoErr != nil {
// Network does not exist.
logger.Info("[cni-net] Creating network", zap.String("networkID", networkID))
logger.Info("Creating network", zap.String("networkID", networkID))
sendEvent(plugin, fmt.Sprintf("[cni-net] Creating network %v.", networkID))
// opts map needs to get passed in here
if nwInfo, err = plugin.createNetworkInternal(networkID, policies, ipamAddConfig, ipamAddResult); err != nil {
logger.Error("Create network failed", zap.Error(err))
return err
}
logger.Info("[cni-net] Created network",
logger.Info("Created network",
zap.String("networkId", networkID),
zap.String("subnet", ipamAddResult.hostSubnetPrefix.String()))
sendEvent(plugin, fmt.Sprintf("[cni-net] Created network %v with subnet %v.", networkID, ipamAddResult.hostSubnetPrefix.String()))
Expand Down Expand Up @@ -625,7 +625,7 @@ func (plugin *NetPlugin) createNetworkInternal(
err := plugin.Errorf("Failed to find the master interface")
return nwInfo, err
}
logger.Info("[cni-net] Found master interface", zap.String("ifname", masterIfName))
logger.Info("Found master interface", zap.String("ifname", masterIfName))

// Add the master as an external interface.
err := plugin.nm.AddExternalInterface(masterIfName, ipamAddResult.hostSubnetPrefix.String())
Expand All @@ -640,7 +640,7 @@ func (plugin *NetPlugin) createNetworkInternal(
return nwInfo, err
}

logger.Info("[cni-net] DNS Info", zap.Any("info", nwDNSInfo))
logger.Info("DNS Info", zap.Any("info", nwDNSInfo))

// Create the network.
nwInfo = network.NetworkInfo{
Expand All @@ -662,7 +662,7 @@ func (plugin *NetPlugin) createNetworkInternal(
}

if err = addSubnetToNetworkInfo(ipamAddResult, &nwInfo); err != nil {
logger.Info("[cni-net] Failed to add subnets to networkInfo",
logger.Info("Failed to add subnets to networkInfo",
zap.Error(err))
return nwInfo, err
}
Expand Down Expand Up @@ -826,7 +826,7 @@ func (plugin *NetPlugin) createEndpointInternal(opt *createEndpointInternalOpt)
}

// Create the endpoint.
logger.Info("[cni-net] Creating endpoint", zap.String("endpointInfo", epInfo.PrettyString()))
logger.Info("Creating endpoint", zap.String("endpointInfo", epInfo.PrettyString()))
sendEvent(plugin, fmt.Sprintf("[cni-net] Creating endpoint %s.", epInfo.PrettyString()))
err = plugin.nm.CreateEndpoint(cnsclient, opt.nwInfo.Id, &epInfo)
if err != nil {
Expand All @@ -847,7 +847,7 @@ func (plugin *NetPlugin) Get(args *cniSkel.CmdArgs) error {
networkID string
)

logger.Info("[cni-net] Processing GET command",
logger.Info("Processing GET command",
zap.String("container", args.ContainerID),
zap.String("netns", args.Netns),
zap.String("ifname", args.IfName),
Expand All @@ -873,7 +873,7 @@ func (plugin *NetPlugin) Get(args *cniSkel.CmdArgs) error {
res.Print()
}

logger.Info("[cni-net] GET command completed", zap.Any("result", result),
logger.Info("GET command completed", zap.Any("result", result),
zap.Error(err))
}()

Expand All @@ -883,22 +883,22 @@ func (plugin *NetPlugin) Get(args *cniSkel.CmdArgs) error {
return err
}

logger.Info("[cni-net] Read network configuration", zap.Any("config", nwCfg))
logger.Info("Read network configuration", zap.Any("config", nwCfg))

iptables.DisableIPTableLock = nwCfg.DisableIPTableLock

// Initialize values from network config.
if networkID, err = plugin.getNetworkName(args.Netns, nil, nwCfg); err != nil {
// TODO: Ideally we should return from here only.
logger.Error("[cni-net] Failed to extract network name from network config",
logger.Error("Failed to extract network name from network config",
zap.Error(err))
}

endpointID := GetEndpointID(args)

// Query the network.
if _, err = plugin.nm.GetNetworkInfo(networkID); err != nil {
plugin.Errorf("Failed to query network: %v", err)
logger.Error("Failed to query network", zap.Error(err))
return err
}

Expand Down Expand Up @@ -946,7 +946,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {

startTime := time.Now()

logger.Info("[cni-net] Processing DEL command",
logger.Info("Processing DEL command",
zap.String("containerId", args.ContainerID),
zap.String("netNS", args.Netns),
zap.String("ifName", args.IfName),
Expand All @@ -957,7 +957,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData))

defer func() {
logger.Info("[cni-net] DEL command completed",
logger.Info("DEL command completed",
zap.String("pod", k8sPodName),
zap.Error(err))
}()
Expand All @@ -970,7 +970,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {

// Parse Pod arguments.
if k8sPodName, k8sNamespace, err = plugin.getPodInfo(args.Args); err != nil {
logger.Error("[cni-net] Failed to get POD info", zap.Error(err))
logger.Error("Failed to get POD info", zap.Error(err))
}

plugin.setCNIReportDetails(nwCfg, CNI_DEL, "")
Expand Down Expand Up @@ -1010,7 +1010,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
case network.AzureCNS:
cnsClient, cnsErr := cnscli.New("", defaultRequestTimeout)
if cnsErr != nil {
logger.Error("[cni-net] failed to create cns client", zap.Error(cnsErr))
logger.Error("failed to create cns client", zap.Error(cnsErr))
return errors.Wrap(cnsErr, "failed to create cns client")
}
plugin.ipamInvoker = NewCNSInvoker(k8sPodName, k8sNamespace, cnsClient, util.ExecutionMode(nwCfg.ExecutionMode), util.IpamMode(nwCfg.IPAM.Mode))
Expand All @@ -1031,7 +1031,7 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
numEndpointsToDelete = plugin.nm.GetNumEndpointsByContainerID(args.ContainerID)
}

logger.Info("[cni-net] Endpoints to be deleted", zap.Int("count", numEndpointsToDelete))
logger.Info("Endpoints to be deleted", zap.Int("count", numEndpointsToDelete))
for i := 0; i < numEndpointsToDelete; i++ {
// Initialize values from network config.
networkID, err = plugin.getNetworkName(args.Netns, nil, nwCfg)
Expand All @@ -1042,14 +1042,14 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
return err
}

logger.Error("[cni-net] Failed to extract network name from network config", zap.Error(err))
logger.Error("Failed to extract network name from network config", zap.Error(err))
err = plugin.Errorf("Failed to extract network name from network config. error: %v", err)
return err
}
// Query the network.
if nwInfo, err = plugin.nm.GetNetworkInfo(networkID); err != nil {
if !nwCfg.MultiTenancy {
logger.Error("[cni-net] Failed to query network",
logger.Error("Failed to query network",
zap.String("network", networkID),
zap.Error(err))
// Log the error but return success if the network is not found.
Expand All @@ -1063,14 +1063,14 @@ func (plugin *NetPlugin) Delete(args *cniSkel.CmdArgs) error {
endpointID := GetEndpointID(args)
// Query the endpoint.
if epInfo, err = plugin.nm.GetEndpointInfo(networkID, endpointID); err != nil {
logger.Info("[cni-net] GetEndpoint",
logger.Info("GetEndpoint",
zap.String("endpoint", endpointID),
zap.Error(err))
if !nwCfg.MultiTenancy {
// attempt to release address associated with this Endpoint id
// This is to ensure clean up is done even in failure cases

logger.Error("[cni-net] Failed to query endpoint",
logger.Error("Failed to query endpoint",
zap.String("endpoint", endpointID),
zap.Error(err))
logger.Error("Release ip by ContainerID (endpoint not found)",
Expand Down Expand Up @@ -1138,7 +1138,7 @@ func (plugin *NetPlugin) Update(args *cniSkel.CmdArgs) error {

startTime := time.Now()

logger.Info("[cni-net] Processing UPDATE command",
logger.Info("Processing UPDATE command",
zap.String("netns", args.Netns),
zap.String("args", args.Args),
zap.String("path", args.Path))
Expand All @@ -1149,7 +1149,7 @@ func (plugin *NetPlugin) Update(args *cniSkel.CmdArgs) error {
return err
}

logger.Info("[cni-net] Read network configuration", zap.Any("config", nwCfg))
logger.Info("Read network configuration", zap.Any("config", nwCfg))

iptables.DisableIPTableLock = nwCfg.DisableIPTableLock
plugin.setCNIReportDetails(nwCfg, CNI_UPDATE, "")
Expand Down Expand Up @@ -1181,14 +1181,14 @@ func (plugin *NetPlugin) Update(args *cniSkel.CmdArgs) error {
res.Print()
}

logger.Info("[cni-net] UPDATE command completed",
logger.Info("UPDATE command completed",
zap.Any("result", result),
zap.Error(err))
}()

// Parse Pod arguments.
if podCfg, err = cni.ParseCniArgs(args.Args); err != nil {
logger.Error("[cni-net] Error while parsing CNI Args during UPDATE",
logger.Error("Error while parsing CNI Args during UPDATE",
zap.Error(err))
return err
}
Expand Down
23 changes: 13 additions & 10 deletions ipam/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@ import (
"strings"
"time"

"github.com/Azure/azure-container-networking/cni/log"
"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/log"
"go.uber.org/zap"
)

var logger = log.CNILogger.With(zap.String("component", "ipam"))

const (
// Host URL to query.
azureQueryUrl = "http://168.63.129.16/machine/plugins?comp=nmagent&type=getinterfaceinfov1"
Expand Down Expand Up @@ -88,22 +91,22 @@ func (s *azureSource) refresh() error {

httpClient := common.InitHttpClient(httpConnectionTimeout, responseHeaderTimeout)
if httpClient == nil {
log.Errorf("[ipam] Failed intializing http client")
logger.Error("Failed intializing http client")
return fmt.Errorf("Error intializing http client")
}

log.Printf("[ipam] Wireserver call %v to retrieve IP List", s.queryUrl)
logger.Info("Wireserver call to retrieve IP List", zap.String("queryUrl", s.queryUrl))
// Fetch configuration.
resp, err := httpClient.Get(s.queryUrl)
if err != nil {
log.Printf("[ipam] wireserver call failed with: %v", err)
logger.Error("wireserver call failed", zap.Error(err))
return err
}

defer resp.Body.Close()

if resp.StatusCode != http.StatusOK {
log.Errorf("[ipam] http return error code for wireserver call %+v", resp)
logger.Error("http return error code for wireserver call", zap.Any("response", resp))
return fmt.Errorf("wireserver http error %+v", resp)
}

Expand Down Expand Up @@ -138,21 +141,21 @@ func (s *azureSource) refresh() error {

// Skip if interface is not found.
if ifName == "" {
log.Printf("[ipam] Failed to find interface with MAC address:%v.", i.MacAddress)
logger.Info("Failed to find interface with", zap.String("MAC Address", i.MacAddress))
continue
}

// For each subnet on the interface...
for _, s := range i.IPSubnet {
_, subnet, err := net.ParseCIDR(s.Prefix)
if err != nil {
log.Printf("[ipam] Failed to parse subnet:%v err:%v.", s.Prefix, err)
logger.Error("Failed to parse subnet", zap.String("prefix", s.Prefix), zap.Error(err))
continue
}

ap, err := local.newAddressPool(ifName, priority, subnet)
if err != nil {
log.Printf("[ipam] Failed to create pool:%v ifName:%v err:%v.", subnet, ifName, err)
logger.Error("Failed to create pool", zap.Any("subnet", subnet), zap.String("ifName", ifName), zap.Error(err))
continue
}

Expand All @@ -168,12 +171,12 @@ func (s *azureSource) refresh() error {

_, err = ap.newAddressRecord(&address)
if err != nil {
log.Printf("[ipam] Failed to create address:%v err:%v.", address, err)
logger.Error("Failed to create", zap.Any("address", address), zap.Error(err))
continue
}
addressCount++
}
log.Printf("[ipam] got %d addresses from interface %s, subnet %s", addressCount, ifName, subnet)
logger.Info("got addresses from interface subnet", zap.Int("addressCount", addressCount), zap.String("ifName", ifName), zap.Any("subnet", subnet))
}
}

Expand Down
12 changes: 6 additions & 6 deletions ipam/fileIpam.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"strings"

"github.com/Azure/azure-container-networking/common"
"github.com/Azure/azure-container-networking/log"
"go.uber.org/zap"
)

const (
Expand Down Expand Up @@ -116,7 +116,7 @@ func (source *fileIpamSource) refresh() error {
return err
}

log.Printf("[ipam] Address space successfully populated from config file")
logger.Info("Address space successfully populated from config file")
source.fileLoaded = true

return nil
Expand Down Expand Up @@ -150,7 +150,7 @@ func populateAddressSpace(localAddressSpace *addressSpace, sdnInterfaces *Networ

// Skip if interface is not found.
if ifName == "" {
log.Printf("[ipam] Failed to find interface with MAC address:%v", sdnIf.MacAddress)
logger.Info("Failed to find interface with", zap.String("MAC Address", sdnIf.MacAddress))
continue
}

Expand All @@ -163,13 +163,13 @@ func populateAddressSpace(localAddressSpace *addressSpace, sdnInterfaces *Networ
for _, subnet := range sdnIf.IPSubnets {
_, network, err := net.ParseCIDR(subnet.Prefix)
if err != nil {
log.Printf("[ipam] Failed to parse subnet:%v err:%v.", subnet.Prefix, err)
logger.Error("Failed to parse subnet", zap.String("prefix", subnet.Prefix), zap.Error(err))
continue
}

addressPool, err := localAddressSpace.newAddressPool(ifName, priority, network)
if err != nil {
log.Printf("[ipam] Failed to create pool:%v ifName:%v err:%v.", subnet, ifName, err)
logger.Error("Failed to create pool", zap.Any("subnet", subnet), zap.String("ifName", ifName), zap.Error(err))
continue
}

Expand All @@ -184,7 +184,7 @@ func populateAddressSpace(localAddressSpace *addressSpace, sdnInterfaces *Networ

_, err = addressPool.newAddressRecord(&address)
if err != nil {
log.Printf("[ipam] Failed to create address:%v err:%v.", address, err)
logger.Error("Failed to create", zap.Any("address", address), zap.Error(err))
continue
}
}
Expand Down
Loading