From 646e0b4f61483ea39a595382c09c3ad60321a0c9 Mon Sep 17 00:00:00 2001 From: Donny Xia Date: Tue, 18 Aug 2020 12:49:10 -0700 Subject: [PATCH] add --fn-user flag to function run --- cmd/config/internal/commands/run-fns.go | 4 ++++ cmd/config/internal/commands/run_test.go | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/cmd/config/internal/commands/run-fns.go b/cmd/config/internal/commands/run-fns.go index 2ae82adae..ad8f4078e 100644 --- a/cmd/config/internal/commands/run-fns.go +++ b/cmd/config/internal/commands/run-fns.go @@ -65,6 +65,8 @@ func GetRunFnRunner(name string) *RunFnRunner { r.Command.Flags().StringArrayVar( &r.Mounts, "mount", []string{}, "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") return r } @@ -91,6 +93,7 @@ type RunFnRunner struct { Network bool NetworkName string Mounts []string + User string } func (r *RunFnRunner) runE(c *cobra.Command, args []string) error { @@ -305,6 +308,7 @@ func (r *RunFnRunner) preRunE(c *cobra.Command, args []string) error { EnableExec: r.EnableExec, StorageMounts: storageMounts, ResultsDir: r.ResultsDir, + User: runtimeutil.ContainerUser(r.User), } // 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 7a3bf6939..7adbb4e8b 100644 --- a/cmd/config/internal/commands/run_test.go +++ b/cmd/config/internal/commands/run_test.go @@ -203,6 +203,7 @@ apiVersion: v1 Path: "dir", NetworkName: "bridge", EnableStarlark: true, + User: "nobody", }, }, { @@ -256,6 +257,7 @@ apiVersion: v1 Path: "dir", NetworkName: "bridge", ResultsDir: "foo/", + User: "nobody", }, expected: ` metadata: @@ -283,6 +285,26 @@ apiVersion: v1 args: []string{"run", "dir", "--image", "foo:bar", "--", "a=b", "c", "e=f"}, err: "must have keys and values separated by", }, + { + name: "specify username", + args: []string{"run", "dir", "--fn-user", "root", "--image", "foo:bar"}, + path: "dir", + expectedStruct: &runfn.RunFns{ + Path: "dir", + NetworkName: "bridge", + User: "root", + }, + expected: ` +metadata: + name: function-input + annotations: + config.kubernetes.io/function: | + container: {image: 'foo:bar'} +data: {} +kind: ConfigMap +apiVersion: v1 +`, + }, } for i := range tests {