Merge pull request #2890 from Shell32-Natsu/fn-user

add --fn-user flag to function run
This commit is contained in:
Jeff Regan
2020-08-26 10:44:49 -07:00
committed by GitHub
2 changed files with 26 additions and 0 deletions

View File

@@ -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

View File

@@ -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 {