Skip to content

Commit 12b1077

Browse files
authored
Merge pull request #306 from yanniszark/feature-sortoptions-docs
Document sortOptions field
2 parents f75c126 + 63ee760 commit 12b1077

File tree

2 files changed

+132
-14
lines changed

2 files changed

+132
-14
lines changed
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
---
2+
title: "sortOptions"
3+
linkTitle: "sortOptions"
4+
type: docs
5+
weight: 22
6+
description: >
7+
Change the strategy used to sort resources at the end of the Kustomize build.
8+
---
9+
10+
The `sortOptions` field is used to sort the resources kustomize outputs. It is
11+
available in kustomize v5.0.0+.
12+
13+
IMPORTANT:
14+
- Currently, this field is respected only in the top-level Kustomization (that
15+
is, the immediate target of `kustomize build`). Any instances of the field in
16+
Kustomizations further down the build chain (for example, in bases included
17+
through the `resources` field) will be ignored.
18+
- This field is the endorsed way to sort resources. It should be used instead of
19+
the `--reorder` CLI flag, which is deprecated.
20+
21+
Currently, we support the following sort options:
22+
- `legacy`
23+
- `fifo`
24+
25+
```yaml
26+
kind: Kustomization
27+
sortOptions:
28+
order: legacy | fifo # "legacy" is the default
29+
```
30+
31+
## FIFO Sorting
32+
33+
In `fifo` order, kustomize does not change the order of resources. They appear
34+
in the order they are loaded in `resources`.
35+
36+
### Example 1: FIFO Sorting
37+
38+
```yaml
39+
kind: Kustomization
40+
sortOptions:
41+
order: fifo
42+
```
43+
44+
## Legacy Sorting
45+
46+
The `legacy` sort is the default order, and is used when the sortOrder field is
47+
unspecified.
48+
49+
In `legacy` order, kustomize sorts resources by using two priority lists:
50+
- An `orderFirst` list for resources which should be first in the output.
51+
- An `orderLast` list for resources which should be last in the output.
52+
- Resources not on the lists will appear in between, sorted using their apiVersion and kind fields.
53+
54+
### Example 2: Legacy Sorting with orderFirst / orderLast lists
55+
56+
In this example, we use the `legacy` sort order to output `Namespace` objects
57+
first and `Deployment` objects last.
58+
59+
```yaml
60+
kind: Kustomization
61+
sortOptions:
62+
order: legacy
63+
legacySortOptions:
64+
orderFirst:
65+
- Namespace
66+
orderLast:
67+
- Deployment
68+
```
69+
70+
### Example 3: Default Legacy Sorting
71+
72+
If you specify `legacy` sort order without any arguments for the lists,
73+
kustomize will fall back to the lists we were using before introducing this
74+
feature. Since legacy sort is the default, this is also equivalent to not
75+
specifying the field at all.
76+
77+
These two configs are equivalent:
78+
79+
```yaml
80+
kind: Kustomization
81+
sortOptions:
82+
order: legacy
83+
```
84+
85+
is equivalent to:
86+
87+
```yaml
88+
kind: Kustomization
89+
sortOptions:
90+
order: legacy
91+
legacySortOptions:
92+
orderFirst:
93+
- Namespace
94+
- ResourceQuota
95+
- StorageClass
96+
- CustomResourceDefinition
97+
- ServiceAccount
98+
- PodSecurityPolicy
99+
- Role
100+
- ClusterRole
101+
- RoleBinding
102+
- ClusterRoleBinding
103+
- ConfigMap
104+
- Secret
105+
- Endpoints
106+
- Service
107+
- LimitRange
108+
- PriorityClass
109+
- PersistentVolume
110+
- PersistentVolumeClaim
111+
- Deployment
112+
- StatefulSet
113+
- CronJob
114+
- PodDisruptionBudget
115+
orderLast:
116+
- MutatingWebhookConfiguration
117+
- ValidatingWebhookConfiguration
118+
```

