mirror of
https://github.com/k8snetworkplumbingwg/multus-cni.git
synced 2025-09-20 09:01:15 +00:00
Merge pull request #497 from s1061123/fix/improve-cni-logs
[WIP] Fix/improve cni logs
This commit is contained in:
@@ -159,7 +159,7 @@ func confAdd(rt *libcni.RuntimeConf, rawNetconf []byte, binDir string, exec invo
|
|||||||
|
|
||||||
result, err := cniNet.AddNetwork(context.Background(), conf, rt)
|
result, err := cniNet.AddNetwork(context.Background(), conf, rt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, logging.Errorf("error in getting result from AddNetwork: %v", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
@@ -219,7 +219,7 @@ func conflistAdd(rt *libcni.RuntimeConf, rawnetconflist []byte, binDir string, e
|
|||||||
|
|
||||||
result, err := cniNet.AddNetworkList(context.Background(), confList, rt)
|
result, err := cniNet.AddNetworkList(context.Background(), confList, rt)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, logging.Errorf("conflistAdd: error in getting result from AddNetworkList: %v", err)
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
@@ -319,12 +319,12 @@ func delegateAdd(exec invoke.Exec, kubeClient *k8s.ClientInfo, pod *v1.Pod, ifNa
|
|||||||
if delegate.ConfListPlugin {
|
if delegate.ConfListPlugin {
|
||||||
result, err = conflistAdd(rt, delegate.Bytes, binDir, exec)
|
result, err = conflistAdd(rt, delegate.Bytes, binDir, exec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, logging.Errorf("delegateAdd: error invoking conflistAdd - %q: %v", delegate.ConfList.Name, err)
|
return nil, err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
result, err = confAdd(rt, delegate.Bytes, binDir, exec)
|
result, err = confAdd(rt, delegate.Bytes, binDir, exec)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, logging.Errorf("delegateAdd: error invoking confAdd - %q: %v", delegate.Conf.Type, err)
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -470,6 +470,14 @@ func cmdErr(k8sArgs *types.K8sArgs, format string, args ...interface{}) error {
|
|||||||
return logging.Errorf(prefix+format, args...)
|
return logging.Errorf(prefix+format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func cmdPluginErr(k8sArgs *types.K8sArgs, confName string, format string, args ...interface{}) error {
|
||||||
|
msg := ""
|
||||||
|
if k8sArgs != nil {
|
||||||
|
msg += fmt.Sprintf("[%s/%s:%s]: ", k8sArgs.K8S_POD_NAMESPACE, k8sArgs.K8S_POD_NAME, confName)
|
||||||
|
}
|
||||||
|
return logging.Errorf(msg+format, args...)
|
||||||
|
}
|
||||||
|
|
||||||
func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (cnitypes.Result, error) {
|
func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (cnitypes.Result, error) {
|
||||||
n, err := types.LoadNetConf(args.StdinData)
|
n, err := types.LoadNetConf(args.StdinData)
|
||||||
logging.Debugf("cmdAdd: %v, %v, %v", args, exec, kubeClient)
|
logging.Debugf("cmdAdd: %v, %v, %v", args, exec, kubeClient)
|
||||||
@@ -533,7 +541,7 @@ func cmdAdd(args *skel.CmdArgs, exec invoke.Exec, kubeClient *k8s.ClientInfo) (c
|
|||||||
}
|
}
|
||||||
// Ignore errors; DEL must be idempotent anyway
|
// Ignore errors; DEL must be idempotent anyway
|
||||||
_ = delPlugins(exec, nil, args.IfName, n.Delegates, idx, rt, n.BinDir)
|
_ = delPlugins(exec, nil, args.IfName, n.Delegates, idx, rt, n.BinDir)
|
||||||
return nil, cmdErr(k8sArgs, "error adding container to network %q: %v", netName, err)
|
return nil, cmdPluginErr(k8sArgs, netName, "error adding container to network %q: %v", netName, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove gateway from routing table if the gateway is not used
|
// Remove gateway from routing table if the gateway is not used
|
||||||
|
@@ -1226,7 +1226,7 @@ var _ = Describe("multus operations cniVersion 0.2.0 config", func() {
|
|||||||
_, err = cmdAdd(args, fExec, nil)
|
_, err = cmdAdd(args, fExec, nil)
|
||||||
Expect(fExec.addIndex).To(Equal(2))
|
Expect(fExec.addIndex).To(Equal(2))
|
||||||
Expect(fExec.delIndex).To(Equal(2))
|
Expect(fExec.delIndex).To(Equal(2))
|
||||||
Expect(err).To(MatchError("Multus: [/]: error adding container to network \"other1\": delegateAdd: error invoking confAdd - \"other-plugin\": error in getting result from AddNetwork: expected plugin failure"))
|
Expect(err).To(MatchError("[/:other1]: error adding container to network \"other1\": expected plugin failure"))
|
||||||
|
|
||||||
// Cleanup default network file.
|
// Cleanup default network file.
|
||||||
if _, errStat := os.Stat(configPath); errStat == nil {
|
if _, errStat := os.Stat(configPath); errStat == nil {
|
||||||
@@ -2464,7 +2464,7 @@ var _ = Describe("multus operations cniVersion 0.4.0 config", func() {
|
|||||||
_, err = cmdAdd(args, fExec, nil)
|
_, err = cmdAdd(args, fExec, nil)
|
||||||
Expect(fExec.addIndex).To(Equal(2))
|
Expect(fExec.addIndex).To(Equal(2))
|
||||||
Expect(fExec.delIndex).To(Equal(2))
|
Expect(fExec.delIndex).To(Equal(2))
|
||||||
Expect(err).To(MatchError("Multus: [/]: error adding container to network \"other1\": delegateAdd: error invoking confAdd - \"other-plugin\": error in getting result from AddNetwork: expected plugin failure"))
|
Expect(err).To(MatchError("[/:other1]: error adding container to network \"other1\": expected plugin failure"))
|
||||||
|
|
||||||
// Cleanup default network file.
|
// Cleanup default network file.
|
||||||
if _, errStat := os.Stat(configPath); errStat == nil {
|
if _, errStat := os.Stat(configPath); errStat == nil {
|
||||||
|
Reference in New Issue
Block a user