Additional tests around reusing the same bases and components

This commit is contained in:
Paul Martin
2020-05-28 19:50:00 +01:00
parent ab9d4c7e7b
commit 34a442bbef
3 changed files with 8 additions and 3 deletions

View File

@@ -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 {

View File

@@ -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)
}
}

View File

@@ -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
}