@@ -4,11 +4,10 @@ weight: 30
4
4
state : beta
5
5
alphaVersion : " 1.14"
6
6
betaVersion : " 1.19"
7
- description : " Usage defines a usage relationship for Managed Resources or Composites "
7
+ description : " Usage indicates a resource is in use "
8
8
---
9
9
10
- A ` Usage ` is a Crossplane resource that defines a usage relationship for a
11
- Managed Resource or a Composite Resource. Two main use cases for the Usages are
10
+ A ` Usage ` indicates a resource is in use. Two main use cases for Usages are
12
11
as follows:
13
12
14
13
1 . Protecting a resource from accidental deletion.
@@ -68,18 +67,6 @@ defines the using resource. Both fields are optional, but at least one of them
68
67
must be provided.
69
68
<!-- vale write-good.Passive = YES -->
70
69
71
- {{<hint "important" >}}
72
- <!-- vale write-good.Passive = NO -->
73
- Usage relationships can be defined between ` Managed Resources` and `Composites`.
74
- <!-- vale write-good.TooWordy = NO -->
75
- However, a `Composite` as the using resource (`spec.by`) would be ineffective
76
- unless the `compositeDeletePolicy` `Foreground` is used because it wouldn't block
77
- deletion of its child resources before its own deletion with the default deletion
78
- policy `Background`.
79
- <!-- vale write-good.TooWordy = YES -->
80
- <!-- vale write-good.Passive = YES -->
81
- {{< /hint >}}
82
-
83
70
### Usage for deletion protection
84
71
85
72
The following example prevents the deletion of the
@@ -88,13 +75,14 @@ any deletion request with the
88
75
{{<hover label="protect" line="11">}}reason{{</hover>}} defined.
89
76
90
77
` ` ` yaml {label="protect"}
91
- apiVersion: apiextensions .crossplane.io/v1beta1
78
+ apiVersion : protection .crossplane.io/v1beta1
92
79
kind : Usage
93
80
metadata :
81
+ namespace : default
94
82
name : protect-production-database
95
83
spec :
96
84
of :
97
- apiVersion: rds.aws.upbound.io/v1beta1
85
+ apiVersion : rds.m. aws.upbound.io/v1beta1
98
86
kind : Instance
99
87
resourceRef :
100
88
name : my-database
@@ -109,18 +97,19 @@ any deletion request before the deletion of
109
97
{{<hover label="order" line="15">}}my-prometheus-chart{{</hover>}} resource.
110
98
111
99
` ` ` yaml {label="order"}
112
- apiVersion: apiextensions .crossplane.io/v1beta1
100
+ apiVersion : protection .crossplane.io/v1beta1
113
101
kind : Usage
114
102
metadata :
103
+ namespace : default
115
104
name : release-uses-cluster
116
105
spec :
117
106
of :
118
- apiVersion: eks.upbound.io/v1beta1
107
+ apiVersion : eks.m. upbound.io/v1beta1
119
108
kind : Cluster
120
109
resourceRef :
121
110
name : my-cluster
122
111
by :
123
- apiVersion: helm.crossplane.io/v1beta1
112
+ apiVersion : helm.m. crossplane.io/v1beta1
124
113
kind : Release
125
114
resourceRef :
126
115
name : my-prometheus-chart
@@ -135,20 +124,21 @@ This enables using {{<hover label="selectors" line="12">}}labels{{</hover>}} or
135
124
to define resource instead of providing the resource name.
136
125
137
126
` ` ` yaml {label="selectors"}
138
- apiVersion: apiextensions .crossplane.io/v1beta1
127
+ apiVersion : protection .crossplane.io/v1beta1
139
128
kind : Usage
140
129
metadata :
130
+ namespace : default
141
131
name : release-uses-cluster
142
132
spec :
143
133
of :
144
- apiVersion: eks.upbound.io/v1beta1
134
+ apiVersion : eks.m. upbound.io/v1beta1
145
135
kind : Cluster
146
136
resourceSelector :
147
137
matchControllerRef : false # default, and could be omitted
148
138
matchLabels :
149
139
foo : bar
150
140
by :
151
- apiVersion: helm.crossplane.io/v1beta1
141
+ apiVersion : helm.m. crossplane.io/v1beta1
152
142
kind : Release
153
143
resourceSelector :
154
144
matchLabels :
@@ -169,21 +159,22 @@ random resource is selected from the list of matched resources.
169
159
{{< /hint >}}
170
160
171
161
` ` ` yaml {label="selectors-resolved"}
172
- apiVersion: apiextensions .crossplane.io/v1beta1
162
+ apiVersion: protection .crossplane.io/v1beta1
173
163
kind: Usage
174
164
metadata:
165
+ namespace: default
175
166
name: release-uses-cluster
176
167
spec:
177
168
of:
178
- apiVersion: eks.upbound.io/v1beta1
169
+ apiVersion: eks.m. upbound.io/v1beta1
179
170
kind: Cluster
180
171
resourceRef:
181
172
name: my-cluster
182
173
resourceSelector:
183
174
matchLabels:
184
175
foo: bar
185
176
by:
186
- apiVersion: helm.crossplane.io/v1beta1
177
+ apiVersion: helm.m. crossplane.io/v1beta1
187
178
kind: Release
188
179
resourceRef:
189
180
name: my-cluster
@@ -200,19 +191,20 @@ Replaying the blocked deletion is possible by setting the
200
191
{{<hover label="replay" line="6">}}replayDeletion{{</hover>}} field to `true`.
201
192
202
193
` ` ` yaml {label="replay"}
203
- apiVersion: apiextensions .crossplane.io/v1beta1
194
+ apiVersion: protection .crossplane.io/v1beta1
204
195
kind: Usage
205
196
metadata:
197
+ namespace: default
206
198
name: release-uses-cluster
207
199
spec:
208
200
replayDeletion: true
209
201
of:
210
- apiVersion: eks.upbound.io/v1beta1
202
+ apiVersion: eks.m. upbound.io/v1beta1
211
203
kind: Cluster
212
204
resourceRef:
213
205
name: my-cluster
214
206
by:
215
- apiVersion: helm.crossplane.io/v1beta1
207
+ apiVersion: helm.m. crossplane.io/v1beta1
216
208
kind: Release
217
209
resourceRef:
218
210
name: my-prometheus-chart
@@ -235,51 +227,6 @@ resources in a Composition. The Usages support
235
227
in selectors to ensures that the matching resource is in the same composite
236
228
resource in the same way as [cross-resource referencing]({{<ref "./managed-resources#referencing-other-resources" >}}).
237
229
238
- The following example shows a Composition that defines a deletion ordering
239
- between a `Cluster` and a `Release` resource. The `Usage` blocks deletion of
240
- the `Cluster` resource until the `Release` resource is successfully deleted.
241
-
242
- ` ` ` yaml {label="composition"}
243
- apiVersion: apiextensions.crossplane.io/v1
244
- kind: Composition
245
- spec:
246
- mode: Pipeline
247
- pipeline:
248
- - step: patch-and-transform
249
- functionRef:
250
- name: function-patch-and-transform
251
- input:
252
- apiVersion: pt.fn.crossplane.io/v1beta1
253
- kind: Resources
254
- resources:
255
- - name: cluster
256
- base:
257
- apiVersion: container.gcp.upbound.io/v1beta1
258
- kind: Cluster
259
- # Removed for brevity
260
- - name: release
261
- base:
262
- apiVersion: helm.crossplane.io/v1beta1
263
- kind: Release
264
- # Removed for brevity
265
- - name: release-uses-cluster
266
- base:
267
- apiVersion: apiextensions.crossplane.io/v1beta1
268
- kind: Usage
269
- spec:
270
- replayDeletion: true
271
- of:
272
- apiVersion: container.gcp.upbound.io/v1beta1
273
- kind: Cluster
274
- resourceSelector:
275
- matchControllerRef: true
276
- by:
277
- apiVersion: helm.crossplane.io/v1beta1
278
- kind: Release
279
- resourceSelector:
280
- matchControllerRef: true
281
- ` ` `
282
-
283
230
{{<hint "tip" >}}
284
231
285
232
<!-- vale write-good.Passive = NO -->
@@ -288,8 +235,55 @@ When there are multiple resources of same type in a Composition, the
288
235
uniquely identify the resource in use or the using one. This could be
289
236
accomplished by using extra labels and combining
290
237
{{<hover label="composition" line="24">}}matchControllerRef{{</hover>}}
291
- with a `matchLabels` selector. Another alternative is patching `resourceRef.name`
292
- directly with the help of `ToCompositeFieldPath` and `FromCompositeFieldPath`
293
- or `ToEnvironmentFieldPath` and `FromEnvironmentFieldPath` type patches.
238
+ with a `matchLabels` selector.
294
239
<!-- vale write-good.Passive = YES -->
295
- {{< /hint >}}
240
+ {{< /hint >}}
241
+
242
+ # # Usage across namespaces
243
+
244
+ A `Usage` with `of` and `by` represents a usage relationship between two
245
+ resources in the same namespace as the `Usage` by default.
246
+
247
+ A `Usage` can represent a usage relationship between a `by` resource in the same
248
+ namespace as the `Usage` and an `of` resource in a different namespace.
249
+
250
+ To use a resource in a different namespace, specify the `namespace` in the `of`
251
+ ` resourceRef` or `resourceSelector`.
252
+
253
+ ` ` ` yaml {label="order"}
254
+ apiVersion: protection.crossplane.io/v1beta1
255
+ kind: Usage
256
+ metadata:
257
+ namespace: default
258
+ name: release-uses-cluster
259
+ spec:
260
+ of:
261
+ apiVersion: eks.m.upbound.io/v1beta1
262
+ kind: Cluster
263
+ resourceRef:
264
+ namespace: cluster-infra
265
+ name: my-cluster
266
+ by:
267
+ apiVersion: helm.m.crossplane.io/v1beta1
268
+ kind: Release
269
+ resourceRef:
270
+ name: my-prometheus-chart
271
+ ` ` `
272
+
273
+ # # ClusterUsages
274
+
275
+ Use a `ClusterUsage` to protect cluster scoped resources.
276
+
277
+ ` ` ` yaml {label="protect"}
278
+ apiVersion: protection.crossplane.io/v1beta1
279
+ kind: ClusterUsage
280
+ metadata:
281
+ name: protect-important-crd
282
+ spec:
283
+ of:
284
+ apiVersion: apiextensions.k8s.io/v1
285
+ kind: CustomResourceDefinition
286
+ resourceRef:
287
+ name: importantresources.example.crossplane.io
288
+ reason: "Very important CRD - should never be deleted!"
289
+ ` ` `
0 commit comments