From 49fb84b284be5a7cc02f1ce0affbeb8ef3d03eb7 Mon Sep 17 00:00:00 2001 From: Eric Chiang Date: Mon, 29 May 2017 17:28:59 -0700 Subject: [PATCH] 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. --- pkg/invoke/args.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) 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 } -- 2.44.0