From: Eric Chiang Date: Tue, 30 May 2017 00:28:59 +0000 (-0700) Subject: pkg/invoke: ensure that custom env vars are prepended to the env X-Git-Url: https://git.halfball.org/?a=commitdiff_plain;h=49fb84b284be5a7cc02f1ce0affbeb8ef3d03eb7;p=cni.git pkg/invoke: ensure that custom env vars are prepended to the env Ensure that custom values take priority over values defined in the environment by prepending them to the env, not appending. --- diff --git a/pkg/invoke/args.go b/pkg/invoke/args.go index ba9d0c3..39b6397 100644 --- a/pkg/invoke/args.go +++ b/pkg/invoke/args.go @@ -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 }