mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge pull request #2088 from bzub/2083-config_run_sans_resource_input
Fix resource directory when using functions directory.
This commit is contained in:
@@ -225,6 +225,11 @@ func (c *ContainerFilter) scope(dir string, nodes []*yaml.RNode) ([]*yaml.RNode,
|
|||||||
}
|
}
|
||||||
|
|
||||||
resourceDir := path.Clean(path.Dir(p))
|
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) {
|
if !strings.HasPrefix(resourceDir, dir) {
|
||||||
// this Resource doesn't fall under the function scope if it
|
// this Resource doesn't fall under the function scope if it
|
||||||
// isn't in a subdirectory of where the function lives
|
// isn't in a subdirectory of where the function lives
|
||||||
|
|||||||
@@ -868,3 +868,26 @@ metadata:
|
|||||||
config.kubernetes.io/index: '1'
|
config.kubernetes.io/index: '1'
|
||||||
`, b.String())
|
`, 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")
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user