Feature Request: Support buildMetadata configuration for Kustomize builds
Problem
Currently, to enable Kustomize build metadata (e.g., originAnnotations which adds source file path annotations to resources), users must add buildMetadata: [originAnnotations] to every kustomization.yaml file in their repositories.
This becomes impractical when:
- Managing many repositories/kustomizations
- Users don't control the source repositories
- Wanting to enforce this cluster-wide for observability/debugging
Proposed Solutions
Option 1: Environment Variable (Simplest)
Add an environment variable to the kustomize-controller deployment:
env:
- name: KUSTOMIZE_BUILD_METADATA
value: "originAnnotations"
Pros: No API changes, easy cluster-wide enablement, backward compatible
Option 2: Kustomization CRD Field (Most Flexible)
Add a buildMetadata field to the Kustomization spec:
apiVersion: kustomize.toolkit.fluxcd.io/v1
kind: Kustomization
metadata:
name: apps
spec:
buildMetadata:
- originAnnotations
Pros: Per-Kustomization control, explicit, follows Flux patterns
Option 3: Both (Recommended)
Support both with precedence: repo file > CRD field > env var
Use Case
The originAnnotations build metadata adds source file path annotations:
metadata:
annotations:
config.kubernetes.io/origin: |
path: apps/tenant-a/deployment.yaml
Valuable for debugging, auditing, and tooling that needs to track resource origins.
Implementation
Changes required:
-
fluxcd/pkg/kustomize - Update Build() and SecureBuild() to accept buildMetadata []string parameter:
func Build(fs filesys.FileSystem, dirPath string, buildMetadata []string) (res resmap.ResMap, err error) {
buildOptions := &krusty.Options{
LoadRestrictions: kustypes.LoadRestrictionsNone,
PluginConfig: kustypes.DisabledPluginConfig(),
BuildMetadata: buildMetadata,
}
// ...
}
-
fluxcd/kustomize-controller - Read env var/CRD field and pass to build functions
The krusty.Options struct already supports BuildMetadata, so this is primarily plumbing.
Related
Feature Request: Support buildMetadata configuration for Kustomize builds
Problem
Currently, to enable Kustomize build metadata (e.g.,
originAnnotationswhich adds source file path annotations to resources), users must addbuildMetadata: [originAnnotations]to everykustomization.yamlfile in their repositories.This becomes impractical when:
Proposed Solutions
Option 1: Environment Variable (Simplest)
Add an environment variable to the kustomize-controller deployment:
Pros: No API changes, easy cluster-wide enablement, backward compatible
Option 2: Kustomization CRD Field (Most Flexible)
Add a
buildMetadatafield to the Kustomization spec:Pros: Per-Kustomization control, explicit, follows Flux patterns
Option 3: Both (Recommended)
Support both with precedence: repo file > CRD field > env var
Use Case
The
originAnnotationsbuild metadata adds source file path annotations:Valuable for debugging, auditing, and tooling that needs to track resource origins.
Implementation
Changes required:
fluxcd/pkg/kustomize- UpdateBuild()andSecureBuild()to acceptbuildMetadata []stringparameter:fluxcd/kustomize-controller- Read env var/CRD field and pass to build functionsThe
krusty.Optionsstruct already supportsBuildMetadata, so this is primarily plumbing.Related