Skip to content

replace entire doc with structured data #6030

@seankhliao

Description

@seankhliao

Eschewed features

  • This issue is not requesting templating, unstuctured edits, build-time side-effects from args or env vars, or any other eschewed feature.

What would you like to have added?

I'd like to replace an entire string doc with some structured data that has been merged/overlayed as regular manifests:

Example input:

apiVersion: v1
kind: MyCustomConfig
metadata:
  name: my-config
  annotations:
    config.kubernetes.io/local-config: "true"
data:
  hello: world
  foo:
    bar: a/b/c
    quz: 1
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  config.yaml: |
    hello: placeholder config
---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
  - base.yaml
replacements:
  - source:
      kind: MyCustomConfig
      name: my-config
      fieldPath: data
    targets:
      - select:
          kind: ConfigMap
          name: my-config
        fieldPaths:
          - data.config\.yaml.

Output I want:

apiVersion: v1
kind: ConfigMap
metadata:
  name: my-config
data:
  config.yaml: |
    hello: world
    foo:
      bar: a/b/c
      quz: 1

Why is this needed?

Config can be complicated, and require updates at different layers, just like kubernetes manifests #4517 .

Kustomize discourages unstructured edits, but what we're dealing with is structured data, it just needs to be stringified at the end when embedded into kubernetes manifests.
Kustomize's overlays / patches are well understood, and we want to apply the same pattern to non k8s native (non CRD) application configs as well.

Can you accomplish the motivating task without this feature, and if so, how?

Currently we can replace the entire config string, or since 5.8.0, individual keys within a structured doc.
The closest thing we can do now is a replacement block per top-level key within structured data.

What other solutions have you considered?

duplicating config files

Anything else we should know?

Current behavior:

  • fieldpath: data.config\.yaml: empty string
  • fieldpath: data.config\.yaml., target is an unstructured string: Error: unable to find field "data.config\.yaml." in replacement target
  • fieldpath: data.config\.yaml., target is a structured data string:: Error: unable to find field "data.config\.yaml." in replacement target: wrong node kind: expected ScalarNode but got MappingNode: node contents:

Feature ownership

  • I am interested in contributing this feature myself! 🎉

Metadata

Metadata

Assignees

No one assigned

    Labels

    kind/featureCategorizes issue or PR as related to a new feature.needs-triageIndicates an issue or PR lacks a `triage/foo` label and requires one.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions