| 1 |
|
| 2 |
package api |
| 3 |
|
| 4 |
var ConfigIoLong = `# Configuration IO API Semantics |
| 5 |
|
| 6 |
Resource Configuration may be read / written from / to sources such as directories, |
| 7 |
stdin|out or network. Tools may be composed using pipes such that the tools writing |
| 8 |
Resource Configuration may be a different tool from the one that read the configuration. |
| 9 |
In order for tools to be composed in this way, while preserving origin information -- |
| 10 |
such as the original file, index, etc.: |
| 11 |
|
| 12 |
Tools **SHOULD** insert the following annotations when reading from sources, |
| 13 |
and **SHOULD** delete the annotations when writing to sinks. |
| 14 |
|
| 15 |
### ` + "`" + `config.kubernetes.io/path` + "`" + ` |
| 16 |
|
| 17 |
Records the slash-delimited, OS-agnostic, relative file path to a Resource. |
| 18 |
|
| 19 |
This annotation **SHOULD** be set when reading Resources from files. |
| 20 |
It **SHOULD** be unset when writing Resources to files. |
| 21 |
When writing Resources to a directory, the Resource **SHOULD** be written to the corresponding |
| 22 |
path relative to that directory. |
| 23 |
|
| 24 |
Example: |
| 25 |
|
| 26 |
metadata: |
| 27 |
annotations: |
| 28 |
config.kubernetes.io/path: "relative/file/path.yaml" |
| 29 |
|
| 30 |
### ` + "`" + `config.kubernetes.io/index` + "`" + ` |
| 31 |
|
| 32 |
Records the index of a Resource in file. In a multi-object YAML file, Resources are separated |
| 33 |
by three dashes (` + "`" + `---` + "`" + `), and the index represents the position of the Resource starting from zero. |
| 34 |
|
| 35 |
This annotation **SHOULD** be set when reading Resources from files. |
| 36 |
It **SHOULD** be unset when writing Resources to files. |
| 37 |
When writing multiple Resources to the same file, the Resource **SHOULD** be written in the |
| 38 |
relative order matching the index. |
| 39 |
|
| 40 |
When this annotation is not specified, it implies a value of ` + "`" + `0` + "`" + `. |
| 41 |
|
| 42 |
Example: |
| 43 |
|
| 44 |
metadata: |
| 45 |
annotations: |
| 46 |
config.kubernetes.io/path: "relative/file/path.yaml" |
| 47 |
config.kubernetes.io/index: 2 |
| 48 |
|
| 49 |
This represents the third Resource in the file. |
| 50 |
|
| 51 |
### ` + "`" + `config.kubernetes.io/local-config` + "`" + ` |
| 52 |
|
| 53 |
` + "`" + `config.kubernetes.io/local-config` + "`" + ` declares that the configuration is to local tools |
| 54 |
rather than a remote Resource. e.g. The ` + "`" + `Kustomization` + "`" + ` config in a ` + "`" + `kustomization.yaml` + "`" + ` |
| 55 |
**SHOULD** contain this annotation so that tools know it is not intended to be sent to |
| 56 |
the Kubernetes api server. |
| 57 |
|
| 58 |
Example: |
| 59 |
|
| 60 |
metadata: |
| 61 |
annotations: |
| 62 |
config.kubernetes.io/local-config: "true"` |
| 63 |
|
| 64 |
var ( |
| 65 |
FunctionsImplShort = `Following is an example for implementing an nginx abstraction using a configuration` |
| 66 |
FunctionsImplLong = `# Running Configuration Functions using kustomize CLI |
| 67 |
|
| 68 |
Configuration functions can be implemented using any toolchain and invoked using any |
| 69 |
container workflow orchestrator including Tekton, Cloud Build, or run directly using ` + "`" + `docker run` + "`" + `. |
| 70 |
|
| 71 |
Run ` + "`" + `config help docs-fn-spec` + "`" + ` to see the Configuration Functions Specification. |
| 72 |
|
| 73 |
` + "`" + `kustomize fn run` + "`" + ` is an example orchestrator for invoking Configuration Functions. This |
| 74 |
document describes how to implement and invoke an example function. |
| 75 |
|
| 76 |
function. |
| 77 |
|
| 78 |
### ` + "`" + `nginx-template.sh` + "`" + ` |
| 79 |
|
| 80 |
` + "`" + `nginx-template.sh` + "`" + ` is a simple bash script which uses a _heredoc_ as a templating solution |
| 81 |
for generating Resources from the functionConfig input fields. |
| 82 |
|
| 83 |
The script wraps itself using ` + "`" + `config run wrap -- $0` + "`" + ` which will: |
| 84 |
|
| 85 |
1. Parse the ` + "`" + `ResourceList.functionConfig` + "`" + ` (provided to the container stdin) into env vars |
| 86 |
2. Merge the stdout into the original list of Resources |
| 87 |
3. Defaults filenames for newly generated Resources (if they are not set as annotations) |
| 88 |
to ` + "`" + `config/NAME_KIND.yaml` + "`" + ` |
| 89 |
4. Format the output |
| 90 |
|
| 91 |
#!/bin/bash |
| 92 |
# script must run wrapped by "kustomize fn run wrap" |
| 93 |
# for parsing input the functionConfig into env vars |
| 94 |
if [ -z ${WRAPPED} ]; then |
| 95 |
export WRAPPED=true |
| 96 |
config run wrap -- $0 |
| 97 |
exit $? |
| 98 |
fi |
| 99 |
|
| 100 |
cat <<End-of-message |
| 101 |
apiVersion: v1 |
| 102 |
kind: Service |
| 103 |
metadata: |
| 104 |
name: ${NAME} |
| 105 |
labels: |
| 106 |
app: nginx |
| 107 |
instance: ${NAME} |
| 108 |
spec: |
| 109 |
ports: |
| 110 |
- port: 80 |
| 111 |
targetPort: 80 |
| 112 |
name: http |
| 113 |
selector: |
| 114 |
app: nginx |
| 115 |
instance: ${NAME} |
| 116 |
--- |
| 117 |
apiVersion: apps/v1 |
| 118 |
kind: Deployment |
| 119 |
metadata: |
| 120 |
name: ${NAME} |
| 121 |
labels: |
| 122 |
app: nginx |
| 123 |
instance: ${NAME} |
| 124 |
spec: |
| 125 |
replicas: ${REPLICAS} |
| 126 |
selector: |
| 127 |
matchLabels: |
| 128 |
app: nginx |
| 129 |
instance: ${NAME} |
| 130 |
template: |
| 131 |
metadata: |
| 132 |
labels: |
| 133 |
app: nginx |
| 134 |
instance: ${NAME} |
| 135 |
spec: |
| 136 |
containers: |
| 137 |
- name: nginx |
| 138 |
image: nginx:1.7.9 |
| 139 |
ports: |
| 140 |
- containerPort: 80 |
| 141 |
End-of-message |
| 142 |
|
| 143 |
### Dockerfile |
| 144 |
|
| 145 |
` + "`" + `Dockerfile` + "`" + ` installs ` + "`" + `kustomize fn` + "`" + ` and copies the script into the container image. |
| 146 |
|
| 147 |
FROM public.ecr.aws/docker/library/golang:1.24.6-bullseye |
| 148 |
RUN go get sigs.k8s.io/kustomize/cmd/config |
| 149 |
RUN mv /go/bin/config /usr/bin/config |
| 150 |
COPY nginx-template.sh /usr/bin/nginx-template.sh |
| 151 |
CMD ["nginx-template.sh] |
| 152 |
|
| 153 |
## Example Function Usage |
| 154 |
|
| 155 |
Following is an example of running the ` + "`" + `kustomize fn run` + "`" + ` using the preceding API. |
| 156 |
|
| 157 |
When run by ` + "`" + `kustomize fn run` + "`" + `, functions are run in containers with the |
| 158 |
following environment: |
| 159 |
|
| 160 |
- Network: ` + "`" + `none` + "`" + ` |
| 161 |
- User: ` + "`" + `nobody` + "`" + ` |
| 162 |
- Security Options: ` + "`" + `no-new-privileges` + "`" + ` |
| 163 |
- Volumes: the volume containing the ` + "`" + `functionConfig` + "`" + ` yaml is mounted under ` + "`" + `/local` + "`" + ` as ` + "`" + `ro` + "`" + ` |
| 164 |
|
| 165 |
### Input |
| 166 |
|
| 167 |
` + "`" + `dir/nginx.yaml` + "`" + ` contains a reference to the Function. The contents of ` + "`" + `nginx.yaml` + "`" + ` |
| 168 |
are passed to the Function through the ` + "`" + `ResourceList.functionConfig` + "`" + ` field. |
| 169 |
|
| 170 |
apiVersion: example.com/v1beta1 |
| 171 |
kind: Nginx |
| 172 |
metadata: |
| 173 |
name: my-instance |
| 174 |
annotations: |
| 175 |
config.kubernetes.io/local-config: "true" |
| 176 |
config.kubernetes.io/function: | |
| 177 |
container: |
| 178 |
image: gcr.io/example-functions/nginx-template:v1.0.0 |
| 179 |
spec: |
| 180 |
replicas: 5 |
| 181 |
|
| 182 |
- ` + "`" + `annotations[config.kubernetes.io/function].container.image` + "`" + `: the image to use for this API |
| 183 |
- ` + "`" + `annotations[config.kubernetes.io/local-config]` + "`" + `: mark this as not a Resource that should |
| 184 |
be applied |
| 185 |
|
| 186 |
### Output |
| 187 |
|
| 188 |
The function is invoked using byrunning ` + "`" + `kustomize fn run dir/` + "`" + `. |
| 189 |
|
| 190 |
` + "`" + `dir/my-instance_deployment.yaml` + "`" + ` contains the Deployment: |
| 191 |
|
| 192 |
apiVersion: apps/v1 |
| 193 |
kind: Deployment |
| 194 |
metadata: |
| 195 |
name: my-instance |
| 196 |
labels: |
| 197 |
app: nginx |
| 198 |
instance: my-instance |
| 199 |
spec: |
| 200 |
replicas: 5 |
| 201 |
selector: |
| 202 |
matchLabels: |
| 203 |
app: nginx |
| 204 |
instance: my-instance |
| 205 |
template: |
| 206 |
metadata: |
| 207 |
labels: |
| 208 |
app: nginx |
| 209 |
instance: my-instance |
| 210 |
spec: |
| 211 |
containers: |
| 212 |
- name: nginx |
| 213 |
image: nginx:1.7.9 |
| 214 |
ports: |
| 215 |
- containerPort: 80 |
| 216 |
|
| 217 |
` + "`" + `dir/my-instance_service.yaml` + "`" + ` contains the Service: |
| 218 |
|
| 219 |
apiVersion: v1 |
| 220 |
kind: Service |
| 221 |
metadata: |
| 222 |
name: my-instance |
| 223 |
labels: |
| 224 |
app: nginx |
| 225 |
instance: my-instance |
| 226 |
spec: |
| 227 |
ports: |
| 228 |
- port: 80 |
| 229 |
targetPort: 80 |
| 230 |
name: http |
| 231 |
selector: |
| 232 |
app: nginx |
| 233 |
instance: my-instance` |
| 234 |
) |
| 235 |
|
| 236 |
var ( |
| 237 |
FunctionsSpecShort = `_Configuration functions_ enable shift-left practices (client-side) through:` |
| 238 |
FunctionsSpecLong = `# Configuration Functions Specification |
| 239 |
|
| 240 |
This document specifies a standard for client-side functions that operate on |
| 241 |
Kubernetes declarative configurations. This standard enables creating |
| 242 |
small, interoperable, and language-independent executable programs packaged as |
| 243 |
containers that can be chained together as part of a configuration management pipeline. |
| 244 |
The end result of such a pipeline are fully rendered configurations that can then be |
| 245 |
applied to a control plane (e.g. Using ‘kubectl apply’ for Kubernetes control plane). |
| 246 |
As such, although this document references Kubernetes Resource Model and API conventions, |
| 247 |
it is completely decoupled from Kubernetes API machinery and does not depend on any |
| 248 |
in-cluster components. |
| 249 |
|
| 250 |
This document references terms described in [Kubernetes API Conventions][1]. |
| 251 |
|
| 252 |
The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", |
| 253 |
"SHOULD NOT", "RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be |
| 254 |
interpreted as described in [RFC 2119][2]. |
| 255 |
|
| 256 |
|
| 257 |
- Pre-commit / delivery validation and linting of configuration |
| 258 |
- e.g. Fail if any containers don't have CPU / Memory limits |
| 259 |
- Implementation of abstractions as client actuated APIs (e.g. templating) |
| 260 |
- e.g. Create a client-side _"CRD"_ for generating configuration checked into git |
| 261 |
- Aspect Orient configuration / Injection of cross-cutting configuration |
| 262 |
- e.g. T-Shirt size containers by annotating Resources with ` + "`" + `small` + "`" + `, ` + "`" + `medium` + "`" + `, ` + "`" + `large` + "`" + ` |
| 263 |
and inject the cpu and memory resources into containers accordingly. |
| 264 |
- e.g. Inject ` + "`" + `init` + "`" + ` and ` + "`" + `side-car` + "`" + ` containers into Resources based off of Resource |
| 265 |
Type, annotations, etc. |
| 266 |
|
| 267 |
Performing these on the client rather than the server enables: |
| 268 |
|
| 269 |
- Configuration to be reviewed prior to being sent to the API server |
| 270 |
- Configuration to be validated as part of the CI/CD pipeline |
| 271 |
- Configuration for Resources to validated holistically rather than individually |
| 272 |
per-Resource |
| 273 |
- e.g. ensure the ` + "`" + `Service.selector` + "`" + ` and ` + "`" + `Deployment.spec.template` + "`" + ` labels |
| 274 |
match. |
| 275 |
- e.g. MutatingWebHooks are scoped to a single Resource instance at a time. |
| 276 |
- Low-level tweaks to the output of high-level abstractions |
| 277 |
- e.g. add an ` + "`" + `init container` + "`" + ` to a client _"CRD"_ Resource after it was generated. |
| 278 |
- Composition and layering of multiple functions together |
| 279 |
- Compose generation, injection, validation together |
| 280 |
|
| 281 |
## Spec |
| 282 |
|
| 283 |
### Input Type |
| 284 |
|
| 285 |
A function MUST accept as input a single [Kubernetes List type][3]. |
| 286 |
The ` + "`" + `items` + "`" + ` field in the input will contain a sequence of [Object types][3]. |
| 287 |
A function MAY not support [Simple types][3] and List types. |
| 288 |
|
| 289 |
An example using ` + "`" + `v1/ConfigMapList` + "`" + ` as input: |
| 290 |
|
| 291 |
apiVersion: v1 |
| 292 |
kind: ConfigMapList |
| 293 |
items: |
| 294 |
- apiVersion: v1 |
| 295 |
kind: ConfigMap |
| 296 |
metadata: |
| 297 |
name: config1 |
| 298 |
data: |
| 299 |
p1: v1 |
| 300 |
p2: v2 |
| 301 |
- apiVersion: v1 |
| 302 |
kind: ConfigMap |
| 303 |
metadata: |
| 304 |
name: config2 |
| 305 |
|
| 306 |
An example using ` + "`" + `v1/List` + "`" + ` as input: |
| 307 |
|
| 308 |
apiVersion: v1 |
| 309 |
kind: List |
| 310 |
items: |
| 311 |
- apiVersion: foo-corp.com/v1 |
| 312 |
kind: FulfillmentCenter |
| 313 |
metadata: |
| 314 |
name: staging |
| 315 |
address: "100 Main St." |
| 316 |
- apiVersion: rbac.authorization.k8s.io/v1 |
| 317 |
kind: ClusterRole |
| 318 |
metadata: |
| 319 |
name: namespace-reader |
| 320 |
rules: |
| 321 |
- resources: |
| 322 |
- namespaces |
| 323 |
apiGroups: |
| 324 |
- "" |
| 325 |
verbs: |
| 326 |
- get |
| 327 |
- watch |
| 328 |
- list |
| 329 |
|
| 330 |
In addition, a function MUST accept as input a List of kind ` + "`" + `ResourceList` + "`" + ` where the |
| 331 |
` + "`" + `functionConfig` + "`" + ` field, if present, will contain the invocation-specific configuration passed to the function |
| 332 |
by the orchestrator. |
| 333 |
Functions MAY consider this field optional so that they can be triggered in an ad-hoc fashion. |
| 334 |
|
| 335 |
An example using ` + "`" + `config.kubernetes.io/v1beta1/ResourceList` + "`" + ` as input: |
| 336 |
|
| 337 |
apiVersion: config.kubernetes.io/v1beta1 |
| 338 |
kind: ResourceList |
| 339 |
functionConfig: |
| 340 |
apiVersion: foo-corp.com/v1 |
| 341 |
kind: FulfillmentCenter |
| 342 |
metadata: |
| 343 |
name: staging |
| 344 |
metadata: |
| 345 |
annotations: |
| 346 |
config.kubernetes.io/function: | |
| 347 |
container: |
| 348 |
image: gcr.io/example/foo:v1.0.0 |
| 349 |
spec: |
| 350 |
address: "100 Main St." |
| 351 |
items: |
| 352 |
- apiVersion: rbac.authorization.k8s.io/v1 |
| 353 |
kind: ClusterRole |
| 354 |
metadata: |
| 355 |
name: namespace-reader |
| 356 |
rules: |
| 357 |
- resources: |
| 358 |
- namespaces |
| 359 |
apiGroups: |
| 360 |
- "" |
| 361 |
verbs: |
| 362 |
- get |
| 363 |
- watch |
| 364 |
- list |
| 365 |
|
| 366 |
Here ` + "`" + `FulfillmentCenter` + "`" + ` kind with name ` + "`" + `staging` + "`" + ` is passed as the invocation-specific configuration |
| 367 |
to the function. |
| 368 |
|
| 369 |
### Output Type |
| 370 |
|
| 371 |
A function’s output MUST be the same as the input specification above |
| 372 |
-- i.e. ` + "`" + `ResourceList` + "`" + ` or ` + "`" + `List` + "`" + `. |
| 373 |
This is necessary to enable chaining two or more functions together in a pipeline. |
| 374 |
The serialization format of the output SHOULD match that of its input on each invocation |
| 375 |
-- e.g. if the input was a ` + "`" + `ResourceList` + "`" + `, the output should also be a ` + "`" + `ResourceList` + "`" + `. |
| 376 |
|
| 377 |
### Serialization Format |
| 378 |
|
| 379 |
A function MUST support YAML as a serialization format for the input and output. |
| 380 |
A function MUST use utf8 encoding (as YAML is a superset of JSON, JSON will also be supported |
| 381 |
by any conforming function). |
| 382 |
|
| 383 |
### Operations |
| 384 |
|
| 385 |
A function MAY Create, Update, or Delete any number of items in the ` + "`" + `items` + "`" + ` field and output the |
| 386 |
resultant list. |
| 387 |
|
| 388 |
A function MAY modify annotations with prefix ` + "`" + `config.kubernetes.io` + "`" + `, but must be careful about |
| 389 |
doing so since they’re used for orchestration purposes and will likely impact subsequent functions |
| 390 |
in the pipeline. |
| 391 |
|
| 392 |
A function SHOULD preserve comments when input serialization format is YAML. |
| 393 |
This allows for human authoring of configuration to coexist with changes made by functions. |
| 394 |
|
| 395 |
### Containerization |
| 396 |
|
| 397 |
A function MUST be implemented as a container. |
| 398 |
|
| 399 |
A function container MUST be capable of running as a non-root user if it does not require |
| 400 |
access to host filesystem or makes network calls. |
| 401 |
|
| 402 |
### stdin/stdout/stderr and Exit Codes |
| 403 |
|
| 404 |
A function MUST accept input from stdin and emit output to stdout. |
| 405 |
|
| 406 |
Any error messages MUST be emitted to stderr. |
| 407 |
|
| 408 |
An exit code of zero indicates function execution was successful. |
| 409 |
A non-zero exit code indicates a failure. |
| 410 |
|
| 411 |
[1]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md |
| 412 |
[2]: https://tools.ietf.org/html/rfc2119 |
| 413 |
[3]: https://github.com/kubernetes/community/blob/master/contributors/devel/sig-architecture/api-conventions.md#types-kinds` |
| 414 |
) |
| 415 |
|
| 416 |
var Merge2Long = `# Merge (2-way) |
| 417 |
|
| 418 |
2-way merges fields from a source to a destination, overriding the destination fields |
| 419 |
where they differ. |
| 420 |
|
| 421 |
### Merge Rules |
| 422 |
|
| 423 |
Fields are recursively merged using the following rules: |
| 424 |
|
| 425 |
- scalars |
| 426 |
- if present only in the dest, it keeps its value |
| 427 |
- if present in the src and is non-null, take the src value -- if ` + "`" + `null` + "`" + `, clear it |
| 428 |
- example src: ` + "`" + `5` + "`" + `, dest: ` + "`" + `3` + "`" + ` => result: ` + "`" + `5` + "`" + ` |
| 429 |
|
| 430 |
- non-associative lists -- lists without a merge key |
| 431 |
- if present only in the dest, it keeps its value |
| 432 |
- if present in the src and is non-null, take the src value -- if ` + "`" + `null` + "`" + `, clear it |
| 433 |
- example src: ` + "`" + `[1, 2, 3]` + "`" + `, dest: ` + "`" + `[a, b, c]` + "`" + ` => result: ` + "`" + `[1, 2, 3]` + "`" + ` |
| 434 |
|
| 435 |
- map keys and fields -- paired by the map-key / field-name |
| 436 |
- if present only in the dest, it keeps its value |
| 437 |
- if present only in the src, it is added to the dest |
| 438 |
- if the field is present in both the src and dest, and the src value is |
| 439 |
` + "`" + `null` + "`" + `, the field is removed from the dest |
| 440 |
- if the field is present in both the src and dest, the value is recursively merged |
| 441 |
- example src: ` + "`" + `{'key1': 'value1', 'key2': 'value2'}` + "`" + `, |
| 442 |
dest: ` + "`" + `{'key2': 'value0', 'key3': 'value3'}` + "`" + ` |
| 443 |
=> result: ` + "`" + `{'key1': 'value1', 'key2': 'value2', 'key3': 'value3'}` + "`" + ` |
| 444 |
|
| 445 |
- associative list elements -- paired by the associative key |
| 446 |
- if present only in the dest, it keeps its value in the list |
| 447 |
- if present only in the src, it is added to the dest list |
| 448 |
- if the field is present in both the src and dest, the value is recursively merged |
| 449 |
|
| 450 |
### Associative Keys |
| 451 |
|
| 452 |
Associative keys are used to identify "same" elements within 2 different lists, and merge them. |
| 453 |
The following fields are recognized as associative keys: |
| 454 |
|
| 455 |
[` + "`" + `mountPath` + "`" + `, ` + "`" + `devicePath` + "`" + `, ` + "`" + `ip` + "`" + `, ` + "`" + `type` + "`" + `, ` + "`" + `topologyKey` + "`" + `, ` + "`" + `name` + "`" + `, ` + "`" + `containerPort` + "`" + `] |
| 456 |
|
| 457 |
Any lists where all of the elements contain associative keys will be merged as associative lists. |
| 458 |
|
| 459 |
### Example |
| 460 |
|
| 461 |
> Source |
| 462 |
|
| 463 |
apiVersion: apps/v1 |
| 464 |
kind: Deployment |
| 465 |
spec: |
| 466 |
replicas: 3 # scalar |
| 467 |
template: |
| 468 |
spec: |
| 469 |
containers: # associative list -- (name) |
| 470 |
- name: nginx |
| 471 |
image: nginx:1.7 |
| 472 |
command: ['new_run.sh', 'arg1'] # non-associative list |
| 473 |
- name: sidecar2 |
| 474 |
image: sidecar2:v1 |
| 475 |
|
| 476 |
> Destination |
| 477 |
|
| 478 |
apiVersion: apps/v1 |
| 479 |
kind: Deployment |
| 480 |
spec: |
| 481 |
replicas: 1 |
| 482 |
template: |
| 483 |
spec: |
| 484 |
containers: |
| 485 |
- name: nginx |
| 486 |
image: nginx:1.6 |
| 487 |
command: ['old_run.sh', 'arg0'] |
| 488 |
- name: sidecar1 |
| 489 |
image: sidecar1:v1 |
| 490 |
|
| 491 |
> Result |
| 492 |
|
| 493 |
apiVersion: apps/v1 |
| 494 |
kind: Deployment |
| 495 |
spec: |
| 496 |
replicas: 3 # scalar |
| 497 |
template: |
| 498 |
spec: |
| 499 |
containers: # associative list -- (name) |
| 500 |
- name: nginx |
| 501 |
image: nginx:1.7 |
| 502 |
command: ['new_run.sh', 'arg1'] # non-associative list |
| 503 |
- name: sidecar1 |
| 504 |
image: sidecar1:v1 |
| 505 |
- name: sidecar2 |
| 506 |
image: sidecar2:v1` |
| 507 |
|
| 508 |
var Merge3Long = `# Merge (3-way) |
| 509 |
|
| 510 |
3-way merge identifies changes between an original source + updated source and merges the result |
| 511 |
into a destination, overriding the destination fields where they have changed between |
| 512 |
original and updated. |
| 513 |
|
| 514 |
### Resource MergeRules |
| 515 |
|
| 516 |
- Resources present in the original and deleted from the update are deleted. |
| 517 |
- Resources missing from the original and added in the update are added. |
| 518 |
- Resources present only in the dest are kept without changes. |
| 519 |
- Resources present in both the update and the dest have their fields merged with the destination. |
| 520 |
|
| 521 |
### Field Merge Rules |
| 522 |
|
| 523 |
Fields are recursively merged using the following rules: |
| 524 |
|
| 525 |
- scalars |
| 526 |
- if present in either dest or updated and ` + "`" + `null` + "`" + `, clear the value |
| 527 |
- if unchanged between original and updated, keep dest value |
| 528 |
- if changed between original and updated (added, deleted, changed), take the updated value |
| 529 |
|
| 530 |
- non-associative lists -- lists without a merge key |
| 531 |
- if present in either dest or updated and ` + "`" + `null` + "`" + `, clear the value |
| 532 |
- if unchanged between original and updated, keep dest value |
| 533 |
- if changed between original and updated (added, deleted, changed), take the updated value |
| 534 |
|
| 535 |
- map keys and fields -- paired by the map-key / field-name |
| 536 |
- if present in either dest or updated and ` + "`" + `null` + "`" + `, clear the value |
| 537 |
- if present only in the dest, it keeps its value |
| 538 |
- if not-present in the dest, add the delta between original-updated as a field |
| 539 |
- otherwise recursively merge the value between original, updated, dest |
| 540 |
|
| 541 |
- associative list elements -- paired by the associative key |
| 542 |
- if present only in the dest, it keeps its value |
| 543 |
- if not-present in the dest, add the delta between original-updated as a field |
| 544 |
- otherwise recursively merge the value between original, updated, dest |
| 545 |
|
| 546 |
### Associative Keys |
| 547 |
|
| 548 |
Associative keys are used to identify "same" elements within 2 different lists, and merge them. |
| 549 |
The following fields are recognized as associative keys: |
| 550 |
|
| 551 |
[` + "`" + `mountPath` + "`" + `, ` + "`" + `devicePath` + "`" + `, ` + "`" + `ip` + "`" + `, ` + "`" + `type` + "`" + `, ` + "`" + `topologyKey` + "`" + `, ` + "`" + `name` + "`" + `, ` + "`" + `containerPort` + "`" + `] |
| 552 |
|
| 553 |
Any lists where all of the elements contain associative keys will be merged as associative lists.` |