Support mounting volumes to containers

This commit is contained in:
Prachi Pendse
2020-03-31 01:08:54 -07:00
parent 78abd4193a
commit 39fe903498
7 changed files with 307 additions and 0 deletions

View File

@@ -51,6 +51,10 @@ 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
@@ -133,6 +137,13 @@ 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 {
@@ -196,6 +207,24 @@ 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

@@ -140,6 +140,16 @@ func TestRunFns_Execute__initDefault(t *testing.T) {
FunctionPaths: []string{"foo"},
},
},
{
name: "explicit directories in volumes",
instance: RunFns{Volumes: []string{"vol"}},
expected: RunFns{
Output: os.Stdout,
Input: os.Stdin,
NoFunctionsFromInput: getFalse(),
Volumes: []string{"vol"},
},
},
}
for i := range tests {
tt := tests[i]