Skip to content

Commit

Permalink
Improve logging
Browse files Browse the repository at this point in the history
Signed-off-by: adrianc <adrianc@nvidia.com>
  • Loading branch information
adrianchiris committed May 3, 2023
1 parent 96aac53 commit 0a1f984
Showing 1 changed file with 12 additions and 15 deletions.
27 changes: 12 additions & 15 deletions pkg/cni/plugin/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,7 @@ func (p *Plugin) CmdAdd(args *skel.CmdArgs) error {
return fmt.Errorf("failed to load config: %w", err)
}
setupLog(conf.IPAM.LogFile, conf.IPAM.LogLevel)

log.Infof("CMD Add Called with args: %+v", args)
log.Infof("CMD Add Stdin data: %s", string(args.StdinData))
logCall("ADD", args, conf.IPAM)

// build host-local config
pool, err := getPoolbyName(conf.IPAM.K8sClient, conf.IPAM.NodeName, conf.IPAM.PoolName)
Expand All @@ -71,8 +69,7 @@ func (p *Plugin) CmdAdd(args *skel.CmdArgs) error {
if err != nil {
return fmt.Errorf("failed to marshal host-local net conf. %w", err)
}

log.Infof("host-local stdin data:%s", string(data))
log.Debugf("host-local stdin data:%q", string(data))

// call host-local cni with alternate path
err = os.Setenv("CNI_PATH", filepath.Join(conf.IPAM.DataDir, "bin"))
Expand All @@ -93,9 +90,7 @@ func (p *Plugin) CmdDel(args *skel.CmdArgs) error {
return fmt.Errorf("failed to load config: %w", err)
}
setupLog(conf.IPAM.LogFile, conf.IPAM.LogLevel)

log.Infof("CMD Del Called with args: %+v", args)
log.Infof("CMD Del Stdin data: %s", string(args.StdinData))
logCall("DEL", args, conf.IPAM)

// build host-local config
pool, err := getPoolbyName(conf.IPAM.K8sClient, conf.IPAM.NodeName, conf.IPAM.PoolName)
Expand All @@ -108,8 +103,7 @@ func (p *Plugin) CmdDel(args *skel.CmdArgs) error {
if err != nil {
return fmt.Errorf("failed to marshal host-local net conf. %w", err)
}

log.Infof("host-local stdin data:%s", string(data))
log.Debugf("host-local stdin data:%q", string(data))

// call host-local cni with alternate path
err = os.Setenv("CNI_PATH", filepath.Join(conf.IPAM.DataDir, "bin"))
Expand All @@ -130,9 +124,7 @@ func (p *Plugin) CmdCheck(args *skel.CmdArgs) error {
return fmt.Errorf("failed to load config: %w", err)
}
setupLog(conf.IPAM.LogFile, conf.IPAM.LogLevel)

log.Infof("CMD Check Called with args: %+v", args)
log.Infof("CMD Check Stdin data: %s", string(args.StdinData))
logCall("CHECK", args, conf.IPAM)

// build host-local config
pool, err := getPoolbyName(conf.IPAM.K8sClient, conf.IPAM.NodeName, conf.IPAM.PoolName)
Expand All @@ -145,8 +137,7 @@ func (p *Plugin) CmdCheck(args *skel.CmdArgs) error {
if err != nil {
return fmt.Errorf("failed to marshal host-local net conf. %w", err)
}

log.Infof("host-local stdin data:%s", string(data))
log.Debugf("host-local stdin data:%q", string(data))

// call host-local cni with alternate path
err = os.Setenv("CNI_PATH", filepath.Join(conf.IPAM.DataDir, "bin"))
Expand All @@ -172,6 +163,12 @@ func setupLog(logFile, logLevel string) {
}
}

func logCall(cmd string, args *skel.CmdArgs, conf *types.IPAMConf) {
log.Infof("CMD %s Call: ContainerID:%s Netns:%s IfName:%s", cmd, args.ContainerID, args.Netns, args.IfName)
log.Debugf("CMD %s: Args:%s StdinData:%q", cmd, args.Args, string(args.StdinData))
log.Debugf("CMD %s: Parsed IPAM conf:%+v", cmd, conf)
}

func getPoolbyName(kclient *kubernetes.Clientset, nodeName, poolName string) (*pool.IPPool, error) {
// get pool info from node
node, err := kclient.CoreV1().Nodes().Get(context.TODO(), nodeName, metav1.GetOptions{})
Expand Down

0 comments on commit 0a1f984

Please sign in to comment.