Use mount flag to pass storage mounts to functions

This commit is contained in:
Prachi Pendse
2020-04-01 15:03:57 -07:00
parent a4ee1c2e72
commit 38973a80c3
7 changed files with 132 additions and 297 deletions

View File

@@ -51,10 +51,6 @@ type RunFns struct {
// NetworkName is the name of the docker network to use for the container
NetworkName string
// Volumes Volumes allows directories to be specified outside the configuration
// directory.
Volumes []string
// Output can be set to write the result to Output rather than back to the directory
Output io.Writer
@@ -137,13 +133,6 @@ func (r RunFns) getFilters(nodes []*yaml.RNode) ([]kio.Filter, error) {
}
fltrs = append(fltrs, f...)
// directories from volumes specified on the struct
f, err = r.getDirectoriesFromVolumes()
if err != nil {
return nil, err
}
fltrs = append(fltrs, f...)
// explicit fns specified on the struct
f, err = r.getFunctionsFromFunctions()
if err != nil {
@@ -207,24 +196,6 @@ func (r RunFns) getFunctionsFromFunctionPaths() ([]kio.Filter, error) {
return r.getFunctionFilters(true, buff.Nodes...)
}
// getDirectoriesFromVolumes returns the set of directories read from r.Volumes
// as a slice of Filters
func (r RunFns) getDirectoriesFromVolumes() ([]kio.Filter, error) {
buff := &kio.PackageBuffer{}
for i := range r.Volumes {
err := kio.Pipeline{
Inputs: []kio.Reader{
kio.LocalPackageReader{PackagePath: r.Volumes[i]},
},
Outputs: []kio.Writer{buff},
}.Execute()
if err != nil {
return nil, err
}
}
return r.getFunctionFilters(true, buff.Nodes...)
}
// getFunctionsFromFunctions returns the set of explicitly provided functions as
// Filters
func (r RunFns) getFunctionsFromFunctions() ([]kio.Filter, error) {

View File

@@ -141,13 +141,13 @@ func TestRunFns_Execute__initDefault(t *testing.T) {
},
},
{
name: "explicit directories in volumes",
instance: RunFns{Volumes: []string{"vol"}},
name: "explicit directories in mounts",
instance: RunFns{StorageMounts: []filters.StorageMount{{MountType: "volume", Src: "myvol", DstPath: "/local/"}}},
expected: RunFns{
Output: os.Stdout,
Input: os.Stdin,
NoFunctionsFromInput: getFalse(),
Volumes: []string{"vol"},
StorageMounts: []filters.StorageMount{{MountType: "volume", Src: "myvol", DstPath: "/local/"}},
},
},
}