mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-30 09:51:23 +00:00
Implement "kind: KustomizationPatch" to support composition of Kustomize files
This commit is contained in:
@@ -155,8 +155,12 @@ func (kt *KustTarget) addHashesToNames(
|
||||
// not yet fixed.
|
||||
func (kt *KustTarget) AccumulateTarget() (
|
||||
ra *accumulator.ResAccumulator, err error) {
|
||||
ra = accumulator.MakeEmptyAccumulator()
|
||||
err = kt.accumulateResources(ra, kt.kustomization.Resources)
|
||||
return kt.accumulateTarget(accumulator.MakeEmptyAccumulator())
|
||||
}
|
||||
|
||||
func (kt *KustTarget) accumulateTarget(ra *accumulator.ResAccumulator) (
|
||||
resRa *accumulator.ResAccumulator, err error) {
|
||||
ra, err = kt.accumulateResources(ra, kt.kustomization.Resources)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "accumulating resources")
|
||||
}
|
||||
@@ -224,7 +228,7 @@ func (kt *KustTarget) runGenerators(
|
||||
|
||||
func (kt *KustTarget) configureExternalGenerators() ([]resmap.Generator, error) {
|
||||
ra := accumulator.MakeEmptyAccumulator()
|
||||
err := kt.accumulateResources(ra, kt.kustomization.Generators)
|
||||
ra, err := kt.accumulateResources(ra, kt.kustomization.Generators)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -250,7 +254,7 @@ func (kt *KustTarget) runTransformers(ra *accumulator.ResAccumulator) error {
|
||||
|
||||
func (kt *KustTarget) configureExternalTransformers() ([]resmap.Transformer, error) {
|
||||
ra := accumulator.MakeEmptyAccumulator()
|
||||
err := kt.accumulateResources(ra, kt.kustomization.Transformers)
|
||||
ra, err := kt.accumulateResources(ra, kt.kustomization.Transformers)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -260,44 +264,52 @@ func (kt *KustTarget) configureExternalTransformers() ([]resmap.Transformer, err
|
||||
// accumulateResources fills the given resourceAccumulator
|
||||
// with resources read from the given list of paths.
|
||||
func (kt *KustTarget) accumulateResources(
|
||||
ra *accumulator.ResAccumulator, paths []string) error {
|
||||
ra *accumulator.ResAccumulator, paths []string) (*accumulator.ResAccumulator, error) {
|
||||
for _, path := range paths {
|
||||
// try loading resource as file then as base (directory or git repository)
|
||||
if errF := kt.accumulateFile(ra, path); errF != nil {
|
||||
ldr, errL := kt.ldr.New(path)
|
||||
if errL != nil {
|
||||
return fmt.Errorf("accumulateFile %q, loader.New %q", errF, errL)
|
||||
return nil, fmt.Errorf("accumulateFile %q, loader.New %q", errF, errL)
|
||||
}
|
||||
errD := kt.accumulateDirectory(ra, ldr)
|
||||
var errD error
|
||||
ra, errD = kt.accumulateDirectory(ra, ldr)
|
||||
if errD != nil {
|
||||
return fmt.Errorf("accumulateFile %q, accumulateDirector: %q", errF, errD)
|
||||
return nil, fmt.Errorf("accumulateFile %q, accumulateDirector: %q", errF, errD)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return ra, nil
|
||||
}
|
||||
|
||||
func (kt *KustTarget) accumulateDirectory(
|
||||
ra *accumulator.ResAccumulator, ldr ifc.Loader) error {
|
||||
ra *accumulator.ResAccumulator, ldr ifc.Loader) (*accumulator.ResAccumulator, error) {
|
||||
defer ldr.Cleanup()
|
||||
subKt := NewKustTarget(
|
||||
ldr, kt.validator, kt.rFactory, kt.tFactory, kt.pLdr)
|
||||
err := subKt.Load()
|
||||
if err != nil {
|
||||
return errors.Wrapf(
|
||||
return nil, errors.Wrapf(
|
||||
err, "couldn't make target for path '%s'", ldr.Root())
|
||||
}
|
||||
subRa, err := subKt.AccumulateTarget()
|
||||
|
||||
var subRa *accumulator.ResAccumulator
|
||||
if subKt.kustomization.Kind == types.KustomizationPatchKind {
|
||||
subRa, err = subKt.accumulateTarget(ra)
|
||||
ra = accumulator.MakeEmptyAccumulator()
|
||||
} else {
|
||||
subRa, err = subKt.AccumulateTarget()
|
||||
}
|
||||
if err != nil {
|
||||
return errors.Wrapf(
|
||||
return nil, errors.Wrapf(
|
||||
err, "recursed accumulation of path '%s'", ldr.Root())
|
||||
}
|
||||
err = ra.MergeAccumulator(subRa)
|
||||
if err != nil {
|
||||
return errors.Wrapf(
|
||||
return nil, errors.Wrapf(
|
||||
err, "recursed merging from path '%s'", ldr.Root())
|
||||
}
|
||||
return nil
|
||||
return ra, nil
|
||||
}
|
||||
|
||||
func (kt *KustTarget) accumulateFile(
|
||||
|
||||
Reference in New Issue
Block a user