@@ -54,59 +54,104 @@ sorting by Resource Type is insufficient.
54
54
55
55
### Goals
56
56
57
- - Provide the ability for users to break glass and override Kustomize's sort ordering.
57
+ - Provide the ability for users to override the order that Kustomize emits Resources
58
+ - Used by ` kubectl apply ` or order Resource operations
59
+ - Used to override creation order for meta-Resources such as Namespaces
58
60
59
61
### Non-Goals
60
62
63
+ - Ensure certain Resources are * Settled* or * Ready* before other Resources
64
+ - Ensure dependencies between Workloads
65
+
61
66
## Proposal
62
67
63
- Add a new field ` resourceOrdering ` that is a list of ` key, value, type ` tuples to define the ordering.
68
+ Provide a simple mechanism allowing users to override the order that
69
+ Resource operations are Applied. Add a new field ` sortOrder ` that is
70
+ a list of ` ResourceSelector ` s which match Resources based
71
+ off their annotations.
72
+
73
+ ``` go
74
+
75
+ type Kustomization struct {
76
+ // ...
77
+
78
+ // sortOrder defines a precedence for ordering Resources. Resources
79
+ // will be sorted in the order the match a ResourecSelector before
80
+ // they are emitted.
81
+ SortOrder []ResourceSelector ` json:"sortOrder"`
82
+
83
+ // ...
84
+ }
85
+
86
+ // ResourceSelector selects Resources that it matches
87
+ type ResourceSelector struct {
88
+ // matchAnnotations is a map of {key,value} pairs. A Resource matches if it has
89
+ // *all* of the annotations in matchAnnotations appear in the Resource metaData.
90
+ // Null and empty values are not allowed.
91
+ // +optional
92
+ MatchAnnotations map [string ]string ` json:"matchAnnotations,omitempty"`
93
+
94
+ // TODO: Consider adding field: MatchExpressions []AnnotationSelectorRequirement
95
+ }
64
96
97
+ ```
65
98
Example:
66
99
67
100
```
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
101
+ sortOrder:
102
+ - matchAnnotations:
103
+ some-annotation-name-1: some-annotation-value-1
104
+ some-annotation-name-a: some-label-value-a
105
+ - matchAnnotations:
106
+ some-annotation-name-1: some-annotation-value-1
107
+ - matchAnnotations:
108
+ some-annotation-name-2: some-annotation-value-2
84
109
```
85
110
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.
111
+ The explicit user defined ordering using annotations will take precedence over the type based
112
+ orderings. Types would be used as a fallback sorting function amongst Resource with equal
113
+ precedence in the explicit ordering.
88
114
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
115
+ - Resources annotated with ` some-annotation -name-1: some-annotation -value-1 ` * and* annotated
116
+ with ` some-annotation-name-a: some-annotation -value-a ` are first
91
117
- These Resources are sorted by type
92
- - Resources annotated with ` some-annotation-name-a=some-annotation-value-b ` are second
118
+ - Resources annotated with ` some-annotation-name-1=some-annotation-value-1 `
119
+ (without ` some-annotation-name-a: some-annotation-value-a ` ) appear second
93
120
- These Resources are sorted by type
94
- - Resources labeled with ` some-label -name-2=some-label -value-2 ` are third
121
+ - Resources annotated with ` some-annotation -name-2=some-annotation -value-2 ` appear third
95
122
- These Resources are sorted by type
96
- - Resources not matching any label or annotation are last
123
+ - Resources not matching any annotation are last
97
124
- These Resources are sorted by type
98
125
99
- Resources matching multiple orderings (e.g. have multiple matching labels and annotations) appear
126
+ Resources matching multiple orderings (e.g. have multiple matching annotations) appear
100
127
in the position matching the earliest label / annotation.
101
128
129
+ ** Note:** Throw an error if there is a selector that selects a superset of another selector
130
+ and it appears first. e.g. this should throw an error because the first selector will match
131
+ everything that the second selector does, and it will have no effect.
132
+
133
+ ```
134
+ sortOrder:
135
+ - matchAnnotations:
136
+ some-annotation-name-1: some-annotation-value-1
137
+ - matchAnnotations:
138
+ some-annotation-name-1: some-annotation-value-1
139
+ some-annotation-name-a: some-label-value-a
140
+ ```
141
+
102
142
### Risks and Mitigations
103
143
104
144
Risk: Users build complex orderings that are hard to reason about.
105
145
Mitigation: Good documentation and recommendations about how to keep things simple.
106
146
107
147
## Graduation Criteria
108
148
109
- NA
149
+ Use customer feedback to determine if we should support:
150
+
151
+ - ` LabelSelectors `
152
+ - ` AnnotationSelectorRequirement ` (like ` LabelSelectorRequirement ` but for annotations)
153
+ - Explicitly order "default" (e.g. Resources that don't match any of the selectors) instead of
154
+ them being last.
110
155
111
156
112
157
## Docs
@@ -117,13 +162,14 @@ Update Kubectl Book and Kustomize Documentation
117
162
118
163
Unit Tests for:
119
164
120
- - [ ] Resources with labels and annotations follow the ordering override semantics
165
+ - [ ] Resources with annotations follow the ordering override semantics
121
166
- [ ] Resources matching multiple orderings land in the right spot
167
+ - [ ] Throw an error if a superset selector appears after its subset (e.g. a more restrict selector appears later)
168
+ - This will have no effect, as everything will have already been matched
122
169
- [ ] 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
170
+ - [ ] Having multiple annotations with the same key and different values works correctly
171
+ - [ ] Having multiple annotations with different keys and the same values works correctly
172
+ - [ ] Empty and Null ` MatchAnnotations ` throw an error
127
173
- [ ] Resources that don't appear in the ordering overrides appear last and are sorted by type
128
174
129
175
### Version Skew Tests
0 commit comments