Skip to content

Commit 4884796

Browse files
authored
docs: update cro docs (#1025)
1 parent 62f2fa2 commit 4884796

File tree

4 files changed

+133
-6
lines changed

4 files changed

+133
-6
lines changed

docs/concepts/Override/README.md

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ and `ResourceOverride`.
3636
- At most 100 `ClusterResourceOverride` can be created.
3737
- At most 100 `ResourceOverride` can be created.
3838

39+
## Placement
40+
41+
This specifies which placement the override should be applied to.
42+
3943
## Resource Selector
4044
`ClusterResourceSelector` of `ClusterResourceOverride` selects which cluster-scoped resources need to be overridden before
4145
applying to the selected clusters.
@@ -64,14 +68,52 @@ Each override rule contains the following fields:
6468
- Select clusters by specifying the cluster labels.
6569
- An empty selector selects ALL the clusters.
6670
- A nil selector selects NO target cluster.
67-
- `JSONPatchOverrides`: a list of JSON path override rules applied to the selected resources following [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902).
71+
- `OverrideType`: which type of the override should be applied to the selected resources. The default type is `JSONPatch`.
72+
- `JSONPatch`: applies the JSON patch to the selected resources using [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902).
73+
- `Delete`: deletes the selected resources on the target cluster.
74+
- `JSONPatchOverrides`: a list of JSON path override rules applied to the selected resources following [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902) when the override type is `JSONPatch`.
6875

6976
> **Note:** Updating the fields in the TypeMeta (e.g., `apiVersion`, `kind`) is not allowed.
7077
7178
> **Note:** Updating the fields in the ObjectMeta (e.g., `name`, `namespace`) excluding annotations and labels is not allowed.
7279
7380
> **Note:** Updating the fields in the Status (e.g., `status`) is not allowed.
7481
82+
### Reserved Variables in the JSON Patch Override Value
83+
84+
There is a list of reserved variables that will be replaced by the actual values used in the `value` of the JSON patch override rule:
85+
* `${MEMBER-CLUSTER-NAME}`: this will be replaced by the name of the `memberCluster` that represents this cluster.
86+
87+
For example, to add a label to the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`,
88+
you can use the following configuration:
89+
```yaml
90+
apiVersion: placement.kubernetes-fleet.io/v1alpha1
91+
kind: ClusterResourceOverride
92+
metadata:
93+
name: example-cro
94+
spec:
95+
placement:
96+
name: crp-example
97+
clusterResourceSelectors:
98+
- group: rbac.authorization.k8s.io
99+
kind: ClusterRole
100+
version: v1
101+
name: secret-reader
102+
policy:
103+
overrideRules:
104+
- clusterSelector:
105+
clusterSelectorTerms:
106+
- labelSelector:
107+
matchLabels:
108+
env: prod
109+
jsonPatchOverrides:
110+
- op: add
111+
path: /metadata/labels
112+
value:
113+
{"cluster-name":"${MEMBER-CLUSTER-NAME}"}
114+
```
115+
The `ClusterResourceOverride` object above will add a label `cluster-name` with the value of the `memberCluster` name to the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`.
116+
75117
## When To Trigger Rollout
76118

77119
It will take the snapshot of each override change as a result of `ClusterResourceOverrideSnapshot` and
@@ -112,6 +154,8 @@ metadata:
112154
resourceVersion: "1436"
113155
uid: 32237804-7eb2-4d5f-9996-ff4d8ce778e7
114156
spec:
157+
placement:
158+
name: crp-example
115159
clusterResourceSelectors:
116160
- group: ""
117161
kind: Namespace
@@ -170,6 +214,8 @@ metadata:
170214
resourceVersion: "3859"
171215
uid: b4117925-bc3c-438d-a4f6-067bc4577364
172216
spec:
217+
placement:
218+
name: crp-example
173219
policy:
174220
overrideRules:
175221
- clusterSelector:

docs/howtos/cluster-resource-override.md

Lines changed: 82 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,17 @@ parameters, ensuring consistent management and enforcement of configurations acr
1111

1212
## API Components
1313
The ClusterResourceOverride API consists of the following components:
14+
- **Placement**: This specifies which placement the override is applied to.
1415
- **Cluster Resource Selectors**: These specify the set of cluster resources selected for overriding.
1516
- **Policy**: This specifies the policy to be applied to the selected resources.
1617

1718

1819
The following sections discuss these components in depth.
1920

21+
## Placement
22+
23+
To configure which placement the override is applied to, you can use the name of `ClusterResourcePlacement`.
24+
2025
## Cluster Resource Selectors
2126
A `ClusterResourceOverride` object may feature one or more cluster resource selectors, specifying which resources to select to be overridden.
2227

@@ -61,7 +66,10 @@ resources on selected clusters.
6166

6267
Each `OverrideRule` supports the following fields:
6368
- **Cluster Selector**: This specifies the set of clusters to which the override applies.
64-
- **JSON Patch Override**: This specifies the changes to be applied to the selected resources.
69+
- **Override Type**: This specifies the type of override to be applied. The default type is `JSONPatch`.
70+
- `JSONPatch`: applies the JSON patch to the selected resources using [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902).
71+
- `Delete`: deletes the selected resources on the target cluster.
72+
- **JSON Patch Override**: This specifies the changes to be applied to the selected resources when the override type is `JSONPatch`.
6573

6674
To add an override rule, edit the `policy` field in the `ClusterResourceOverride` spec:
6775
```yaml
@@ -70,6 +78,8 @@ kind: ClusterResourceOverride
7078
metadata:
7179
name: example-cro
7280
spec:
81+
placement:
82+
name: crp-example
7383
clusterResourceSelectors:
7484
- group: rbac.authorization.k8s.io
7585
kind: ClusterRole
@@ -87,7 +97,7 @@ spec:
8797
path: /rules/0/verbs/2
8898
```
8999
The `ClusterResourceOverride` object above will remove the verb "list" in the `ClusterRole` named `secret-reader` on
90-
clusters with the label `env: prod`.
100+
clusters with the label `env: prod` selected by the clusterResourcePlacement `crp-example`.
91101

92102
> The ClusterResourceOverride mentioned above utilizes the cluster role displayed below:
93103
> ```
@@ -100,12 +110,42 @@ clusters with the label `env: prod`.
100110
> secrets [] [] [get watch list]
101111
>```
102112

113+
To delete the `secret-reader` on the clusters with the label `env: test` selected by the clusterResourcePlacement `crp-example`, you can use the `Delete` override type.
114+
```yaml
115+
apiVersion: placement.kubernetes-fleet.io/v1alpha1
116+
kind: ClusterResourceOverride
117+
metadata:
118+
name: example-cro
119+
spec:
120+
placement:
121+
name: crp-example
122+
clusterResourceSelectors:
123+
- group: rbac.authorization.k8s.io
124+
kind: ClusterRole
125+
version: v1
126+
name: secret-reader
127+
policy:
128+
overrideRules:
129+
- clusterSelector:
130+
clusterSelectorTerms:
131+
- labelSelector:
132+
matchLabels:
133+
env: test
134+
overrideType: Delete
135+
```
136+
103137
### Cluster Selector
104138
To specify the clusters to which the override applies, you can use the `clusterSelector` field in the `OverrideRule` spec.
105139
The `clusterSelector` field supports the following fields:
106140
- `clusterSelectorTerms`: A list of terms that are used to select clusters.
107141
* Each term in the list is used to select clusters based on the label selector.
108142

143+
### Override Type
144+
To specify the type of override to be applied, you can use the overrideType field in the OverrideRule spec.
145+
The default value is `JSONPatch`.
146+
- `JSONPatch`: applies the JSON patch to the selected resources using [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902).
147+
- `Delete`: deletes the selected resources on the target cluster.
148+
109149
### JSON Patch Override
110150
To specify the changes to be applied to the selected resources, you can use the jsonPatchOverrides field in the OverrideRule spec.
111151
The jsonPatchOverrides field supports the following fields:
@@ -136,7 +176,38 @@ The jsonPatchOverrides field supports the following fields:
136176

137177
- `value`: The value to be set.
138178
* If the `op` is `remove`, the value cannot be set.
179+
* There is a list of reserved variables that will be replaced by the actual values:
180+
* `${MEMBER-CLUSTER-NAME}`: this will be replaced by the name of the `memberCluster` that represents this cluster.
139181

182+
For example, to add a label to the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`,
183+
you can use the following configuration:
184+
```yaml
185+
apiVersion: placement.kubernetes-fleet.io/v1alpha1
186+
kind: ClusterResourceOverride
187+
metadata:
188+
name: example-cro
189+
spec:
190+
placement:
191+
name: crp-example
192+
clusterResourceSelectors:
193+
- group: rbac.authorization.k8s.io
194+
kind: ClusterRole
195+
version: v1
196+
name: secret-reader
197+
policy:
198+
overrideRules:
199+
- clusterSelector:
200+
clusterSelectorTerms:
201+
- labelSelector:
202+
matchLabels:
203+
env: prod
204+
jsonPatchOverrides:
205+
- op: add
206+
path: /metadata/labels
207+
value:
208+
{"cluster-name":"${MEMBER-CLUSTER-NAME}"}
209+
```
210+
The `ClusterResourceOverride` object above will add a label `cluster-name` with the value of the `memberCluster` name to the `ClusterRole` named `secret-reader` on clusters with the label `env: prod`.
140211

141212
### Multiple Override Patches
142213
You may add multiple `JSONPatchOverride` to an `OverrideRule` to apply multiple changes to the selected cluster resources.
@@ -146,6 +217,8 @@ kind: ClusterResourceOverride
146217
metadata:
147218
name: example-cro
148219
spec:
220+
placement:
221+
name: crp-example
149222
clusterResourceSelectors:
150223
- group: rbac.authorization.k8s.io
151224
kind: ClusterRole
@@ -210,6 +283,9 @@ spec:
210283
- labelSelector:
211284
matchLabels:
212285
env: prod
286+
- labelSelector:
287+
matchLabels:
288+
env: test
213289
```
214290
The `ClusterResourcePlacement` configuration outlined above will disperse resources across all clusters labeled with `env: prod`.
215291
As the changes are implemented, the corresponding `ClusterResourceOverride` configurations will be applied to the
@@ -245,7 +321,7 @@ Status:
245321
...
246322
```
247323
Each cluster maintains its own `Applicable Cluster Resource Overrides` which contain the cluster resource override snapshot
248-
if relevant. Additionally, individual status messages for each cluster indicates whether the override rules have been
324+
if relevant. Additionally, individual status messages for each cluster indicate whether the override rules have been
249325
effectively applied.
250326

251327
The `ClusterResourcePlacementOverridden` condition indicates whether the resource override has been successfully applied
@@ -260,7 +336,7 @@ check resources in the selected clusters:
260336
`kubectl --context=<member-cluster-context> get clusterrole secret-reader -o yaml`
261337

262338
Upon inspecting the described ClusterRole object, it becomes apparent that the verbs "watch" and "list" have been
263-
removed from the permissions list within the ClusterRole named "secret-reader" on the selected cluster.
339+
removed from the permissions list within the ClusterRole named "secret-reader" on the prod clusters.
264340
```
265341
apiVersion: rbac.authorization.k8s.io/v1
266342
kind: ClusterRole
@@ -273,4 +349,5 @@ removed from the permissions list within the ClusterRole named "secret-reader" o
273349
- secrets
274350
verbs:
275351
- get
276-
```
352+
```
353+
Similarly, you can verify that this cluster role does not exist in the test clusters.

examples/test-cro1.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ kind: ClusterResourceOverride
33
metadata:
44
name: cro-1
55
spec:
6+
placement:
7+
name: crp-example
68
clusterResourceSelectors:
79
- group: apiextensions.k8s.io
810
kind: CustomResourceDefinition

examples/test-ro1.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ metadata:
44
name: ro-1
55
namespace: test-namespace
66
spec:
7+
placement:
8+
name: crp-example
79
resourceSelectors:
810
- group: ""
911
kind: ConfigMap

0 commit comments

Comments
 (0)