# Writing Code | Kustomize
How to modify Kustomize

Writing Code | Kustomize

# Writing Code

How to modify Kustomize

To build kustomize using the locally modified modules, `replace` statements must be added to the `kustomize/go.mod`.

e.g. if code in `api` was modified, a `replace` statement would need to be added for the `kustomize/api` module.

Call stack when running `kustomize build`, with links to code.

## Run build

- RunBuild
  - MakeKustomizer
  - Run: performs a kustomization. It uses its internal filesystem reference to read the file at the given path argument, interpret it as a kustomization.yaml file, perform the kustomization it represents, and return the resulting resources.
    - Create factories
      - tranformer.NewFactoryImpl
      - resmap.NewFactory
        - resource.NewFactory
          - kustruct.NewKunstructuredFactoryImpl
      - loader.NewLoader
      - validator.NewKustValidator
    - NewKustTarget
    - Load
    - MakeCustomizeResMap: details in next section
  - emitResources

## Make resource map

- makeCustomizeResMap
  - AccumulateTarget: returns a new ResAccumulator, holding customized resources and the data/rules used to do so. The name back references and vars are not yet fixed.
    - accummulateResources: fills the given resourceAccumulator with resources read from the given list of paths.
    - Merge config from builtin and CRDs
    - runGenerators
      - configureBuiltinGenerators
        - ConfigMapGenerator
        - SecretGenerator
      - configureExternalGenerators
      - Iterate all generators
    - runTransfomers
      - configureBuiltinTransformers
        - PatchStrategicMergeTransformer
        - PatchTransformer
        - NamespaceTransformer
        - PrefixSuffixTransformer
        - LabelTransformer
        - AnnotationsTransformer
        - PatchJson6902Transformer
        - ReplicaCountTransformer
        - ImageTagTransformer
      - configureExternalTransformers
    - MergeVars
  - The following steps must be done last, not as part of the recursion implicit in AccumulateTarget.
    - addHashesToNames
    - FixBackReferences: Given that names have changed (prefixs/suffixes added), fix all the back references to those names.
    - ResolveVars

最后修改 2020年07月16日: Docs: Auto-fix markdownlint issues (f9ee578a)