diff --git a/kyaml/kio/filters/container.go b/kyaml/kio/filters/container.go index 50a411de6..705b39f0f 100644 --- a/kyaml/kio/filters/container.go +++ b/kyaml/kio/filters/container.go @@ -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 diff --git a/kyaml/kio/filters/container_test.go b/kyaml/kio/filters/container_test.go index 441f43a7f..c8152f128 100644 --- a/kyaml/kio/filters/container_test.go +++ b/kyaml/kio/filters/container_test.go @@ -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") +}