mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
add --fn-user flag to function run
This commit is contained in:
@@ -65,6 +65,8 @@ func GetRunFnRunner(name string) *RunFnRunner {
|
|||||||
r.Command.Flags().StringArrayVar(
|
r.Command.Flags().StringArrayVar(
|
||||||
&r.Mounts, "mount", []string{},
|
&r.Mounts, "mount", []string{},
|
||||||
"a list of storage options read from the filesystem")
|
"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
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -91,6 +93,7 @@ type RunFnRunner struct {
|
|||||||
Network bool
|
Network bool
|
||||||
NetworkName string
|
NetworkName string
|
||||||
Mounts []string
|
Mounts []string
|
||||||
|
User string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *RunFnRunner) runE(c *cobra.Command, args []string) error {
|
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,
|
EnableExec: r.EnableExec,
|
||||||
StorageMounts: storageMounts,
|
StorageMounts: storageMounts,
|
||||||
ResultsDir: r.ResultsDir,
|
ResultsDir: r.ResultsDir,
|
||||||
|
User: runtimeutil.ContainerUser(r.User),
|
||||||
}
|
}
|
||||||
|
|
||||||
// don't consider args for the function
|
// don't consider args for the function
|
||||||
|
|||||||
@@ -203,6 +203,7 @@ apiVersion: v1
|
|||||||
Path: "dir",
|
Path: "dir",
|
||||||
NetworkName: "bridge",
|
NetworkName: "bridge",
|
||||||
EnableStarlark: true,
|
EnableStarlark: true,
|
||||||
|
User: "nobody",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -256,6 +257,7 @@ apiVersion: v1
|
|||||||
Path: "dir",
|
Path: "dir",
|
||||||
NetworkName: "bridge",
|
NetworkName: "bridge",
|
||||||
ResultsDir: "foo/",
|
ResultsDir: "foo/",
|
||||||
|
User: "nobody",
|
||||||
},
|
},
|
||||||
expected: `
|
expected: `
|
||||||
metadata:
|
metadata:
|
||||||
@@ -283,6 +285,26 @@ apiVersion: v1
|
|||||||
args: []string{"run", "dir", "--image", "foo:bar", "--", "a=b", "c", "e=f"},
|
args: []string{"run", "dir", "--image", "foo:bar", "--", "a=b", "c", "e=f"},
|
||||||
err: "must have keys and values separated by",
|
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 {
|
for i := range tests {
|
||||||
|
|||||||
Reference in New Issue
Block a user