Skip to content

Commit e1301a8

Browse files
Clean up search-replace and apply-setters docs (#201)
* Clean up search-replace and apply-setters docs * Use run instead of eval and migrate later * Add sh
1 parent f0e9983 commit e1301a8

File tree

8 files changed

+220
-218
lines changed

8 files changed

+220
-218
lines changed

examples/apply-setters/simple/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# apply-setters: Simple Example
22

3-
Setters provide a solution for template-free setting of field values. The
3+
Setters provide a solution for template-free setting of field values. The
44
`apply-setters` KRM config function applies setter values to resource fields
55
with setter references.
66

@@ -19,8 +19,8 @@ kind: MyKind
1919
metadata:
2020
name: ns
2121
environments: # kpt-set: ${env}
22-
- dev
23-
- stage
22+
- dev
23+
- stage
2424
```
2525
2626
We use ConfigMap to configure the `apply-setters` function. The desired
@@ -32,15 +32,15 @@ desired value for the tagged field.
3232
apiVersion: v1
3333
kind: ConfigMap
3434
metadata:
35-
...
35+
name: apply-setters-fn-config
3636
data:
3737
name: my-new-map
3838
env: |
3939
- prod
4040
- stage
4141
```
4242

43-
Invoking `apply-setters` function would apply the changes to resource configs
43+
Invoking `apply-setters` function would apply the changes to resource configs
4444

4545
```yaml
4646
apiVersion: v1
@@ -55,8 +55,8 @@ kind: MyKind
5555
metadata:
5656
name: ns
5757
environments: # kpt-set: ${env}
58-
- prod
59-
- stage
58+
- prod
59+
- stage
6060
```
6161

6262
## Function invocation
@@ -74,5 +74,5 @@ Check the value of setter `name` is set to `my-new-map`.
7474
Check the value of setter `env` is set to array value `[prod, stage]`.
7575

7676
```sh
77-
kpt cfg cat simple
77+
$ kpt cfg cat simple/
7878
```

examples/apply-setters/simple/fn-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
apiVersion: v1
22
kind: ConfigMap
33
metadata:
4-
name: my-func-config
4+
name: apply-setters-fn-config
5+
# TODO:(pmarupaka) remove annotations when e2e tests switch to kpt v1 binary
56
annotations:
67
config.k8s.io/function: |
78
container:

examples/search-replace/simple/README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ We use the following ConfigMap to provide input matchers to the function.
2323
```yaml
2424
apiVersion: v1
2525
kind: ConfigMap
26-
metadata: ...
26+
metadata:
27+
...
2728
data:
2829
by-path: metadata.name
2930
by-value: the-deployment
@@ -45,7 +46,7 @@ metadata:
4546
Get the config example and try it out by running the following commands:
4647

4748
```sh
48-
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/search/simple .
49+
kpt pkg get https://github.com/GoogleContainerTools/kpt-functions-catalog.git/examples/search-replace/simple .
4950
kpt fn run simple
5051
```
5152

@@ -54,5 +55,5 @@ kpt fn run simple
5455
Check the value of deployment `the-deloyment` is changed to `my-deloyment`.
5556

5657
```sh
57-
kpt cfg cat simple
58+
$ kpt cfg cat simple/
5859
```

examples/search-replace/simple/fn-config.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
apiVersion: v1
22
kind: ConfigMap
33
metadata:
4-
name: my-func-config
4+
name: search-replace-fn-config
5+
# TODO:(pmarupaka) remove annotations when e2e tests switch to kpt v1 binary
56
annotations:
67
config.k8s.io/function: |
78
container:

functions/go/apply-setters/README.md

Lines changed: 32 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -9,44 +9,26 @@ setting of field values.
99

1010
<!--mdtogo-->
1111

12-
Setters are a safer alternative to other substitution techniques which do not have the context
13-
of the structured data. Setters may be invoked to modify the package resources
14-
using `apply-setters` function to set values.
15-
1612
### Synopsis
1713

1814
<!--mdtogo:Long-->
1915

20-
Package publishers declare setters in the package, consumers can set their values
21-
either declaratively or imperatively.
16+
Setters are a safer alternative to other substitution techniques which do not
17+
have the context of the structured data. Setters may be invoked to modify the
18+
package resources using `apply-setters` function to set desired values.
2219

23-
Setter names can be discovered in the pipeline section of Kptfile, and the values
24-
can be declared next to setter names.
20+
We use ConfigMap to configure the `apply-setters` function. The desired setter
21+
values are provided as key-value pairs using `data` field where key is the name of the
22+
setter and value is the new desired value for the setter.
2523

2624
```yaml
27-
apiVersion: v1alpha2
28-
kind: Kptfile
25+
apiVersion: v1
26+
kind: ConfigMap
2927
metadata:
30-
name: my-pkg
31-
pipeline:
32-
mutators:
33-
- image: gcr.io/kpt-fn/apply-setters:unstable
34-
configMap:
35-
setter_name1: setter-value1
36-
setter_name2: setter-value2
37-
```
38-
39-
The declared values for setters are rendered by invoking the following command:
40-
41-
```
42-
kpt fn render [PKG_PATH]
43-
```
44-
45-
Alternatively, this function can be invoked imperatively on the package by passing the
46-
inputs as key-value pairs.
47-
48-
```
49-
kpt fn eval --image gcr.io/kpt-fn/apply-setters:VERSION [PKG_PATH] -- [setter_name=setter_value]
28+
name: my-func-config
29+
data:
30+
setter_name1: setter_value1
31+
setter_name2: setter_value2
5032
```
5133
5234
<!--mdtogo-->
@@ -68,31 +50,28 @@ spec:
6850
replicas: 1 # kpt-set: ${replicas}
6951
```
7052
71-
Discover the names of setters in the Kptfile and declare desired values.
53+
Discover the names of setters in the function config file and declare desired values.
7254
7355
```yaml
74-
apiVersion: v1alpha2
75-
kind: Kptfile
56+
apiVersion: v1
57+
kind: ConfigMap
7658
metadata:
77-
name: my-pkg
78-
pipeline:
79-
mutators:
80-
- image: gcr.io/kpt-fn/apply-setters:unstable
81-
configMap:
82-
image: ubuntu
83-
replicas: 3
59+
name: apply-setters-fn-config
60+
data:
61+
image: ubuntu
62+
replicas: "3"
8463
```
8564
8665
Render the declared values by invoking:
8766
88-
```
89-
kpt fn render
67+
```sh
68+
$ kpt fn run --image gcr.io/kpt-fn/apply-setters:unstable --fn-config ./apply-setters-fn-config
9069
```
9170

92-
Alternatively, values can be rendered imperatively
71+
Alternatively, setter values can be passed as key-value pairs in the CLI
9372

94-
```
95-
kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable -- 'replicas=3'
73+
```sh
74+
$ kpt fn run --image gcr.io/kpt-fn/apply-setters:unstable -- 'image=ubuntu' 'replicas=3'
9675
```
9776

9877
Rendered resource looks like the following:
@@ -127,29 +106,20 @@ environments: # kpt-set: ${env}
127106
Declare the desired array values, wrapped into string.
128107
129108
```yaml
130-
apiVersion: v1alpha2
131-
kind: Kptfile
109+
apiVersion: v1
110+
kind: ConfigMap
132111
metadata:
133-
name: my-pkg
134-
pipeline:
135-
mutators:
136-
- image: gcr.io/kpt-fn/apply-setters:unstable
137-
configMap:
138-
env: |
139-
- prod
140-
- dev
112+
name: apply-setters-fn-config
113+
data:
114+
env: |
115+
- prod
116+
- dev
141117
```
142118
143119
Render the declared values by invoking:
144120
145121
```
146-
kpt fn render
147-
```
148-
149-
Alternatively, values can be rendered imperatively
150-
151-
```
152-
kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable -- 'env=[prod, dev]'
122+
$ kpt fn run --image gcr.io/kpt-fn/apply-setters:unstable --fn-config ./apply-setters-fn-config
153123
```
154124

155125
Rendered resource looks like the following:

functions/go/apply-setters/generated/docs.go

Lines changed: 30 additions & 50 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)