Skip to content

Commit ab9dcd8

Browse files
committed
Update READMEs and XRD
Signed-off-by: Yury Tsarev <[email protected]>
1 parent 5fbd8d1 commit ab9dcd8

File tree

5 files changed

+92
-40
lines changed

5 files changed

+92
-40
lines changed

README.md

Lines changed: 56 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,66 @@
1-
# function-template-go
2-
[![CI](https://github.com/crossplane/function-template-go/actions/workflows/ci.yml/badge.svg)](https://github.com/crossplane/function-template-go/actions/workflows/ci.yml)
1+
# function-azresourcegraph
2+
[![CI](https://github.com/UpboundCare//function-azresourcegraph/actions/workflows/ci.yml/badge.svg)](https://github.com/UpboundCare/function-azresourcegraph/actions/workflows/ci.yml)
33

4-
A template for writing a [composition function][functions] in [Go][go].
4+
A function to query [Azure Resource Graph][azresourcegraph]
55

6-
To learn how to use this template:
6+
## Usage
77

8-
* [Follow the guide to writing a composition function in Go][function guide]
9-
* [Learn about how composition functions work][functions]
10-
* [Read the function-sdk-go package documentation][package docs]
8+
See [examples][examples]
119

12-
If you just want to jump in and get started:
10+
Example pipeline step:
1311

14-
1. Replace `function-template-go` with your function in `go.mod`,
15-
`package/crossplane.yaml`, and any Go imports. (You can also do this
16-
automatically by running the `./init.sh <function-name>` script.)
17-
1. Update `input/v1beta1/` to reflect your desired input (and run `go generate`)
18-
1. Add your logic to `RunFunction` in `fn.go`
19-
1. Add tests for your logic in `fn_test.go`
20-
1. Update this file, `README.md`, to be about your function!
21-
22-
This template uses [Go][go], [Docker][docker], and the [Crossplane CLI][cli] to
23-
build functions.
24-
25-
```shell
26-
# Run code generation - see input/generate.go
27-
$ go generate ./...
12+
```yaml
13+
pipeline:
14+
- step: query-azresourcegraph
15+
functionRef:
16+
name: function-azresourcegraph
17+
input:
18+
apiVersion: azresourcegraph.fn.crossplane.io/v1alpha1
19+
kind: Input
20+
query: "Resources | project name, location, type, id| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
21+
credentials:
22+
- name: azure-creds
23+
source: Secret
24+
secretRef:
25+
namespace: upbound-system
26+
name: azure-account-creds
27+
```
2828
29-
# Run tests - see fn_test.go
30-
$ go test ./...
29+
The Azure Credentials Secret structure is fully compatible with the standard
30+
[Azure Official Provider][azop]
3131
32-
# Build the function's runtime image - see Dockerfile
33-
$ docker build . --tag=runtime
32+
Example XR status after e2e query:
3433
35-
# Build a function package - see package/crossplane.yaml
36-
$ crossplane xpkg build -f package --embed-runtime-image=runtime
34+
```yaml
35+
apiVersion: example.crossplane.io/v1
36+
kind: XR
37+
metadata:
38+
...
39+
status:
40+
azResourceGraphQueryResult:
41+
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vm-zxqnj-s2jdb/providers/Microsoft.Compute/virtualMachines/us-vm-zxqnj-2h59v
42+
location: centralus
43+
name: us-vm-zxqnj-2h59v
44+
type: microsoft.compute/virtualmachines
45+
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vm-lzbpt-tdv2h/providers/Microsoft.Compute/virtualMachines/us-vm-lzbpt-fgcds
46+
location: centralus
47+
name: us-vm-lzbpt-fgcds
48+
type: microsoft.compute/virtualmachines
49+
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/us-vac-dr27h-ttsq5/providers/Microsoft.Compute/virtualMachines/us-vac-dr27h-t7dhd
50+
location: centralus
51+
name: us-vac-dr27h-t7dhd
52+
type: microsoft.compute/virtualmachines
53+
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/my-vm-mm59z/providers/Microsoft.Compute/virtualMachines/my-vm-jm8g2
54+
location: swedencentral
55+
name: my-vm-jm8g2
56+
type: microsoft.compute/virtualmachines
57+
- id: /subscriptions/f403a412-959c-4214-8c4d-ad5598f149cc/resourceGroups/javid-labs/providers/Microsoft.Compute/virtualMachines/devstack-test
58+
location: westus2
59+
name: devstack-test
60+
type: microsoft.compute/virtualmachines
3761
```
3862
39-
[functions]: https://docs.crossplane.io/latest/concepts/composition-functions
40-
[go]: https://go.dev
41-
[function guide]: https://docs.crossplane.io/knowledge-base/guides/write-a-composition-function-in-go
42-
[package docs]: https://pkg.go.dev/github.com/crossplane/function-sdk-go
43-
[docker]: https://www.docker.com
44-
[cli]: https://docs.crossplane.io/latest/cli
63+
64+
[azresourcegraph]: https://learn.microsoft.com/en-us/azure/governance/resource-graph/
65+
[azop]: https://marketplace.upbound.io/providers/upbound/provider-family-azure/latest
66+
[examples]: ./example

example/README.md

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,44 @@ $ go run . --insecure --debug
1010

1111
```shell
1212
# Then, in another terminal, call it with these example manifests
13-
$ crossplane render example/xr.yaml example/composition.yaml example/functions.yaml --function-credentials=example/secrets/azure-creds.yaml -r
13+
$ crossplane render example/xr.yaml example/composition.yaml example/functions-dev.yaml --function-credentials=example/secrets/azure-creds.yaml -r
1414
---
1515
apiVersion: example.crossplane.io/v1
1616
kind: XR
1717
metadata:
1818
name: example-xr
19+
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
41+
conditions:
42+
- lastTransitionTime: "2024-01-01T00:00:00Z"
43+
reason: Available
44+
status: "True"
45+
type: Ready
1946
---
2047
apiVersion: render.crossplane.io/v1beta1
2148
kind: Result
22-
message: I was run with input "Hello world"!
49+
message: 'Query: "Resources | project name, location, type, id| where type =~ ''Microsoft.Compute/virtualMachines''
50+
| order by name desc"'
2351
severity: SEVERITY_NORMAL
24-
step: run-the-template
52+
step: query-azresourcegraph
2553
```

example/composition.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ spec:
88
kind: XR
99
mode: Pipeline
1010
pipeline:
11-
- step: run-the-template
11+
- step: query-azresourcegraph
1212
functionRef:
1313
name: function-azresourcegraph
1414
input:

example/definition.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ spec:
2525
properties:
2626
azResourceGraphQueryResult:
2727
description: Freeform field containing query results from function-azresourcegraph
28-
type: object
28+
type: array
29+
items:
30+
type: object
2931
x-kubernetes-preserve-unknown-fields: true
3032
required:
3133
- spec

example/functions.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,4 @@ kind: Function
44
metadata:
55
name: function-azresourcegraph
66
spec:
7-
package: xpkg.upbound.io/upboundcare/function-azresourcegraph:v0.0.0-20241211174419-67e6f1bcbc61
7+
package: xpkg.upbound.io/upboundcare/function-azresourcegraph:v0.0.0-20241211180855-5fbd8d144852

0 commit comments

Comments
 (0)