Skip to content

Commit d89a56c

Browse files
add examples
Signed-off-by: Steven Borrelli <[email protected]>
1 parent bcd58de commit d89a56c

File tree

6 files changed

+166
-0
lines changed

6 files changed

+166
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Conditional Rendering of Individual Resources
2+
3+
In this example, we show how each resource in a pipeline step can
4+
be individually rendered based on a condition. We will have a blue and a
5+
green deployment that the user can activate:
6+
7+
```yaml
8+
apiVersion: nop.example.org/v1alpha1
9+
kind: XNopConditional
10+
metadata:
11+
name: test-resource
12+
spec:
13+
env: dev
14+
render: true
15+
deployment:
16+
blue: true
17+
green: false
18+
```
19+
20+
In our Composition both the `blue-resource` and the `green-resource` have a
21+
`condition` that determines if they will be run.
22+
23+
```yaml
24+
resources:
25+
- name: blue-resource
26+
condition: observed.composite.resource.spec.deployment.blue == true
27+
base:
28+
apiVersion: nop.crossplane.io/v1alpha1
29+
kind: NopResource
30+
spec:
31+
forProvider:
32+
```
33+
34+
## Running this example
35+
36+
- Install Crossplane version 1.14 or newer. See <https://docs.crossplane.io/v1.14/software/install/>
37+
- Install the nop provider in `kubectl apply -f provider.yaml`
38+
- Install the XRD & Composition in `kubectl apply -f definition.yaml -f composition.yaml`
39+
- Install the Function `kubectl apply -f functions.yaml`
40+
41+
Finally install the xr: `kubectl apply -f xr`
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
---
2+
apiVersion: apiextensions.crossplane.io/v1
3+
kind: Composition
4+
metadata:
5+
name: xnopconditionals.nop.example.org
6+
spec:
7+
compositeTypeRef:
8+
apiVersion: nop.example.org/v1alpha1
9+
kind: XNopConditional
10+
mode: Pipeline
11+
pipeline:
12+
- step: conditional-patch-and-transform
13+
functionRef:
14+
name: function-conditional-patch-and-transform
15+
input:
16+
apiVersion: conditional-pt.fn.crossplane.io/v1beta1
17+
kind: Resources
18+
resources:
19+
- name: blue-resource
20+
condition: observed.composite.resource.spec.deployment.blue == true
21+
base:
22+
apiVersion: nop.crossplane.io/v1alpha1
23+
kind: NopResource
24+
spec:
25+
forProvider:
26+
fields:
27+
integerField: 42
28+
stringField: "blue"
29+
objectField:
30+
stringField: "blueObject"
31+
arrayField:
32+
- stringField: "blueArray"
33+
conditionAfter:
34+
- time: 5s
35+
conditionType: Ready
36+
conditionStatus: "True"
37+
connectionDetails:
38+
- name: username
39+
value: fakeuser
40+
- name: password
41+
value: verysecurepassword
42+
- name: endpoint
43+
value: 127.0.0.1
44+
- name: green-resource
45+
condition: observed.composite.resource.spec.deployment.green == true
46+
base:
47+
apiVersion: nop.crossplane.io/v1alpha1
48+
kind: NopResource
49+
spec:
50+
forProvider:
51+
fields:
52+
integerField: 42
53+
stringField: "green"
54+
objectField:
55+
stringField: "greenObject"
56+
arrayField:
57+
- stringField: "greenArray"
58+
conditionAfter:
59+
- time: 5s
60+
conditionType: Ready
61+
conditionStatus: "True"
62+
connectionDetails:
63+
- name: username
64+
value: fakeuser
65+
- name: password
66+
value: verysecurepassword
67+
- name: endpoint
68+
value: 127.0.0.1
69+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: CompositeResourceDefinition
3+
metadata:
4+
name: xnopconditionals.nop.example.org
5+
spec:
6+
group: nop.example.org
7+
names:
8+
kind: XNopConditional
9+
plural: xnopconditionals
10+
versions:
11+
- name: v1alpha1
12+
referenceable: true
13+
served: true
14+
schema:
15+
openAPIV3Schema:
16+
type: object
17+
properties:
18+
spec:
19+
type: object
20+
properties:
21+
env:
22+
type: string
23+
render:
24+
type: boolean
25+
deployment:
26+
type: object
27+
properties:
28+
blue:
29+
description: Activate the blue resource
30+
type: boolean
31+
green:
32+
description: Activate the green resource
33+
type: boolean
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: pkg.crossplane.io/v1beta1
2+
kind: Function
3+
metadata:
4+
name: function-conditional-patch-and-transform
5+
spec:
6+
package: xpkg.upbound.io/borrelli-org/function-conditional-patch-and-transform:v0.3.0
7+
packagePullPolicy: Always
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
apiVersion: pkg.crossplane.io/v1
2+
kind: Provider
3+
metadata:
4+
name: provider-nop
5+
spec:
6+
package: xpkg.upbound.io/crossplane-contrib/provider-nop:v0.2.0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: nop.example.org/v1alpha1
2+
kind: XNopConditional
3+
metadata:
4+
name: test-resource
5+
spec:
6+
env: dev
7+
render: true
8+
deployment:
9+
blue: true
10+
green: false

0 commit comments

Comments
 (0)