diff --git a/api/internal/target/kusttarget.go b/api/internal/target/kusttarget.go index 18a38f3c48..046ed27a17 100644 --- a/api/internal/target/kusttarget.go +++ b/api/internal/target/kusttarget.go @@ -21,6 +21,7 @@ import ( "sigs.k8s.io/kustomize/api/resmap" "sigs.k8s.io/kustomize/api/resource" "sigs.k8s.io/kustomize/api/types" + "sigs.k8s.io/kustomize/kyaml/kio/kioutil" "sigs.k8s.io/kustomize/kyaml/openapi" "sigs.k8s.io/yaml" ) @@ -262,7 +263,12 @@ func (kt *KustTarget) configureExternalGenerators() ([]resmap.Generator, error) if err != nil { return nil, err } - return kt.pLdr.LoadGenerators(kt.ldr, kt.validator, ra.ResMap()) + m := ra.ResMap() + err = m.AnnotateAll(kioutil.PathAnnotation, kt.ldr.Root()) + if err != nil { + return nil, err + } + return kt.pLdr.LoadGenerators(kt.ldr, kt.validator, m) } func (kt *KustTarget) runTransformers(ra *accumulator.ResAccumulator) error { diff --git a/api/krusty/fnplugin_test.go b/api/krusty/fnplugin_test.go index eca491056b..554b5637f9 100644 --- a/api/krusty/fnplugin_test.go +++ b/api/krusty/fnplugin_test.go @@ -1,10 +1,16 @@ package krusty_test import ( + "os" "os/exec" + "path/filepath" "testing" + "github.com/stretchr/testify/assert" + "sigs.k8s.io/kustomize/api/internal/utils" + "sigs.k8s.io/kustomize/api/krusty" kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" + "sigs.k8s.io/kustomize/kyaml/filesys" ) func TestFnExecGenerator(t *testing.T) { @@ -82,6 +88,125 @@ spec: `) } +func TestFnExecGeneratorWithOverlay(t *testing.T) { + fSys := filesys.MakeFsOnDisk() + th := kusttest_test.MakeHarness(t) + o := th.MakeOptionsPluginsEnabled() + o.PluginConfig.FnpLoadingOptions.EnableExec = true + b := krusty.MakeKustomizer(&o) + + tmpDir, err := filesys.NewTmpConfirmedDir() + assert.NoError(t, err) + base := filepath.Join(tmpDir.String(), "base") + prod := filepath.Join(tmpDir.String(), "prod") + assert.NoError(t, fSys.Mkdir(base)) + assert.NoError(t, fSys.Mkdir(prod)) + assert.NoError(t, fSys.WriteFile(filepath.Join(base, "kustomization.yaml"), []byte(` +resources: +- short_secret.yaml +generators: +- gener.yaml +`))) + assert.NoError(t, fSys.WriteFile(filepath.Join(prod, "kustomization.yaml"), []byte(` +resources: +- ../base +`))) + assert.NoError(t, fSys.WriteFile(filepath.Join(base, "short_secret.yaml"), []byte(` +apiVersion: v1 +kind: Secret +metadata: + labels: + airshipit.org/ephemeral-user-data: "true" + name: node1-bmc-secret +type: Opaque +stringData: + userData: | + bootcmd: + - mkdir /mnt/vda +`))) + assert.NoError(t, fSys.WriteFile(filepath.Join(base, "exec.sh"), []byte(`#!/bin/sh + +cat <