Skip to content

Feature Request: Support buildMetadata configuration for Kustomize builds #1579

@markussiebert

Description

@markussiebert

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:

  1. 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,
        }
        // ...
    }
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/kustomizeKustomize related issues and pull requestsenhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions