Skip to content

[Feature request] Replacements value in the structured data. #4517

Open
@koba1t

Description

@koba1t

Is your feature request related to a problem? Please describe.

I feel difficult to Overlay when structured data is in k8s YAML's value. (ex. Structured data(yaml or json) format value in configMap data And structured data(almost json) format value in annotations(this way is used in many projects, I think)).

Therefore I propose to add options for replacing the value in structured data to replacements function.

I think this function can be an alternative vars function on almost use cases.

Example (json format value in configMap data)
apiVersion: v1
kind: ConfigMap
metadata:
  name: jsoned-configmap
data:
  config.json: |-
    {"config": {
      "id": "42",
      "hostname": "REPLACE_TARGET"
    }}
Example (json format value in annotations)

Describe the solution you'd like

FIrst, set format and formatPath parameters to replacements option.
And interpretation in k8s YAML value using formatPath with format.
Finally, execute replacements which place set by formatPath.

(Please watch Proposal config on the "Additional context" section.)

Describe alternatives you've considered

I tried to use delimiter: '"' options on replacement to parse json.
I think I will be able to resolve my problem with this solution, but It is very hard.

Additional context

Proposal config

source
apiVersion: v1
kind: ConfigMap
metadata:
  name: source-configmap
data:
  HOSTNAME: www.example.com
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: target-configmap
data:
  config.json: |-
    {"config": {
      "id": "42",
      "hostname": "REPLACE_TARGET_HOSTNAME"
    }}
replacement
replacements:
- source:
    kind: ConfigMap
    name: source-configmap
    fieldPath: data.HOSTNAME
  targets:
  - select:
      kind: ConfigMap
      name: target-configmap
    fieldPaths:
    - data.config\.json
    options:
      format: 'json'
      formatPath: '/config/hostname'
expected
apiVersion: v1
kind: ConfigMap
metadata:
  name: source-configmap
data:
  HOSTNAME: www.example.com
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: target-configmap
data:
  config.json: '{"config":{"hostname":"www.example.com","id":"42"}}'

Metadata

Metadata

Assignees

Labels

kind/featureCategorizes issue or PR as related to a new feature.triage/acceptedIndicates an issue or PR is ready to be actively worked on.

Type

No type

Projects

Status

In Progress

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions