Skip to content

Commit 0f788af

Browse files
committed
update with pr comments
1 parent 1df8b3e commit 0f788af

File tree

1 file changed

+84
-33
lines changed

1 file changed

+84
-33
lines changed

keps/sig-cli/kustomize-ordering.md

+84-33
Original file line numberDiff line numberDiff line change
@@ -54,59 +54,109 @@ sorting by Resource Type is insufficient.
5454

5555
### Goals
5656

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
5860

5961
### Non-Goals
6062

61-
## Proposal
63+
- Ensure certain Resources are *Settled* or *Ready* before other Resources
64+
- Ensure dependencies between Workloads
6265

63-
Add a new field `resourceOrdering` that is a list of `key, value, type` tuples to define the ordering.
66+
## Proposal
6467

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+
// annotationSelector matches Resources based on their Annotations.
89+
AnnotationSelector AnnotationSelector `json:"annotationSelector"`
90+
}
91+
92+
// A annotation selector is a annotation query over a set of resources. The results of matchAnnotations is ANDed.
93+
// An empty annotation selector matches all objects. A null annotation selector matches no objects.
94+
type AnnotationSelector struct {
95+
// matchAnnotations is a map of {key,value} pairs. A Resource matches if it has
96+
// *all* of the annotations in matchAnnotations appear in the Resource metaData.
97+
// Null and empty values are not allowed.
98+
// +optional
99+
MatchAnnotations map[string]string `json:"matchAnnotations,omitempty"`
100+
101+
// TODO: Consider adding field: MatchExpressions []AnnotationSelectorRequirement
102+
}
103+
```
65104
Example:
66105

67106
```
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
107+
sortOrder:
108+
- annotationSelector:
109+
some-annotation-name-1: some-annotation-value-1
110+
some-annotation-name-a: some-label-value-a
111+
- annotationSelector:
112+
some-annotation-name-1: some-annotation-value-1
113+
- annotationSelector:
114+
some-annotation-name-2: some-annotation-value-2
84115
```
85116

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.
117+
The explicit user defined ordering using annotations will take precedence over the type based
118+
orderings. Types would be used as a fallback sorting function amongst Resource with equal
119+
precedence in the explicit ordering.
88120

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
121+
- Resources annotated with `some-annotation-name-1: some-annotation-value-1` *and* annotated
122+
with `some-annotation-name-a: some-annotation-value-a` are first
91123
- These Resources are sorted by type
92-
- Resources annotated with `some-annotation-name-a=some-annotation-value-b` are second
124+
- Resources annotated with `some-annotation-name-1=some-annotation-value-1`
125+
(without `some-annotation-name-a: some-annotation-value-a`) appear second
93126
- These Resources are sorted by type
94-
- Resources labeled with `some-label-name-2=some-label-value-2` are third
127+
- Resources annotated with `some-annotation-name-2=some-annotation-value-2`
95128
- These Resources are sorted by type
96-
- Resources not matching any label or annotation are last
129+
- Resources not matching any annotation are last
97130
- These Resources are sorted by type
98131

99-
Resources matching multiple orderings (e.g. have multiple matching labels and annotations) appear
132+
Resources matching multiple orderings (e.g. have multiple matching annotations) appear
100133
in the position matching the earliest label / annotation.
101134

135+
**Note:** Throw an error if there is a selector that selects a superset of another selector
136+
and it appears first. e.g. this should throw an error because the first selector will match
137+
everything that the second selector does, and it will have no effect.
138+
139+
```
140+
sortOrder:
141+
- annotationSelector:
142+
some-annotation-name-1: some-annotation-value-1
143+
- annotationSelector:
144+
some-annotation-name-1: some-annotation-value-1
145+
some-annotation-name-a: some-label-value-a
146+
```
147+
102148
### Risks and Mitigations
103149

104150
Risk: Users build complex orderings that are hard to reason about.
105151
Mitigation: Good documentation and recommendations about how to keep things simple.
106152

107153
## Graduation Criteria
108154

109-
NA
155+
Use customer feedback to determine if we should support:
156+
157+
- `LabelSelectors`
158+
- `AnnotationSelectorRequirement` (like `LabelSelectorRequirement` but for annotations)
159+
- Explicitly ordering things
110160

111161

112162
## Docs
@@ -117,13 +167,14 @@ Update Kubectl Book and Kustomize Documentation
117167

118168
Unit Tests for:
119169

120-
- [ ] Resources with labels and annotations follow the ordering override semantics
170+
- [ ] Resources with annotations follow the ordering override semantics
121171
- [ ] Resources matching multiple orderings land in the right spot
172+
- [ ] Throw an error if a superset selector appears after its subset (e.g. a more restrict selector appears later)
173+
- This will have no effect, as everything will have already been matched
122174
- [ ] 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
175+
- [ ] Having multiple annotations with the same key and different values works correctly
176+
- [ ] Having multiple annotations with different keys and the same values works correctly
177+
- [ ] Empty and Null `MatchAnnotations` throw an error
127178
- [ ] Resources that don't appear in the ordering overrides appear last and are sorted by type
128179

129180
### Version Skew Tests

0 commit comments

Comments
 (0)