Skip to content

Commit 8f2f705

Browse files
authored
Rearrange examples and update documentation (#8)
* Rearrange examples and update documentation * Sort examples by context dir * Provide render target specific for each use case * Avoid test file duplication, share as much as possible Signed-off-by: Yury Tsarev <[email protected]> * Update syntax highlighting Signed-off-by: Yury Tsarev <[email protected]> --------- Signed-off-by: Yury Tsarev <[email protected]>
1 parent 0ac31b7 commit 8f2f705

File tree

21 files changed

+228
-57
lines changed

21 files changed

+228
-57
lines changed

README.md

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ A function to query [Azure Resource Graph][azresourcegraph]
55

66
## Usage
77

8-
See [examples][examples]
8+
See the [examples][examples] for a variety of practical and testable use cases demonstrating this Function.
99

1010
Example pipeline step:
1111

@@ -47,26 +47,14 @@ status:
4747
location: centralus
4848
name: us-vm-lzbpt-fgcds
4949
type: microsoft.compute/virtualmachines
50-
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vac-dr27h-ttsq5/providers/Microsoft.Compute/virtualMachines/us-vac-dr27h-t7dhd
51-
location: centralus
52-
name: us-vac-dr27h-t7dhd
53-
type: microsoft.compute/virtualmachines
54-
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/my-vm-mm59z/providers/Microsoft.Compute/virtualMachines/my-vm-jm8g2
55-
location: swedencentral
56-
name: my-vm-jm8g2
57-
type: microsoft.compute/virtualmachines
58-
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/javid-labs/providers/Microsoft.Compute/virtualMachines/devstack-test
59-
location: westus2
60-
name: devstack-test
61-
type: microsoft.compute/virtualmachines
6250
```
6351
6452
### QueryRef
6553
6654
Rather than specifying a direct query string as shown in the example above,
6755
the function allows referencing a query from any arbitrary string within the Context or Status.
6856
69-
#### Context
57+
#### Context Query Reference
7058
7159
* Simple context field reference
7260
```yaml
@@ -78,7 +66,7 @@ the function allows referencing a query from any arbitrary string within the Con
7866
queryRef: "context.[apiextensions.crossplane.io/environment].azResourceGraphQuery"
7967
```
8068
81-
#### XR Status
69+
#### XR Status Query Reference
8270
8371
* Simple XR Status field reference
8472
```yaml
@@ -94,7 +82,7 @@ the function allows referencing a query from any arbitrary string within the Con
9482
9583
Function supports publishing Query Results to different locations.
9684
97-
#### Context
85+
#### Context Target
9886
9987
* Simple Context field target
10088
```yaml
@@ -106,7 +94,7 @@ Function supports publishing Query Results to different locations.
10694
target: "context.[apiextensions.crossplane.io/environment].azResourceGraphQuery"
10795
```
10896
109-
#### XR Status
97+
#### XR Status Target
11098
11199
* Simple XR status field target
112100
```yaml

example/README.md

Lines changed: 32 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,33 @@
11
# Example manifests
22

3-
You can run your function locally and test it using `crossplane beta render`
4-
with these example manifests.
3+
This directory contains a collection of practical examples to demonstrate the functionality. Each example is organized into a directory with a self-descriptive name.
54

6-
```shell
7-
# Run the function locally
8-
$ go run . --insecure --debug
9-
```
5+
## Usage
6+
7+
To render a specific example, navigate to its directory and run the `make` command.
8+
9+
Each example provides a unique `composition.yaml` file that highlights a specific function usage scenario.
10+
11+
The Makefile in the examples directory provides a simple `render` target to
12+
streamline rendering Crossplane compositions.
13+
14+
To enable a successful query, update `secrets/azure-creds.yaml` with
15+
your valid Azure credentials.
16+
17+
## Example
18+
19+
For instance, the static-query-to-context-field directory demonstrates how to use a static query to populate a specific context field.
1020

1121
```shell
12-
# Then, in another terminal, call it with these example manifests
13-
$ crossplane render example/xr.yaml example/composition.yaml example/functions-dev.yaml --function-credentials=example/secrets/azure-creds.yaml -r
22+
$ cd queryref-from-environment
23+
$ make
24+
crossplane render ../xr.yaml composition.yaml ./functions.yaml --function-credentials=../secrets/azure-creds.yaml --extra-resources=envconfig.yaml -rc
1425
---
1526
apiVersion: example.crossplane.io/v1
1627
kind: XR
1728
metadata:
1829
name: example-xr
1930
status:
20-
azResourceGraphQueryResult:
21-
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vm-zxqnj-s2jdb/providers/Microsoft.Compute/virtualMachines/us-vm-zxqnj-2h59v
22-
location: centralus
23-
name: us-vm-zxqnj-2h59v
24-
type: microsoft.compute/virtualmachines
25-
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vm-lzbpt-tdv2h/providers/Microsoft.Compute/virtualMachines/us-vm-lzbpt-fgcds
26-
location: centralus
27-
name: us-vm-lzbpt-fgcds
28-
type: microsoft.compute/virtualmachines
29-
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vac-dr27h-ttsq5/providers/Microsoft.Compute/virtualMachines/us-vac-dr27h-t7dhd
30-
location: centralus
31-
name: us-vac-dr27h-t7dhd
32-
type: microsoft.compute/virtualmachines
33-
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/my-vm-mm59z/providers/Microsoft.Compute/virtualMachines/my-vm-jm8g2
34-
location: swedencentral
35-
name: my-vm-jm8g2
36-
type: microsoft.compute/virtualmachines
37-
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/javid-labs/providers/Microsoft.Compute/virtualMachines/devstack-test
38-
location: westus2
39-
name: devstack-test
40-
type: microsoft.compute/virtualmachines
4131
conditions:
4232
- lastTransitionTime: "2024-01-01T00:00:00Z"
4333
reason: Available
@@ -46,8 +36,19 @@ status:
4636
---
4737
apiVersion: render.crossplane.io/v1beta1
4838
kind: Result
49-
message: 'Query: "Resources | project name, location, type, id| where type =~ ''Microsoft.Compute/virtualMachines''
50-
| order by name desc"'
39+
message: 'Query: "Resources|count"'
5140
severity: SEVERITY_NORMAL
5241
step: query-azresourcegraph
42+
---
43+
apiVersion: render.crossplane.io/v1beta1
44+
fields:
45+
apiextensions.crossplane.io/environment:
46+
apiVersion: internal.crossplane.io/v1alpha1
47+
azResourceGraphQuery: Resources|count
48+
kind: Environment
49+
azResourceGraphQueryResult:
50+
- Count: 204
51+
kind: Context
5352
```
53+
54+
Explore the examples to better understand various use cases and integrations!

example/functions.yaml

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,8 @@ apiVersion: pkg.crossplane.io/v1beta1
33
kind: Function
44
metadata:
55
name: function-azresourcegraph
6+
annotations:
7+
# This tells crossplane beta render to connect to the function locally.
8+
render.crossplane.io/runtime: Development
69
spec:
710
package: xpkg.upbound.io/upboundcare/function-azresourcegraph:v0.2.0
8-
---
9-
apiVersion: pkg.crossplane.io/v1beta1
10-
kind: Function
11-
metadata:
12-
name: function-environment-configs
13-
spec:
14-
package: xpkg.upbound.io/crossplane-contrib/function-environment-configs:v0.2.0
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: render
2+
render:
3+
crossplane render ../xr.yaml composition.yaml ../functions.yaml --function-credentials=../secrets/azure-creds.yaml -rc
File renamed without changes.

example/definition.yaml renamed to example/query-with-mgmt-groups/definition.yaml

File renamed without changes.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.PHONY: render
2+
render:
3+
crossplane render ../xr.yaml composition.yaml ./functions.yaml --function-credentials=../secrets/azure-creds.yaml --extra-resources=envconfig.yaml -rc
File renamed without changes.
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: CompositeResourceDefinition
3+
metadata:
4+
name: xrs.example.crossplane.io
5+
spec:
6+
group: example.crossplane.io
7+
names:
8+
categories:
9+
- crossplane
10+
kind: XR
11+
plural: xrs
12+
versions:
13+
- name: v1
14+
referenceable: true
15+
schema:
16+
openAPIV3Schema:
17+
description: XR is the Schema for the XR API.
18+
properties:
19+
spec:
20+
description: XRSpec defines the desired state of XR.
21+
type: object
22+
status:
23+
description: XRStatus defines the observed state of XR.
24+
type: object
25+
properties:
26+
azResourceGraphQueryResult:
27+
description: Freeform field containing query results from function-azresourcegraph
28+
type: array
29+
items:
30+
type: object
31+
x-kubernetes-preserve-unknown-fields: true
32+
required:
33+
- spec
34+
type: object
35+
served: true
36+
status:
37+
controllers:
38+
compositeResourceClaimType:
39+
apiVersion: ""
40+
kind: ""
41+
compositeResourceType:
42+
apiVersion: ""
43+
kind: ""

example/envconfig.yaml renamed to example/queryref-from-environment/envconfig.yaml

File renamed without changes.

0 commit comments

Comments
 (0)