-
Notifications
You must be signed in to change notification settings - Fork 74
Expand file tree
/
Copy pathdocs.go
More file actions
150 lines (120 loc) · 3.96 KB
/
docs.go
File metadata and controls
150 lines (120 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Code generated by "mdtogo"; DO NOT EDIT.
package generated
var ApplySettersShort = `Update the field values parameterized by setters.
Definitions:
**Setters**: Setters serve as parameters for customizing field values.
Setters are a safer way to parameterize field values compared to common templating techniques.
By using comments instead of interleaving templating directives, the resource is still
valid, adheres to the KRM schema, and can be consumed by other tools.
**Setter Name**: Name of the parameter.
**Setter Value**: Value of the parameter.
**Setter Comment**: A field value can be fully or partially parameterized using setter comments.
A setter comment can be derived by replacing all the instances of setter values
in the field value, with the corresponding setter names along with 'kpt-set:' prefix.
e.g. image: gcr.io/nginx:1.16.1 # kpt-set: gcr.io/${image}:${tag}`
var ApplySettersLong = `
We use ConfigMap to configure the ` + "`" + `apply-setters` + "`" + ` function. The desired setter
values are provided as key-value pairs using ` + "`" + `data` + "`" + ` field where key is the name of the
setter and value is the new desired value for the setter.
apiVersion: v1
kind: ConfigMap
metadata:
name: apply-setters-func-config
data:
setter_name1: setter_value1
setter_name2: setter_value2
` + "`" + `apply-setters` + "`" + ` function performs the following steps when invoked:
1. Searches for the field values tagged by setter comments.
2. Updates the field value fully or partially with the corresponding input setter values.
`
var ApplySettersExamples = `
Setting scalar values:
Let's start with the input resource in a package
# resources.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
replicas: 4 # kpt-set: ${nginx-replicas}
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: "nginx:1.16.1" # kpt-set: nginx:${tag}
ports:
- protocol: TCP
containerPort: 80
Declare the new desired values for setters in the functionConfig file.
# apply-setters-fn-config.yaml
apiVersion: v1
kind: ConfigMap
metadata:
name: apply-setters-fn-config
data:
nginx-replicas: "3"
tag: 1.16.2
Invoke the function:
$ kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable --fn-config ./apply-setters-fn-config
Alternatively, setter values can be passed as key-value pairs in the CLI
$ kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable -- image=ubuntu replicas=3
Modified resource looks like the following:
# resources.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: my-nginx
spec:
replicas: 3 # kpt-set: ${nginx-replicas}
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: "nginx:1.16.2" # kpt-set: nginx:${tag}
ports:
- protocol: TCP
containerPort: 80
Setting array values:
Array values can also be parameterized using setters. Since the values of configMap
in pipeline definition must be of string type, the array values must be wrapped into
string. However, the rendered values in the resources will be array type.
Let's start with the input resource
apiVersion: v1
kind: MyKind
metadata:
name: foo
environments: # kpt-set: ${env}
- dev
- stage
Declare the desired array values, wrapped into string.
apiVersion: v1
kind: ConfigMap
metadata:
name: apply-setters-fn-config
data:
env: |
- prod
- dev
Invoke the function using the input config:
$ kpt fn eval --image gcr.io/kpt-fn/apply-setters:unstable --fn-config ./apply-setters-fn-config
Modified resource looks like the following:
apiVersion: v1
kind: MyKind
metadata:
name: foo
environments: # kpt-set: ${env}
- prod
- dev
`