pkg/invoke: ensure that custom env vars are prepended to the env
authorEric Chiang <eric.chiang.m@gmail.com>
Tue, 30 May 2017 00:28:59 +0000 (17:28 -0700)
committerEric Chiang <eric.chiang.m@gmail.com>
Tue, 30 May 2017 00:32:49 +0000 (17:32 -0700)
Ensure that custom values take priority over values defined in the
environment by prepending them to the env, not appending.

pkg/invoke/args.go

index ba9d0c3..39b6397 100644 (file)
@@ -57,13 +57,16 @@ func (args *Args) AsEnv() []string {
                pluginArgsStr = stringify(args.PluginArgs)
        }
 
-       env = append(env,
-               "CNI_COMMAND="+args.Command,
-               "CNI_CONTAINERID="+args.ContainerID,
-               "CNI_NETNS="+args.NetNS,
-               "CNI_ARGS="+pluginArgsStr,
-               "CNI_IFNAME="+args.IfName,
-               "CNI_PATH="+args.Path)
+       // Ensure that the custom values are first, so any value present in
+       // the process environment won't override them.
+       env = append([]string{
+               "CNI_COMMAND=" + args.Command,
+               "CNI_CONTAINERID=" + args.ContainerID,
+               "CNI_NETNS=" + args.NetNS,
+               "CNI_ARGS=" + pluginArgsStr,
+               "CNI_IFNAME=" + args.IfName,
+               "CNI_PATH=" + args.Path,
+       }, env...)
        return env
 }