site/content/en/references/kustomize/kustomization/vars/_index.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: "vars"
33
linkTitle: "vars"
44
type: docs
5-
weight: 22
5+
weight: 23
66
description: >
77
Substitute name references.
88
---
@@ -11,7 +11,7 @@ description: >
1111

1212
WARNING: There are plans to deprecate vars. For existing users of vars, we recommend migration to [replacements]
1313
as early as possible. There is a guide for convering vars to replacements at the bottom of this page under
14-
"convert vars to replacements". For new users, we recommend never using vars, and starting with replacements
14+
"convert vars to replacements". For new users, we recommend never using vars, and starting with replacements
1515
to avoid migration in the future.
1616

1717
Vars are used to capture text from one resource's field
@@ -134,7 +134,7 @@ vars:
134134
In order to convert `vars` to `replacements`, we have to:
135135
1. Replace every instance of $(SOME_SECRET_NAME) with any arbitrary placeholder value.
136136
2. Convert the vars `objref` field to a [replacements] `source` field.
137-
3. Replace the vars `name` fied with a [replacements] `targets` field that points to
137+
3. Replace the vars `name` fied with a [replacements] `targets` field that points to
138138
every instance of the placeholder value in step 1.
139139

140140
In our simple example here, this would look like the following:
@@ -169,7 +169,7 @@ replacements:
169169
name: my-secret
170170
version: v1
171171
targets:
172-
- select:
172+
- select:
173173
kind: Pod
174174
name: my-pod
175175
fieldPaths:
@@ -178,9 +178,9 @@ replacements:
178178

179179
#### More complex migration example
180180

181-
Let's take a more complex usage of vars and convert it to [replacements]. We are going
181+
Let's take a more complex usage of vars and convert it to [replacements]. We are going
182182
to convert the vars in the [wordpress example](https://github.com/kubernetes-sigs/kustomize/tree/master/examples/wordpress)
183-
to replacements.
183+
to replacements.
184184

185185
The wordpress example has the following directory structure:
186186

@@ -228,15 +228,15 @@ spec:
228228
```
229229

230230
and the top level `kustomization.yaml` has the following contents:
231-
231+
232232
```
233233
resources:
234234
- wordpress
235235
- mysql
236236
patchesStrategicMerge:
237237
- patch.yaml
238238
namePrefix: demo-
239-
239+
240240
vars:
241241
- name: WORDPRESS_SERVICE
242242
objref:
@@ -255,7 +255,7 @@ In this example, the patch is used to:
255255
- Add environment variable that allow wordpress to find the mysql database
256256

257257
We can convert vars to replacements in this more complex case too, by taking the same steps as
258-
the previous example. To do this, we can change the contents of `patch.yaml` to:
258+
the previous example. To do this, we can change the contents of `patch.yaml` to:
259259

260260
```yaml
261261
apiVersion: apps/v1
@@ -283,7 +283,7 @@ spec:
283283
284284
```
285285

286-
Then, in our kustomization, we can have our replacements:
286+
Then, in our kustomization, we can have our replacements:
287287

288288
`kustomization.yaml`
289289

@@ -296,22 +296,22 @@ patchesStrategicMerge:
296296
namePrefix: demo-
297297
298298
replacements:
299-
- source:
299+
- source:
300300
name: demo-wordpress
301301
kind: Service
302302
version: v1
303303
targets:
304-
- select:
304+
- select:
305305
kind: Deployment
306306
name: demo-wordpress
307307
fieldPaths:
308308
- spec.template.spec.initContainers.[name=init-command].args.2
309-
- source:
309+
- source:
310310
name: demo-mysql
311311
kind: Service
312312
version: v1
313313
targets:
314-
- select:
314+
- select:
315315
kind: Deployment
316316
name: demo-wordpress
317317
fieldPaths:

0 commit comments

Comments
 (0)