add --as-current-user flag to fn run

This commit is contained in:
Donny Xia
2020-10-14 17:07:03 -07:00
parent ca45907af0
commit 64fda38e2d
2 changed files with 14 additions and 0 deletions

View File

@@ -70,6 +70,8 @@ func GetRunFnRunner(name string) *RunFnRunner {
r.Command.Flags().StringArrayVarP(
&r.Env, "env", "e", []string{},
"a list of environment variables to be used by functions")
r.Command.Flags().BoolVar(
&r.AsCurrentUser, "as-current-user", false, "use the uid and gid that kpt is running with to run the function in the container")
return r
}
@@ -97,6 +99,7 @@ type RunFnRunner struct {
Mounts []string
LogSteps bool
Env []string
AsCurrentUser bool
}
func (r *RunFnRunner) runE(c *cobra.Command, args []string) error {
@@ -312,6 +315,7 @@ func (r *RunFnRunner) preRunE(c *cobra.Command, args []string) error {
ResultsDir: r.ResultsDir,
LogSteps: r.LogSteps,
Env: r.Env,
AsCurrentUser: r.AsCurrentUser,
}
// don't consider args for the function

View File

@@ -300,6 +300,16 @@ apiVersion: v1
Env: []string{"FOO=BAR", "BAR"},
},
},
{
name: "as current user",
args: []string{"run", "dir", "--as-current-user"},
path: "dir",
expectedStruct: &runfn.RunFns{
Path: "dir",
AsCurrentUser: true,
Env: []string{},
},
},
}
for i := range tests {