Handle functions dir for resource destination.

This commit is contained in:
bzub
2020-01-14 13:01:22 -06:00
parent 070e128e47
commit 34f21f44a1
2 changed files with 28 additions and 0 deletions

View File

@@ -225,6 +225,11 @@ func (c *ContainerFilter) scope(dir string, nodes []*yaml.RNode) ([]*yaml.RNode,
}
resourceDir := path.Clean(path.Dir(p))
if path.Base(resourceDir) == functionsDirectoryName {
// Functions in the `functions` directory are scoped to
// themselves, and should see themselves as input
resourceDir = path.Dir(resourceDir)
}
if !strings.HasPrefix(resourceDir, dir) {
// this Resource doesn't fall under the function scope if it
// isn't in a subdirectory of where the function lives

View File

@@ -868,3 +868,26 @@ metadata:
config.kubernetes.io/index: '1'
`, b.String())
}
func TestContainerFilter_scope(t *testing.T) {
cf := &ContainerFilter{}
fnR, err := yaml.Parse(`apiVersion: config.kubernetes.io/v1beta1
kind: ConfigFunction
metadata:
name: config-function
annotations:
config.kubernetes.io/path: 'functions/bar.yaml'
`)
if !assert.NoError(t, err) {
return
}
inRs := []*yaml.RNode{fnR}
inScopeRs, notInScopeRs, err := cf.scope(".", inRs)
if !assert.NoError(t, err) {
return
}
assert.Len(t, inScopeRs, 1, "Number of in-scope Resources")
assert.Len(t, notInScopeRs, 0, "Number of out-of-scope Resources")
}