-
Notifications
You must be signed in to change notification settings - Fork 242
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement zap for cni #1933
Merged
Merged
implement zap for cni #1933
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
13013aa
feat: added logger package and replaced old log initialization for th…
29fefec
feat: changed all log lines to new zap logger
0f3ff39
fix: typo
3283cb4
Update azure-ipam/logger/logger.go
estebancams 70b1a94
fix: adding constants to describe logger rotations constraints
02ea33a
Renamed logger New method
3965710
Replaced logAndSend method by log 1st and send then so we can use zap…
555233e
minor fixes
604e0ef
added logger init for tests
87c8b7f
replaced Any by Error
4990b3d
gci ipam_test
789d4c0
fixed govet errors
a3f49b9
moved component to a zap field
8d14f0b
fixed linit issues
3c0a03d
added log mock
9f108ce
fix: gci
d703324
fix: added context for logger teardown
f20773e
Update cni/log/logger.go
estebancams 89ccfd5
moved logger init mock function
8f3e413
fix: lint findings
estebancams File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,13 +9,14 @@ import ( | |
"strconv" | ||
|
||
"github.com/Azure/azure-container-networking/cni" | ||
"github.com/Azure/azure-container-networking/cni/log" | ||
"github.com/Azure/azure-container-networking/common" | ||
"github.com/Azure/azure-container-networking/ipam" | ||
"github.com/Azure/azure-container-networking/log" | ||
"github.com/Azure/azure-container-networking/platform" | ||
cniSkel "github.com/containernetworking/cni/pkg/skel" | ||
cniTypes "github.com/containernetworking/cni/pkg/types" | ||
cniTypesCurr "github.com/containernetworking/cni/pkg/types/100" | ||
"go.uber.org/zap" | ||
) | ||
|
||
const ipamV6 = "azure-vnet-ipamv6" | ||
|
@@ -61,22 +62,29 @@ func (plugin *ipamPlugin) Start(config *common.PluginConfig) error { | |
// Initialize base plugin. | ||
err := plugin.Initialize(config) | ||
if err != nil { | ||
log.Printf("[cni-ipam] Failed to initialize base plugin, err:%v.", err) | ||
log.Logger.Error("Failed to initialize base plugin.", | ||
zap.Error(err), zap.String("component", "cni-ipam")) | ||
return err | ||
} | ||
|
||
// Log platform information. | ||
log.Printf("[cni-ipam] Plugin %v version %v.", plugin.Name, plugin.Version) | ||
log.Printf("[cni-ipam] Running on %v", platform.GetOSInfo()) | ||
log.Logger.Info("Plugin version.", zap.String("name", plugin.Name), | ||
zap.String("version", plugin.Version), | ||
zap.String("component", "cni-ipam")) | ||
log.Logger.Info("Running on", | ||
zap.String("platform", platform.GetOSInfo()), | ||
zap.String("component", "cni-ipam")) | ||
|
||
// Initialize address manager. rehyrdration not required on reboot for cni ipam plugin | ||
err = plugin.am.Initialize(config, false, plugin.Options) | ||
if err != nil { | ||
log.Printf("[cni-ipam] Failed to initialize address manager, err:%v.", err) | ||
log.Logger.Error("Failed to initialize address manager", | ||
zap.String("error", err.Error()), | ||
zap.String("component", "cni-ipam")) | ||
return err | ||
} | ||
|
||
log.Printf("[cni-ipam] Plugin started.") | ||
log.Logger.Info("Plugin started", zap.String("component", "cni-ipam")) | ||
|
||
return nil | ||
} | ||
|
@@ -85,7 +93,7 @@ func (plugin *ipamPlugin) Start(config *common.PluginConfig) error { | |
func (plugin *ipamPlugin) Stop() { | ||
plugin.am.Uninitialize() | ||
plugin.Uninitialize() | ||
log.Printf("[cni-ipam] Plugin stopped.") | ||
log.Logger.Info("Plugin stopped", zap.String("component", "cni-ipam")) | ||
} | ||
|
||
// Configure parses and applies the given network configuration. | ||
|
@@ -96,7 +104,9 @@ func (plugin *ipamPlugin) Configure(stdinData []byte) (*cni.NetworkConfig, error | |
return nil, err | ||
} | ||
|
||
log.Printf("[cni-ipam] Read network configuration %+v.", nwCfg) | ||
log.Logger.Info("Read network configuration", | ||
zap.Any("config", nwCfg), | ||
zap.String("component", "cni-ipam")) | ||
|
||
// Apply IPAM configuration. | ||
|
||
|
@@ -135,10 +145,21 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error { | |
var result *cniTypesCurr.Result | ||
var err error | ||
|
||
log.Printf("[cni-ipam] Processing ADD command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}.", | ||
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData) | ||
log.Logger.Info("Processing ADD command", | ||
zap.String("ContainerId", args.ContainerID), | ||
zap.String("Netns", args.Netns), | ||
zap.String("IfName", args.IfName), | ||
zap.String("Args", args.Args), | ||
zap.String("Path", args.Path), | ||
zap.ByteString("StdinData", args.StdinData), | ||
zap.String("component", "cni-ipam")) | ||
|
||
defer func() { log.Printf("[cni-ipam] ADD command completed with result:%+v err:%v.", result, err) }() | ||
defer func() { | ||
log.Logger.Info("ADD command completed", | ||
zap.Any("result", result), | ||
zap.Any("error:", err), | ||
zap.String("component", "cni-ipam")) | ||
}() | ||
|
||
// Parse network configuration from stdin. | ||
nwCfg, err := plugin.Configure(args.StdinData) | ||
|
@@ -174,13 +195,18 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error { | |
// On failure, release the address pool. | ||
defer func() { | ||
if err != nil && poolID != "" { | ||
log.Printf("[cni-ipam] Releasing pool %v.", poolID) | ||
log.Logger.Info("Releasing pool", | ||
zap.String("poolId", poolID), | ||
zap.String("component", "cni-ipam")) | ||
_ = plugin.am.ReleasePool(nwCfg.IPAM.AddrSpace, poolID) | ||
} | ||
}() | ||
|
||
nwCfg.IPAM.Subnet = subnet | ||
log.Printf("[cni-ipam] Allocated address poolID %v with subnet %v.", poolID, subnet) | ||
log.Logger.Info("Allocated address with subnet", | ||
zap.String("poolId", poolID), | ||
zap.String("subnet", subnet), | ||
zap.String("component", "cni-ipam")) | ||
} | ||
|
||
// Allocate an address for the endpoint. | ||
|
@@ -193,12 +219,16 @@ func (plugin *ipamPlugin) Add(args *cniSkel.CmdArgs) error { | |
// On failure, release the address. | ||
defer func() { | ||
if err != nil && address != "" { | ||
log.Printf("[cni-ipam] Releasing address %v.", address) | ||
log.Logger.Info("Releasing address", | ||
zap.String("address", address), | ||
zap.String("component", "cni-ipam")) | ||
_ = plugin.am.ReleaseAddress(nwCfg.IPAM.AddrSpace, nwCfg.IPAM.Subnet, address, options) | ||
} | ||
}() | ||
|
||
log.Printf("[cni-ipam] Allocated address %v.", address) | ||
log.Logger.Info("Allocated address", | ||
zap.String("address", address), | ||
zap.String("component", "cni-ipam")) | ||
|
||
// Parse IP address. | ||
ipAddress, err := platform.ConvertStringToIPNet(address) | ||
|
@@ -263,10 +293,18 @@ func (plugin *ipamPlugin) Get(args *cniSkel.CmdArgs) error { | |
func (plugin *ipamPlugin) Delete(args *cniSkel.CmdArgs) error { | ||
var err error | ||
|
||
log.Printf("[cni-ipam] Processing DEL command with args {ContainerID:%v Netns:%v IfName:%v Args:%v Path:%v StdinData:%s}.", | ||
args.ContainerID, args.Netns, args.IfName, args.Args, args.Path, args.StdinData) | ||
log.Logger.Info("[cni-ipam] Processing DEL command", | ||
zap.String("ContainerId", args.ContainerID), | ||
zap.String("Netns", args.Netns), | ||
zap.String("IfName", args.IfName), | ||
zap.String("Args", args.Args), | ||
zap.String("Path", args.Path), | ||
zap.ByteString("StdinData", args.StdinData)) | ||
|
||
defer func() { log.Printf("[cni-ipam] DEL command completed with err:%v.", err) }() | ||
defer func() { | ||
log.Logger.Info("[cni-ipam] DEL command completed", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. move this There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
zap.Error(err)) | ||
}() | ||
|
||
// Parse network configuration from stdin. | ||
nwCfg, err := plugin.Configure(args.StdinData) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "poolID"