Skip to content

Commit

Permalink
Document sortOptions field
Browse files Browse the repository at this point in the history
Kustomize has a new field called "sortOptions" to sort resources:
kubernetes-sigs/kustomize#3913
kubernetes-sigs/kustomize#4019

Document what it does and how to use it.

Signed-off-by: Yannis Zarkadas <yanniszark@gmail.com>
  • Loading branch information
yanniszark committed Dec 9, 2022
1 parent 28bc5ff commit 41be91c
Showing 1 changed file with 105 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
---
title: "sortOptions"
linkTitle: "sortOptions"
type: docs
weight: 23
description: >
Sort the kustomize resources.
---

The `sortOptions` field is used to sort the resources kustomize outputs.

IMPORTANT:
- Currently, this field is enforced only for the top-level kustomization.
- This is the endorsed way to sort resources. Users should avoid using
the CLI flag `--reorder` and instead use `sortOptions`.

Currently, we support the following sort options:
- `legacy`
- `fifo`

## Legacy Sorting

In `legacy` order, kustomize sorts resources by using two priority lists:
- An `orderFirst` list for resources which should be first in the output.
- An `orderLast` list for resources which should be last in the output.
- Resources not on the lists are will appear in-between, sorted by their GVK.

### Example 1: Legacy Sorting with orderFirst / orderLast lists

In this example, we use the `legacy` sort order to output `Namespace` objects
first and `Deployment` objects last.

```yaml
kind: Kustomization
sortOptions:
order: legacy
legacySortOptions:
orderFirst:
- Namespace
orderLast:
- Deployment
```

### Example 2: Default Legacy Sorting

If you specify `legacy` sort order without any arguments for the lists,
kustomize will fall back to the lists we were using before introducing this
feature. This is useful if you want to continue using the sort order kustomize
was using by-default before introducing this feature.

These two configs are equivalent:

```yaml
kind: Kustomization
sortOptions:
order: legacy
```

is equivalent to:

```yaml
kind: Kustomization
sortOptions:
order: legacy
legacySortOptions:
orderFirst:
- Namespace
- ResourceQuota
- StorageClass
- CustomResourceDefinition
- ServiceAccount
- PodSecurityPolicy
- Role
- ClusterRole
- RoleBinding
- ClusterRoleBinding
- ConfigMap
- Secret
- Endpoints
- Service
- LimitRange
- PriorityClass
- PersistentVolume
- PersistentVolumeClaim
- Deployment
- StatefulSet
- CronJob
- PodDisruptionBudget
orderLast:
- MutatingWebhookConfiguration
- ValidatingWebhookConfiguration
```

## FIFO Sorting

In `fifo` order, kustomize does not change the order of resources. They appear
in the order they are loaded in `resources`.

### Example 3: FIFO Sorting

```yaml
kind: Kustomization
sortOptions:
order: fifo
```

0 comments on commit 41be91c

Please sign in to comment.