mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-17 18:25:26 +00:00
Handle functions dir for resource destination.
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))
|
||||
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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user