Skip to content

Commit 89dbb44

Browse files
committed
Document Usages for v2
Signed-off-by: Nic Cope <[email protected]>
1 parent dc39ca3 commit 89dbb44

File tree

1 file changed

+72
-78
lines changed
  • content/v2.0-preview/managed-resources

1 file changed

+72
-78
lines changed

content/v2.0-preview/managed-resources/usages.md

Lines changed: 72 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ weight: 30
44
state: beta
55
alphaVersion: "1.14"
66
betaVersion: "1.19"
7-
description: "Usage defines a usage relationship for Managed Resources or Composites"
7+
description: "Usage indicates a resource is in use"
88
---
99

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
1211
as follows:
1312

1413
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
6867
must be provided.
6968
<!-- vale write-good.Passive = YES -->
7069
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-
8370
### Usage for deletion protection
8471
8572
The following example prevents the deletion of the
@@ -88,13 +75,14 @@ any deletion request with the
8875
{{<hover label="protect" line="11">}}reason{{</hover>}} defined.
8976
9077
```yaml {label="protect"}
91-
apiVersion: apiextensions.crossplane.io/v1beta1
78+
apiVersion: protection.crossplane.io/v1beta1
9279
kind: Usage
9380
metadata:
81+
namespace: default
9482
name: protect-production-database
9583
spec:
9684
of:
97-
apiVersion: rds.aws.upbound.io/v1beta1
85+
apiVersion: rds.m.aws.upbound.io/v1beta1
9886
kind: Instance
9987
resourceRef:
10088
name: my-database
@@ -109,18 +97,19 @@ any deletion request before the deletion of
10997
{{<hover label="order" line="15">}}my-prometheus-chart{{</hover>}} resource.
11098
11199
```yaml {label="order"}
112-
apiVersion: apiextensions.crossplane.io/v1beta1
100+
apiVersion: protection.crossplane.io/v1beta1
113101
kind: Usage
114102
metadata:
103+
namespace: default
115104
name: release-uses-cluster
116105
spec:
117106
of:
118-
apiVersion: eks.upbound.io/v1beta1
107+
apiVersion: eks.m.upbound.io/v1beta1
119108
kind: Cluster
120109
resourceRef:
121110
name: my-cluster
122111
by:
123-
apiVersion: helm.crossplane.io/v1beta1
112+
apiVersion: helm.m.crossplane.io/v1beta1
124113
kind: Release
125114
resourceRef:
126115
name: my-prometheus-chart
@@ -135,20 +124,21 @@ This enables using {{<hover label="selectors" line="12">}}labels{{</hover>}} or
135124
to define resource instead of providing the resource name.
136125
137126
```yaml {label="selectors"}
138-
apiVersion: apiextensions.crossplane.io/v1beta1
127+
apiVersion: protection.crossplane.io/v1beta1
139128
kind: Usage
140129
metadata:
130+
namespace: default
141131
name: release-uses-cluster
142132
spec:
143133
of:
144-
apiVersion: eks.upbound.io/v1beta1
134+
apiVersion: eks.m.upbound.io/v1beta1
145135
kind: Cluster
146136
resourceSelector:
147137
matchControllerRef: false # default, and could be omitted
148138
matchLabels:
149139
foo: bar
150140
by:
151-
apiVersion: helm.crossplane.io/v1beta1
141+
apiVersion: helm.m.crossplane.io/v1beta1
152142
kind: Release
153143
resourceSelector:
154144
matchLabels:
@@ -169,21 +159,22 @@ random resource is selected from the list of matched resources.
169159
{{< /hint >}}
170160

171161
```yaml {label="selectors-resolved"}
172-
apiVersion: apiextensions.crossplane.io/v1beta1
162+
apiVersion: protection.crossplane.io/v1beta1
173163
kind: Usage
174164
metadata:
165+
namespace: default
175166
name: release-uses-cluster
176167
spec:
177168
of:
178-
apiVersion: eks.upbound.io/v1beta1
169+
apiVersion: eks.m.upbound.io/v1beta1
179170
kind: Cluster
180171
resourceRef:
181172
name: my-cluster
182173
resourceSelector:
183174
matchLabels:
184175
foo: bar
185176
by:
186-
apiVersion: helm.crossplane.io/v1beta1
177+
apiVersion: helm.m.crossplane.io/v1beta1
187178
kind: Release
188179
resourceRef:
189180
name: my-cluster
@@ -200,19 +191,20 @@ Replaying the blocked deletion is possible by setting the
200191
{{<hover label="replay" line="6">}}replayDeletion{{</hover>}} field to `true`.
201192

202193
```yaml {label="replay"}
203-
apiVersion: apiextensions.crossplane.io/v1beta1
194+
apiVersion: protection.crossplane.io/v1beta1
204195
kind: Usage
205196
metadata:
197+
namespace: default
206198
name: release-uses-cluster
207199
spec:
208200
replayDeletion: true
209201
of:
210-
apiVersion: eks.upbound.io/v1beta1
202+
apiVersion: eks.m.upbound.io/v1beta1
211203
kind: Cluster
212204
resourceRef:
213205
name: my-cluster
214206
by:
215-
apiVersion: helm.crossplane.io/v1beta1
207+
apiVersion: helm.m.crossplane.io/v1beta1
216208
kind: Release
217209
resourceRef:
218210
name: my-prometheus-chart
@@ -235,51 +227,6 @@ resources in a Composition. The Usages support
235227
in selectors to ensures that the matching resource is in the same composite
236228
resource in the same way as [cross-resource referencing]({{<ref "./managed-resources#referencing-other-resources" >}}).
237229

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-
283230
{{<hint "tip" >}}
284231

285232
<!-- vale write-good.Passive = NO -->
@@ -288,8 +235,55 @@ When there are multiple resources of same type in a Composition, the
288235
uniquely identify the resource in use or the using one. This could be
289236
accomplished by using extra labels and combining
290237
{{<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.
294239
<!-- 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

Comments
 (0)