forked from github/multus-cni
Replace setenv with runtimeConfig set (#785)
setenv refers environment variables, which is unique in process, not unique to go routine. Hence it may causes some issue in multi threaded case, hence it is replaced with libcni's runtimeConfig value set to set these variables at libcni side, after process fork.
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/containernetworking/cni/libcni"
|
||||
@@ -208,6 +209,33 @@ func NewCNIRuntimeConf(containerID, sandboxID, podName, podNamespace, podUID, ne
|
||||
rt := CreateRuntimeConf(netNs, podNamespace, podName, containerID, sandboxID, podUID, ifName)
|
||||
|
||||
var cniDeviceInfoFile string
|
||||
|
||||
// get CNI_ARGS and set it if it does not exist in rt.Args
|
||||
cniArgs := os.Getenv("CNI_ARGS")
|
||||
if cniArgs != "" {
|
||||
for _, arg := range strings.Split(cniArgs, ";") {
|
||||
for _, keyval := range strings.Split(arg, "=") {
|
||||
if len(keyval) != 2 {
|
||||
logging.Errorf("CreateCNIRuntimeConf: CNI_ARGS %s %s %d is not recognized as CNI arg, skipped", arg, keyval, len(keyval))
|
||||
continue
|
||||
}
|
||||
|
||||
envKey := string(keyval[0])
|
||||
envVal := string(keyval[1])
|
||||
isExists := false
|
||||
for _, rtArg := range rt.Args {
|
||||
if rtArg[0] == envKey {
|
||||
isExists = true
|
||||
}
|
||||
}
|
||||
if isExists != false {
|
||||
logging.Debugf("CreateCNIRuntimeConf: add new val: %s", arg)
|
||||
rt.Args = append(rt.Args, [2]string{envKey, envVal})
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if delegateRc != nil {
|
||||
cniDeviceInfoFile = delegateRc.CNIDeviceInfoFile
|
||||
capabilityArgs := map[string]interface{}{}
|
||||
|
Reference in New Issue
Block a user