From 1c75a46d75a81377db9a44fc76abc7da132de48b Mon Sep 17 00:00:00 2001 From: Matthew Endsley Date: Thu, 21 Nov 2024 20:29:39 -0800 Subject: [PATCH] Only handle valid CNI_ARGS If arguments fail to parse, continue without additional endpoint configuration. --- common/core/network.go | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/common/core/network.go b/common/core/network.go index a8fa157c..3a6e880f 100644 --- a/common/core/network.go +++ b/common/core/network.go @@ -105,12 +105,6 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) (resultError error) { k8sNamespace = string(podConfig.K8S_POD_NAMESPACE) } - epConfig, err := cni.ParseCniEndpointArgs(args.Args) - if err != nil { - logrus.Errorf("[cni-net] Failed to parse endpoint args, err:%v", err) - return err - } - // Parse network configuration from stdin. cniConfig, err := cni.ParseNetworkConfig(args.StdinData) if err != nil { @@ -139,14 +133,17 @@ func (plugin *netPlugin) Add(args *cniSkel.CmdArgs) (resultError error) { return err } - if epConfig.MAC != "" { - hwAddr, err := net.ParseMAC(string(epConfig.MAC)) - if err != nil { - logrus.Errorf("[cni-net] Failed to parse MAC addres '%s', err:%v", epConfig.MAC, err) - return err - } + epConfig, err := cni.ParseCniEndpointArgs(args.Args) + if err == nil { + if epConfig.MAC != "" { + hwAddr, err := net.ParseMAC(string(epConfig.MAC)) + if err != nil { + logrus.Errorf("[cni-net] Failed to parse MAC addres '%s', err:%v", epConfig.MAC, err) + return err + } - epInfo.MacAddress = hwAddr + epInfo.MacAddress = hwAddr + } } epInfo.DualStack = cniConfig.OptionalFlags.EnableDualStack