diff --git a/api/internal/target/kusttarget.go b/api/internal/target/kusttarget.go index a51299a4c..1e39d925f 100644 --- a/api/internal/target/kusttarget.go +++ b/api/internal/target/kusttarget.go @@ -158,6 +158,8 @@ func (kt *KustTarget) AccumulateTarget() ( return kt.accumulateTarget(accumulator.MakeEmptyAccumulator()) } +// ra should be empty when this KustTarget is a Kustomization, or the ra of the parent if this KustTarget is a Component +// (or empty if the Component does not have a parent). func (kt *KustTarget) accumulateTarget(ra *accumulator.ResAccumulator) ( resRa *accumulator.ResAccumulator, err error) { ra, err = kt.accumulateResources(ra, kt.kustomization.Resources) @@ -324,10 +326,13 @@ func (kt *KustTarget) accumulateDirectory( } var subRa *accumulator.ResAccumulator - if subKt.kustomization.Kind == types.ComponentKind { + if isComponent { + // Components don't create a new accumulator: the kustomization directives are added to the current accumulator subRa, err = subKt.accumulateTarget(ra) ra = accumulator.MakeEmptyAccumulator() } else { + // Child Kustomizations create a new accumulator which resolves their kustomization directives, which will later + // be merged into the current accumulator. subRa, err = subKt.AccumulateTarget() } if err != nil { diff --git a/api/krusty/component_test.go b/api/krusty/component_test.go index bc1d1be82..7681e3962 100644 --- a/api/krusty/component_test.go +++ b/api/krusty/component_test.go @@ -463,7 +463,7 @@ configMapGenerator: err := th.RunWithErr("/app/prod", th.MakeDefaultOptions()) if !strings.Contains( err.Error(), - "apiVersion should be kustomize.config.k8s.io/v1alpha1") { + "apiVersion for Component should be kustomize.config.k8s.io/v1alpha1") { t.Fatalf("unexpected error: %s", err) } } diff --git a/api/types/kustomization.go b/api/types/kustomization.go index f86edb4bf..4a2c42d36 100644 --- a/api/types/kustomization.go +++ b/api/types/kustomization.go @@ -158,7 +158,7 @@ func (k *Kustomization) EnforceFields() []string { requiredVersion = ComponentVersion } if k.APIVersion != "" && k.APIVersion != requiredVersion { - errs = append(errs, "apiVersion should be "+requiredVersion) + errs = append(errs, "apiVersion for "+k.Kind+" should be "+requiredVersion) } return errs }