Skip to content

Commit 1df8b3e

Browse files
committed
Kustomize Resource Ordering Proposal
1 parent a1dc903 commit 1df8b3e

File tree

1 file changed

+133
-0
lines changed

1 file changed

+133
-0
lines changed

keps/sig-cli/kustomize-ordering.md

+133
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
---
2+
title: Kustomize Resource Ordering
3+
authors:
4+
- "@pwittrock"
5+
owning-sig: sig-cli
6+
participating-sigs:
7+
- sig-apps
8+
- sig-api-machinery
9+
reviewers:
10+
- "@apelisse"
11+
- "@anguslees"
12+
approvers:
13+
- "@monopole"
14+
editors:
15+
- "@pwittrock"
16+
creation-date: 2019-03-1
17+
last-updated: 2019-03-1
18+
status: implementable
19+
see-also:
20+
replaces:
21+
superseded-by:
22+
- n/a
23+
---
24+
25+
# Kustomize Resource Ordering
26+
27+
## Table of Contents
28+
* [Table of Contents](#table-of-contents)
29+
* [Summary](#summary)
30+
* [Motivation](#motivation)
31+
* [Goals](#goals)
32+
* [Non-Goals](#non-goals)
33+
* [Proposal](#proposal)
34+
* [Implementation Details/Notes/Constraints](#implementation-detailsnotesconstraints)
35+
* [Risks and Mitigations](#risks-and-mitigations)
36+
* [Graduation Criteria](#graduation-criteria)
37+
* [Implementation History](#implementation-history)
38+
* [Alternatives](#alternatives)
39+
40+
[Tools for generating]: https://github.com/ekalinin/github-markdown-toc
41+
42+
## Summary
43+
44+
Kustomize orders Resource creation by sorting the Resources it emits based off their type. While
45+
this works well for most types (e.g. create Namespaces before other things), it doesn't work
46+
in all cases and users will need the ability to break glass.
47+
48+
See [kubernetes-sigs/kustomize#836] for an example.
49+
50+
## Motivation
51+
52+
Users may need direct control of the Resource create / update / delete ordering in cases were
53+
sorting by Resource Type is insufficient.
54+
55+
### Goals
56+
57+
- Provide the ability for users to break glass and override Kustomize's sort ordering.
58+
59+
### Non-Goals
60+
61+
## Proposal
62+
63+
Add a new field `resourceOrdering` that is a list of `key, value, type` tuples to define the ordering.
64+
65+
Example:
66+
67+
```
68+
resourceOrdering:
69+
- name: first
70+
- type: label
71+
key: some-label-name-1
72+
value: some-label-value-1
73+
- type: annotation
74+
key: some-annotation-name-a
75+
value: some-label-value-a
76+
- name: second
77+
- type: annotation
78+
key: some-annotation-name-b
79+
value: some-annotation-value-b
80+
- name: third
81+
type: label
82+
key: some-label-name-2
83+
value: some-label-value-2
84+
```
85+
86+
The explicit user defined ordering using labels and annotations would take precedence over the
87+
ordering based off types. Types would be used as a secondary sorting function.
88+
89+
- Resources labeled with `some-label-name-1=some-label-value-1` *and* annotated
90+
with `some-annotation-name-a=some-label-value-a` are first
91+
- These Resources are sorted by type
92+
- Resources annotated with `some-annotation-name-a=some-annotation-value-b` are second
93+
- These Resources are sorted by type
94+
- Resources labeled with `some-label-name-2=some-label-value-2` are third
95+
- These Resources are sorted by type
96+
- Resources not matching any label or annotation are last
97+
- These Resources are sorted by type
98+
99+
Resources matching multiple orderings (e.g. have multiple matching labels and annotations) appear
100+
in the position matching the earliest label / annotation.
101+
102+
### Risks and Mitigations
103+
104+
Risk: Users build complex orderings that are hard to reason about.
105+
Mitigation: Good documentation and recommendations about how to keep things simple.
106+
107+
## Graduation Criteria
108+
109+
NA
110+
111+
112+
## Docs
113+
114+
Update Kubectl Book and Kustomize Documentation
115+
116+
## Test plan
117+
118+
Unit Tests for:
119+
120+
- [ ] Resources with labels and annotations follow the ordering override semantics
121+
- [ ] Resources matching multiple orderings land in the right spot
122+
- [ ] Resources are sorted by type as a secondary factor
123+
- [ ] Having multiple labels / annotations with the same key and different values works correctly
124+
- [ ] Having multiple labels / annotations with different keys and the same values works correctly
125+
- [ ] Mixing labels and annotations works
126+
- [ ] Unrecognized type values throw and error
127+
- [ ] Resources that don't appear in the ordering overrides appear last and are sorted by type
128+
129+
### Version Skew Tests
130+
131+
## Implementation History
132+
133+
## Alternatives

0 commit comments

Comments
 (0)