Support writing results from container filter

This commit is contained in:
Phillip Wittrock
2020-04-13 11:53:29 -07:00
parent b72db9e783
commit 8d22cbdcca
5 changed files with 516 additions and 65 deletions

View File

@@ -51,6 +51,9 @@ func GetRunFnRunner(name string) *RunFnRunner {
&r.StarName, "star-name", "", "name of starlark program.")
r.Command.Flags().MarkHidden("star-name")
r.Command.Flags().StringVar(
&r.ResultsDir, "results-dir", "", "write function results to this dir")
r.Command.Flags().BoolVar(
&r.Network, "network", false, "enable network access for functions that declare it")
r.Command.Flags().StringVar(
@@ -77,6 +80,7 @@ type RunFnRunner struct {
StarPath string
StarName string
RunFns runfn.RunFns
ResultsDir string
Network bool
NetworkName string
Mounts []string
@@ -267,6 +271,7 @@ func (r *RunFnRunner) preRunE(c *cobra.Command, args []string) error {
NetworkName: r.NetworkName,
EnableStarlark: r.EnableStar,
StorageMounts: storageMounts,
ResultsDir: r.ResultsDir,
}
// don't consider args for the function

View File

@@ -11,23 +11,25 @@ import (
"github.com/spf13/cobra"
"github.com/stretchr/testify/assert"
"sigs.k8s.io/kustomize/kyaml/runfn"
)
// TestRunFnCommand_preRunE verifies that preRunE correctly parses the commandline
// flags and arguments into the RunFns structure to be executed.
func TestRunFnCommand_preRunE(t *testing.T) {
tests := []struct {
name string
args []string
expected string
err string
path string
input io.Reader
output io.Writer
functionPaths []string
network bool
networkName string
mount []string
name string
args []string
expected string
expectedStruct *runfn.RunFns
err string
path string
input io.Reader
output io.Writer
functionPaths []string
network bool
networkName string
mount []string
}{
{
name: "config map",
@@ -234,6 +236,26 @@ metadata:
data: {g: h, i: j=k}
kind: Foo
apiVersion: v1
`,
},
{
name: "results_dir",
args: []string{"run", "dir", "--results-dir", "foo/", "--image", "foo:bar", "--", "a=b", "c=d", "e=f"},
path: "dir",
expectedStruct: &runfn.RunFns{
Path: "dir",
NetworkName: "bridge",
ResultsDir: "foo/",
},
expected: `
metadata:
name: function-input
annotations:
config.kubernetes.io/function: |
container: {image: 'foo:bar'}
data: {a: b, c: d, e: f}
kind: ConfigMap
apiVersion: v1
`,
},
{
@@ -324,6 +346,10 @@ apiVersion: v1
t.FailNow()
}
if !assert.Equal(t, r.RunFns, r.RunFns) {
t.FailNow()
}
if !assert.Equal(t, toStorageMounts(tt.mount), r.RunFns.StorageMounts) {
t.FailNow()
}
@@ -339,6 +365,14 @@ apiVersion: v1
}
}
if tt.expectedStruct != nil {
r.RunFns.Functions = nil
tt.expectedStruct.FunctionPaths = tt.functionPaths
if !assert.Equal(t, *tt.expectedStruct, r.RunFns) {
t.FailNow()
}
}
})
}