diff --git a/cni/ipam/ipam.go b/cni/ipam/ipam.go index 73777b9334..dfd78ddcd3 100644 --- a/cni/ipam/ipam.go +++ b/cni/ipam/ipam.go @@ -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), @@ -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)) }() diff --git a/cni/network/network.go b/cni/network/network.go index f958031213..09cc38792a 100644 --- a/cni/network/network.go +++ b/cni/network/network.go @@ -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 } @@ -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), @@ -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)) @@ -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 @@ -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())) @@ -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()) @@ -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{ @@ -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 } @@ -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 { @@ -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), @@ -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)) }() @@ -883,14 +883,14 @@ 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)) } @@ -898,7 +898,7 @@ func (plugin *NetPlugin) Get(args *cniSkel.CmdArgs) error { // 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 } @@ -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), @@ -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)) }() @@ -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, "") @@ -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)) @@ -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) @@ -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. @@ -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)", @@ -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)) @@ -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, "") @@ -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 } diff --git a/ipam/azure.go b/ipam/azure.go index 67371093a5..1f73a23a19 100644 --- a/ipam/azure.go +++ b/ipam/azure.go @@ -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" @@ -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) } @@ -138,7 +141,7 @@ 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 } @@ -146,13 +149,13 @@ func (s *azureSource) refresh() error { 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 } @@ -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)) } } diff --git a/ipam/fileIpam.go b/ipam/fileIpam.go index 85a98c9103..25f668c433 100644 --- a/ipam/fileIpam.go +++ b/ipam/fileIpam.go @@ -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 ( @@ -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 @@ -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 } @@ -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 } @@ -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 } } diff --git a/ipam/ipv6Ipam.go b/ipam/ipv6Ipam.go index a69350feb1..603c03e550 100644 --- a/ipam/ipv6Ipam.go +++ b/ipam/ipv6Ipam.go @@ -10,8 +10,8 @@ import ( "strings" "github.com/Azure/azure-container-networking/common" - "github.com/Azure/azure-container-networking/log" "github.com/Masterminds/semver" + "go.uber.org/zap" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/version" @@ -89,13 +89,13 @@ func (source *ipv6IpamSource) stop() { func (source *ipv6IpamSource) loadKubernetesConfig() (kubernetes.Interface, error) { config, err := clientcmd.BuildConfigFromFlags("", source.kubeConfigPath) if err != nil { - log.Printf("[ipam] Failed to load Kubernetes config from disk: %+v", err) + logger.Error("Failed to load Kubernetes config from disk", zap.Error(err)) return nil, err } client, err := kubernetes.NewForConfig(config) if err != nil { - log.Printf("[ipam] Failed to create Kubernetes config: %+v", err) + logger.Error("Failed to create Kubernetes config", zap.Error(err)) return nil, err } @@ -106,7 +106,7 @@ func (source *ipv6IpamSource) loadKubernetesConfig() (kubernetes.Interface, erro serverVersion, err := client.ServerVersion() if err != nil { - log.Printf("[ipam] Failed to retrieve Kubernetes version: %+v", err) + logger.Error("Failed to retrieve Kubernetes version", zap.Error(err)) return nil, err } @@ -153,14 +153,14 @@ func (source *ipv6IpamSource) refresh() error { } if source.isLoaded { - log.Printf("ipv6 source already loaded") + logger.Info("ipv6 source already loaded") return nil } if source.kubeClient == nil { kubeClient, err := source.loadKubernetesConfig() if err != nil { - log.Printf("[ipam] Failed to load Kubernetes config: %+v", err) + logger.Error("Failed to load Kubernetes config", zap.Error(err)) return err } @@ -169,24 +169,24 @@ func (source *ipv6IpamSource) refresh() error { kubeNode, err := source.kubeClient.CoreV1().Nodes().Get(context.TODO(), source.nodeHostname, metav1.GetOptions{}) if err != nil { - log.Printf("[ipam] Failed to retrieve node using hostname: %+v with err %+v", source.nodeHostname, err) + logger.Error("Failed to retrieve node using", zap.String("hostName", source.nodeHostname), zap.Error(err)) return err } source.kubeNode = kubeNode - log.Printf("[ipam] Discovered CIDR's %v.", source.kubeNode.Spec.PodCIDRs) + logger.Info("Discovered", zap.Any("CIDR's", source.kubeNode.Spec.PodCIDRs)) // Query the list of Kubernetes Pod IPs interfaceIPs, err := retrieveKubernetesPodIPs(source.kubeNode, source.subnetMaskSizeLimit) if err != nil { - log.Printf("[ipam] Failed retrieve Kubernetes IP's from subnet: %v.", err) + logger.Error("Failed retrieve Kubernetes IP's from subnet", zap.Error(err)) return err } // Configure the local default address space. local, err := source.sink.newAddressSpace(LocalDefaultAddressSpaceId, LocalScope) if err != nil { - log.Printf("[ipam] Failed to configure local default address space: %v.", err) + logger.Error("Failed to configure local default address space", zap.Error(err)) return err } @@ -201,7 +201,7 @@ func (source *ipv6IpamSource) refresh() error { address := net.ParseIP(a.Address) _, 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 } } @@ -214,7 +214,7 @@ func (source *ipv6IpamSource) refresh() error { } source.isLoaded = true - log.Printf("[ipam] Address space successfully populated from Kubernetes API Server") + logger.Info("Address space successfully populated from Kubernetes API Server") return err } diff --git a/ipam/manager.go b/ipam/manager.go index 710ce21305..85156060f4 100644 --- a/ipam/manager.go +++ b/ipam/manager.go @@ -8,9 +8,9 @@ import ( "time" "github.com/Azure/azure-container-networking/common" - "github.com/Azure/azure-container-networking/log" "github.com/Azure/azure-container-networking/platform" "github.com/Azure/azure-container-networking/store" + "go.uber.org/zap" ) const ( @@ -96,7 +96,7 @@ func (am *addressManager) Uninitialize() { func (am *addressManager) restore(rehydrateIpamInfoOnReboot bool) error { // Skip if a store is not provided. if am.store == nil { - log.Printf("[ipam] ipam store is nil") + logger.Info("ipam store is nil") return nil } @@ -104,13 +104,13 @@ func (am *addressManager) restore(rehydrateIpamInfoOnReboot bool) error { err := am.store.Read(storeKey, am) if err != nil { if err == store.ErrKeyNotFound { - log.Printf("[ipam] store key not found") + logger.Info("store key not found") return nil } else if err == store.ErrStoreEmpty { - log.Printf("[ipam] store empty") + logger.Info("store empty") return nil } else { - log.Printf("[ipam] Failed to restore state, err:%v\n", err) + logger.Error("Failed to restore state", zap.Error(err)) return err } } @@ -136,10 +136,10 @@ func (am *addressManager) restore(rehydrateIpamInfoOnReboot bool) error { if err == nil { p := platform.NewExecClient(nil) rebootTime, err := p.GetLastRebootTime() - log.Printf("[ipam] reboot time %v store mod time %v", rebootTime, modTime) + logger.Info("reboot store mod", zap.Any("rebootTime", rebootTime), zap.Any("modTime", modTime)) if err == nil && rebootTime.After(modTime) { - log.Printf("[ipam] Rehydrating ipam state from persistent store") + logger.Info("Rehydrating ipam state from persistent store") for _, as := range am.AddrSpaces { for _, ap := range as.Pools { ap.as = as @@ -154,7 +154,7 @@ func (am *addressManager) restore(rehydrateIpamInfoOnReboot bool) error { } } - log.Printf("[ipam] Restored state, %+v\n", am) + logger.Info("Restored state", zap.Any("am", am)) return nil } @@ -163,19 +163,19 @@ func (am *addressManager) restore(rehydrateIpamInfoOnReboot bool) error { func (am *addressManager) save() error { // Skip if a store is not provided. if am.store == nil { - log.Printf("[ipam] ipam store is nil.\n") + logger.Info("ipam store is nil") return nil } // Update time stamp. am.TimeStamp = time.Now() - log.Printf("[ipam] saving ipam state.\n") + logger.Info("saving ipam state") err := am.store.Write(storeKey, am) if err == nil { - log.Printf("[ipam] Save succeeded.\n") + logger.Info("Save succeeded") } else { - log.Printf("[ipam] Save failed, err:%v\n", err) + logger.Error("Save failed", zap.Error(err)) } return err } @@ -216,12 +216,12 @@ func (am *addressManager) StartSource(options map[string]interface{}) error { } if am.source != nil { - log.Printf("[ipam] Starting source %v.", environment) + logger.Info("Starting source", zap.String("environment", environment)) err = am.source.start(am) } if err != nil { - log.Printf("[ipam] Failed to start source %v, err:%v.", environment, err) + logger.Error("Failed to start source", zap.String("environment", environment), zap.Error(err)) } return err @@ -238,10 +238,10 @@ func (am *addressManager) StopSource() { // Signals configuration source to refresh. func (am *addressManager) refreshSource() { if am.source != nil { - log.Printf("[ipam] Refreshing address source.") + logger.Info("Refreshing address source.") err := am.source.refresh() if err != nil { - log.Printf("[ipam] Source refresh failed, err:%v.\n", err) + logger.Error("Source refresh failed", zap.Error(err)) } } } diff --git a/ipam/pool.go b/ipam/pool.go index d61142986c..e0e2d60c29 100644 --- a/ipam/pool.go +++ b/ipam/pool.go @@ -8,8 +8,8 @@ import ( "net" "strings" - "github.com/Azure/azure-container-networking/log" "github.com/Azure/azure-container-networking/platform" + "go.uber.org/zap" ) const ( @@ -161,7 +161,7 @@ func (am *addressManager) setAddressSpace(as *addressSpace) error { } else { // merges the address set refreshed from the source // and the ones we have currently in this address space - log.Printf("[ipam] merging address space") + logger.Info("merging address space") as1.merge(as) } @@ -293,7 +293,7 @@ func (as *addressSpace) requestPool(poolId string, subPoolId string, options map var ap *addressPool var err error - log.Printf("[ipam] Requesting pool with poolId:%v options:%+v v6:%v.", poolId, options, v6) + logger.Info("Requesting pool with", zap.String("poolId", poolId), zap.Any("options", options), zap.Any("v6", v6)) if poolId != "" { // Return the specific address pool requested. @@ -307,11 +307,11 @@ func (as *addressSpace) requestPool(poolId string, subPoolId string, options map ifName := options[OptInterfaceName] for _, pool := range as.Pools { - log.Printf("[ipam] Checking pool %v.", pool.Id) + logger.Info("Checking pool", zap.String("id", pool.Id)) // Skip if pool is already in use. if pool.isInUse() { - log.Printf("[ipam] Pool %s is in use.", pool.Id) + logger.Info("Pool is in use", zap.String("id", pool.Id)) // in case the pool is actually not in use, // attempt to release it @@ -323,17 +323,17 @@ func (as *addressSpace) requestPool(poolId string, subPoolId string, options map // Pick a pool from the same address family. if pool.IsIPv6 != v6 { - log.Printf("[ipam] Pool is of a different address family.") + logger.Info("Pool is of a different address family") continue } // Skip if pool is not on the requested interface. if ifName != "" && ifName != pool.IfName { - log.Printf("[ipam] Pool is not on the requested interface.") + logger.Info("Pool is not on the requested interface") continue } - log.Printf("[ipam] Pool %v matches requirements.", pool.Id) + logger.Info("Pool matches requirements", zap.String("id", pool.Id)) if ap == nil { ap = pool @@ -342,13 +342,13 @@ func (as *addressSpace) requestPool(poolId string, subPoolId string, options map // Prefer the pool with the highest priority. if pool.Priority > ap.Priority { - log.Printf("[ipam] Pool is preferred because of priority.") + logger.Info("Pool is preferred because of priority") ap = pool } // Prefer the pool with the highest number of addresses. if len(pool.Addresses) > len(ap.Addresses) { - log.Printf("[ipam] Pool is preferred because of capacity.") + logger.Info("Pool is preferred because of capacity") ap = pool } } @@ -362,7 +362,7 @@ func (as *addressSpace) requestPool(poolId string, subPoolId string, options map ap.RefCount = 1 } - log.Printf("[ipam] Pool request completed with pool:%+v err:%v.", ap, err) + logger.Info("Pool request completed with pool", zap.Any("ap", ap), zap.Error(err)) return ap, err } @@ -377,17 +377,15 @@ func (as *addressSpace) releasePool(poolId string) error { } if addressesInUse = ap.IsAnyRecordInUse(); addressesInUse { - log.Printf("[ipam] Skip releasing pool with poolId:%s. due to address being in use", - poolId) + logger.Info("Skip releasing pool with due to address being in use", zap.String("poolId", poolId)) } else { - log.Printf("[ipam] Releasing pool %s as there are no allocations", poolId) + logger.Info("Releasing pool as there are no allocations", zap.String("poolId", poolId)) ap.RefCount = 0 } return nil } -// // AddressPool // // Returns address pool information. @@ -461,19 +459,19 @@ func (ap *addressPool) requestAddress(address string, options map[string]string) var addr *net.IPNet id := options[OptAddressID] - log.Printf("[ipam] Requesting address with address:%v options:%+v.", address, options) + logger.Info("Requesting address with", zap.String("address", address), zap.Any("options", options)) if address != "" { // Return the specific address requested. ar = ap.Addresses[address] if ar == nil { - log.Printf("[ipam] Address request failed with %v", errAddressNotFound) + logger.Error("Address request failed with", zap.Error(errAddressNotFound)) return "", errAddressNotFound } if ar.InUse { // Return the same address if IDs match. if id == "" || id != ar.ID { - log.Printf("[ipam] Address request failed with %v", errAddressInUse) + logger.Error("Address request failed with", zap.Error(errAddressInUse)) return "", errAddressInUse } } @@ -498,7 +496,7 @@ func (ap *addressPool) requestAddress(address string, options map[string]string) } if ar == nil { - log.Printf("[ipam] Address request failed with %v", errNoAvailableAddresses) + logger.Error("Address request failed with", zap.Error(errNoAvailableAddresses)) return "", errNoAvailableAddresses } } @@ -516,7 +514,7 @@ func (ap *addressPool) requestAddress(address string, options map[string]string) Mask: ap.Subnet.Mask, } - log.Printf("[ipam] Address request completed with address:%v", addr) + logger.Info("Address request completed with", zap.Any("address", addr)) return addr.String(), nil } @@ -527,8 +525,8 @@ func (ap *addressPool) releaseAddress(address string, options map[string]string) var id string var err error - log.Printf("[ipam] Releasing address with address:%v options:%+v.", address, options) - defer func() { log.Printf("[ipam] Address release completed with address:%v err:%v.", address, err) }() + logger.Info("Releasing address with", zap.String("address", address), zap.Any("options", options)) + defer func() { logger.Error("Address release completed with", zap.String("address", address), zap.Error(err)) }() if options != nil { id = options[OptAddressID] @@ -552,12 +550,12 @@ func (ap *addressPool) releaseAddress(address string, options map[string]string) // Fail if an address record with a matching ID is not found. if ar == nil || (id != "" && id != ar.ID) { - log.Printf("Address not found. Not Returning error") + logger.Info("Address not found. Not Returning error") return nil } if !ar.InUse { - log.Printf("Address not in use. Not Returning error") + logger.Info("Address not in use. Not Returning error") return nil } @@ -570,7 +568,7 @@ func (ap *addressPool) releaseAddress(address string, options map[string]string) // Delete address record if it is no longer available. if ar.epoch < ap.as.epoch { - log.Printf("Deleting Address record from address pool as metadata doesn't have this address") + logger.Info("Deleting Address record from address pool as metadata doesn't have this address") delete(ap.Addresses, address) } diff --git a/network/transparent_vlan_endpointclient_linux.go b/network/transparent_vlan_endpointclient_linux.go index 795832a8ce..19363bbfb0 100644 --- a/network/transparent_vlan_endpointclient_linux.go +++ b/network/transparent_vlan_endpointclient_linux.go @@ -7,7 +7,6 @@ import ( "time" "github.com/Azure/azure-container-networking/iptables" - "github.com/Azure/azure-container-networking/log" "github.com/Azure/azure-container-networking/netio" "github.com/Azure/azure-container-networking/netlink" "github.com/Azure/azure-container-networking/netns" @@ -480,7 +479,7 @@ func (client *TransparentVlanEndpointClient) GetVnetRoutes(ipAddresses []net.IPN } else { ipNet = net.IPNet{IP: ipAddr.IP, Mask: net.CIDRMask(ipv6FullMask, ipv6Bits)} } - log.Printf("[net] Getting route for this ip %v", ipNet.String()) + logger.Info("Getting route for this", zap.String("ip", ipNet.String())) routeInfo.Dst = ipNet routeInfoList = append(routeInfoList, routeInfo) diff --git a/ovsctl/ovsctl.go b/ovsctl/ovsctl.go index bdca8de8cc..24ecd7f0ab 100644 --- a/ovsctl/ovsctl.go +++ b/ovsctl/ovsctl.go @@ -255,14 +255,14 @@ func (o Ovsctl) DeleteArpReplyRule(bridgeName, port string, ip net.IP, vlanid in bridgeName, port) _, err := o.execcli.ExecuteCommand(cmd) if err != nil { - logger.Error("[net] Deleting ARP reply rule failed with", zap.Error(err)) + logger.Error("Deleting ARP reply rule failed with", zap.Error(err)) } cmd = fmt.Sprintf("ovs-ofctl del-flows %s table=1,arp,arp_tpa=%s,dl_vlan=%v,arp_op=1", bridgeName, ip.String(), vlanid) _, err = o.execcli.ExecuteCommand(cmd) if err != nil { - logger.Error("[net] Deleting ARP reply rule failed with", zap.Error(err)) + logger.Error("Deleting ARP reply rule failed with", zap.Error(err)) } } @@ -288,7 +288,7 @@ func (o Ovsctl) DeleteMacDnatRule(bridgeName, port string, ip net.IP, vlanid int _, err := o.execcli.ExecuteCommand(cmd) if err != nil { - logger.Error("[net] Deleting MAC DNAT rule failed with", zap.Error(err)) + logger.Error("Deleting MAC DNAT rule failed with", zap.Error(err)) } }