From 3801a29d9b24683641ae3cf1707835bcccfdc3c2 Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Thu, 27 Aug 2020 12:24:22 -0700 Subject: [PATCH] add --fn-env flag to fn run --- cmd/config/internal/commands/run-fns.go | 5 +++++ cmd/config/internal/commands/run_test.go | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/cmd/config/internal/commands/run-fns.go b/cmd/config/internal/commands/run-fns.go index ad8f4078e..f34ec7ad7 100644 --- a/cmd/config/internal/commands/run-fns.go +++ b/cmd/config/internal/commands/run-fns.go @@ -67,6 +67,9 @@ func GetRunFnRunner(name string) *RunFnRunner { "a list of storage options read from the filesystem") r.Command.Flags().StringVar( &r.User, "fn-user", "nobody", "the username/uid used to run function in container") + r.Command.Flags().StringArrayVar( + &r.Env, "fn-env", []string{}, + "a list of environment variables that will be exposed to container. Each item can be key=value pair or a key name of exported env.") return r } @@ -94,6 +97,7 @@ type RunFnRunner struct { NetworkName string Mounts []string User string + Env []string } func (r *RunFnRunner) runE(c *cobra.Command, args []string) error { @@ -309,6 +313,7 @@ func (r *RunFnRunner) preRunE(c *cobra.Command, args []string) error { StorageMounts: storageMounts, ResultsDir: r.ResultsDir, User: runtimeutil.ContainerUser(r.User), + Env: r.Env, } // don't consider args for the function diff --git a/cmd/config/internal/commands/run_test.go b/cmd/config/internal/commands/run_test.go index 7adbb4e8b..b4eadacab 100644 --- a/cmd/config/internal/commands/run_test.go +++ b/cmd/config/internal/commands/run_test.go @@ -204,6 +204,7 @@ apiVersion: v1 NetworkName: "bridge", EnableStarlark: true, User: "nobody", + Env: []string{}, }, }, { @@ -258,6 +259,7 @@ apiVersion: v1 NetworkName: "bridge", ResultsDir: "foo/", User: "nobody", + Env: []string{}, }, expected: ` metadata: @@ -293,6 +295,28 @@ apiVersion: v1 Path: "dir", NetworkName: "bridge", User: "root", + Env: []string{}, + }, + expected: ` +metadata: + name: function-input + annotations: + config.kubernetes.io/function: | + container: {image: 'foo:bar'} +data: {} +kind: ConfigMap +apiVersion: v1 +`, + }, + { + name: "specify env", + args: []string{"run", "dir", "--fn-env", "foo=bar", "--fn-env", "baz", "--image", "foo:bar"}, + path: "dir", + expectedStruct: &runfn.RunFns{ + Path: "dir", + NetworkName: "bridge", + User: "nobody", + Env: []string{"foo=bar", "baz"}, }, expected: ` metadata: