Skip to content

Commit 53ec758

Browse files
committed
update with pr comments
1 parent 1df8b3e commit 53ec758

File tree

1 file changed

+78
-32
lines changed

1 file changed

+78
-32
lines changed

keps/sig-cli/kustomize-ordering.md

+78-32
Original file line numberDiff line numberDiff line change
@@ -54,59 +54,104 @@ 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

63+
- Ensure certain Resources are *Settled* or *Ready* before other Resources
64+
- Ensure dependencies between Workloads
65+
6166
## Proposal
6267

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+
}
6496

97+
```
6598
Example:
6699

67100
```
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
84109
```
85110

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.
88114

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
91117
- 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
93120
- 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
95122
- These Resources are sorted by type
96-
- Resources not matching any label or annotation are last
123+
- Resources not matching any annotation are last
97124
- These Resources are sorted by type
98125

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
100127
in the position matching the earliest label / annotation.
101128

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+
102142
### Risks and Mitigations
103143

104144
Risk: Users build complex orderings that are hard to reason about.
105145
Mitigation: Good documentation and recommendations about how to keep things simple.
106146

107147
## Graduation Criteria
108148

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.
110155

111156

112157
## Docs
@@ -117,13 +162,14 @@ Update Kubectl Book and Kustomize Documentation
117162

118163
Unit Tests for:
119164

120-
- [ ] Resources with labels and annotations follow the ordering override semantics
165+
- [ ] Resources with annotations follow the ordering override semantics
121166
- [ ] 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
122169
- [ ] 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
127173
- [ ] Resources that don't appear in the ordering overrides appear last and are sorted by type
128174

129175
### Version Skew Tests

0 commit comments

Comments
 (0)