Skip to content

Commit a34dd1f

Browse files
committed
fix replacements syntax
1 parent 2831689 commit a34dd1f

File tree

1 file changed

+6
-19
lines changed

1 file changed

+6
-19
lines changed

proposals/22-03-value-in-the-structured-data.md

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,8 @@ If you have a PR, link to it at the top of this section.
111111
112112
### Replacement the value in structured data
113113
114-
I propose to add options for replacing the value in structured data to replacements function. My sample implementation is [here](https://github.com/kubernetes-sigs/kustomize/pull/4518).\
115-
This idea is add two parameter `format` and `formatPath` to [options](https://github.com/kubernetes-sigs/kustomize/blob/8668691ade05bc17b3c6f44bcd4723735033196e/api/types/replacement.go#L67-L80) in replacement [TargetSelector](https://github.com/kubernetes-sigs/kustomize/blob/8668691ade05bc17b3c6f44bcd4723735033196e/api/types/replacement.go#L52-L64). The `format` option is used by select to structured data format like "json" or "yaml", and The `formatPath` option is "path" to target to change values in structured data with selected format from `format` option.\
116-
I think these two parameters can't select a specific default value. Therefore kustomize return error message for the user if only one parameter was set.\
114+
I propose to extend the `fieldPath` and `fieldPaths` fields to replace the value in structured data with the replacements function.\
115+
This idea is extending how to select any field in replacement [TargetSelector](https://github.com/kubernetes-sigs/kustomize/blob/8668691ade05bc17b3c6f44bcd4723735033196e/api/types/replacement.go#L52-L64). If the `source.fieldPath` and `targets.fieldPaths` had extra values after a specific string literal in Yaml, Kustomize tries to parse that string as structure data and tries to drill down using that additional values.
117116

118117
#### Example.
119118

@@ -129,10 +128,7 @@ replacements:
129128
kind: ConfigMap
130129
name: target-configmap
131130
fieldPaths:
132-
- data.config\.json
133-
options:
134-
format: 'json' # Setting structured data format.
135-
formatPath: '/config/hostname' # Setting replacements path.
131+
- data.config\.json.config.hostname # A path after `config\.json` is pointing one place in the structured data.
136132
```
137133

138134
Please check [Story 1](#Story-1).
@@ -249,10 +245,7 @@ replacements:
249245
kind: ConfigMap
250246
name: target-configmap
251247
fieldPaths:
252-
- data.config\.json
253-
options:
254-
format: 'json'
255-
formatPath: '/config/hostname'
248+
- data.config\.json.config.hostname
256249
```
257250
258251
```yaml
@@ -393,10 +386,7 @@ replacements:
393386
kind: ConfigMap
394387
name: prometheus-config
395388
fieldPaths:
396-
- data.prometheus\.yml
397-
options:
398-
format: 'yaml'
399-
formatPath: '/global/external_labels/prometheus_env'
389+
- data.prometheus\.yml.global.external_labels?prometheus_env
400390
```
401391
402392
```yaml
@@ -471,10 +461,7 @@ replacements:
471461
kind: ConServicefigMap
472462
name: appA-svc
473463
fieldPaths:
474-
- metadata.annotations.cloud-provider/backend-config
475-
options:
476-
format: 'json'
477-
formatPath: '/ports/appA'
464+
- metadata.annotations.cloud-provider/backend-config.ports.appA
478465
```
479466
480467
```yaml

0 commit comments

Comments
 (0)