Skip to content

Commit 9caae27

Browse files
authored
Add subscriptionsRef and refactor XR handling (#56)
* Add subscriptionsRef capability Signed-off-by: Yury Tsarev <[email protected]> * Generate new subscriptionsRef field Signed-off-by: Yury Tsarev <[email protected]> * refactor XR handling, add subscriptionsRef render example * Standardize XR status handling across operations. * Always take DXR into account * Add subscriptionsRef render/e2e example Signed-off-by: Yury Tsarev <[email protected]> * Consistent OXR/DXR handling Signed-off-by: Yury Tsarev <[email protected]> * Enable dot notation for subscriptionsRef status and context Using crossplane-runtime fieldpath Signed-off-by: Yury Tsarev <[email protected]> * Add tests for nested and bracket subscriptionsRef from status Signed-off-by: Yury Tsarev <[email protected]> * Add dot notation and bracket tests for subscriptionsRef from context Signed-off-by: Yury Tsarev <[email protected]> * Extend README Signed-off-by: Yury Tsarev <[email protected]> --------- Signed-off-by: Yury Tsarev <[email protected]>
1 parent 75cb82e commit 9caae27

File tree

16 files changed

+871
-114
lines changed

16 files changed

+871
-114
lines changed

README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,30 @@ using the optional `skipQueryWhenTargetHasData` flag:
125125

126126
Use this option carefully, as it may lead to stale query results over time.
127127

128+
## Explicit Subscriptions scope
129+
130+
It is possible to specify explicit subscriptions scope and override the one that
131+
is coming from credentials
132+
133+
```yaml
134+
kind: Input
135+
query: "Resources | project name, location, type, id| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
136+
subscriptions:
137+
- 00000000-0000-0000-0000-000000000001
138+
- 00000000-0000-0000-0000-000000000002
139+
target: "status.azResourceGraphQueryResult"
140+
```
141+
142+
There is also possible to use references from status and context.
143+
144+
145+
```yaml
146+
subscriptionsRef: status.subscriptions
147+
```
148+
149+
```yaml
150+
subscriptionsRef: "context.[apiextensions.crossplane.io/environment].subscriptions"
151+
```
128152

129153
[azresourcegraph]: https://learn.microsoft.com/en-us/azure/governance/resource-graph/
130154
[azop]: https://marketplace.upbound.io/providers/upbound/provider-family-azure/latest
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
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: Composition
3+
metadata:
4+
name: function-azresourcegraph
5+
spec:
6+
compositeTypeRef:
7+
apiVersion: example.crossplane.io/v1
8+
kind: XR
9+
mode: Pipeline
10+
pipeline:
11+
- step: environmentConfigs
12+
functionRef:
13+
name: crossplane-contrib-function-environment-configs
14+
input:
15+
apiVersion: environmentconfigs.fn.crossplane.io/v1beta1
16+
kind: Input
17+
spec:
18+
environmentConfigs:
19+
- type: Reference
20+
ref:
21+
name: example-config
22+
- step: query-azresourcegraph
23+
functionRef:
24+
name: function-azresourcegraph
25+
input:
26+
apiVersion: azresourcegraph.fn.crossplane.io/v1beta1
27+
kind: Input
28+
queryRef: "context.[apiextensions.crossplane.io/environment].azResourceGraphQuery"
29+
subscriptionsRef: "context.[apiextensions.crossplane.io/environment].subscriptions"
30+
target: "status.azResourceGraphQueryResult"
31+
credentials:
32+
- name: azure-creds
33+
source: Secret
34+
secretRef:
35+
namespace: upbound-system
36+
name: azure-account-creds
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: ""
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
apiVersion: apiextensions.crossplane.io/v1alpha1
2+
kind: EnvironmentConfig
3+
metadata:
4+
name: example-config
5+
data:
6+
azResourceGraphQuery: "Resources|count"
7+
subscriptions:
8+
- 00000000-0000-0000-0000-000000000001
9+
- 00000000-0000-0000-0000-000000000002
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: pkg.crossplane.io/v1beta1
3+
kind: Function
4+
metadata:
5+
name: function-azresourcegraph
6+
annotations:
7+
# This tells crossplane beta render to connect to the function locally.
8+
render.crossplane.io/runtime: Development
9+
spec:
10+
package: xpkg.upbound.io/upbound/function-azresourcegraph:v0.7.0
11+
---
12+
apiVersion: pkg.crossplane.io/v1beta1
13+
kind: Function
14+
metadata:
15+
name: crossplane-contrib-function-environment-configs
16+
spec:
17+
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
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
apiVersion: apiextensions.crossplane.io/v1
2+
kind: Composition
3+
metadata:
4+
name: function-azresourcegraph
5+
spec:
6+
compositeTypeRef:
7+
apiVersion: example.crossplane.io/v1
8+
kind: XR
9+
mode: Pipeline
10+
pipeline:
11+
- step: query-to-status
12+
functionRef:
13+
name: function-go-templating
14+
input:
15+
apiVersion: gotemplating.fn.crossplane.io/v1beta1
16+
kind: GoTemplate
17+
source: Inline
18+
inline:
19+
template: |
20+
apiVersion: example.crossplane.io/v1
21+
kind: XR
22+
status:
23+
subscriptions:
24+
- 00000000-0000-0000-0000-000000000001
25+
- 00000000-0000-0000-0000-000000000002
26+
- step: query-azresourcegraph
27+
functionRef:
28+
name: function-azresourcegraph
29+
input:
30+
apiVersion: azresourcegraph.fn.crossplane.io/v1beta1
31+
kind: Input
32+
query: "Resources | project name, location, type, id| where type =~ 'Microsoft.Compute/virtualMachines' | order by name desc"
33+
target: "status.azResourceGraphQueryResult"
34+
subscriptionsRef: status.subscriptions
35+
credentials:
36+
- name: azure-creds
37+
source: Secret
38+
secretRef:
39+
namespace: upbound-system
40+
name: azure-account-creds
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
properties:
23+
queryResourceType:
24+
description: resource type for az resource query construction
25+
type: string
26+
status:
27+
description: XRStatus defines the observed state of XR.
28+
type: object
29+
properties:
30+
azResourceGraphQueryResult:
31+
description: Freeform field containing query results from function-azresourcegraph
32+
type: array
33+
items:
34+
type: object
35+
x-kubernetes-preserve-unknown-fields: true
36+
azResourceGraphQuery:
37+
description: Freeform field containing query results from function-azresourcegraph
38+
type: string
39+
subscriptions:
40+
description: Field to dynamically propagate subscriptions IDs
41+
type: array
42+
items:
43+
type: string
44+
required:
45+
- spec
46+
type: object
47+
served: true
48+
status:
49+
controllers:
50+
compositeResourceClaimType:
51+
apiVersion: ""
52+
kind: ""
53+
compositeResourceType:
54+
apiVersion: ""
55+
kind: ""
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
apiVersion: pkg.crossplane.io/v1beta1
3+
kind: Function
4+
metadata:
5+
name: function-azresourcegraph
6+
annotations:
7+
# This tells crossplane beta render to connect to the function locally.
8+
render.crossplane.io/runtime: Development
9+
spec:
10+
package: xpkg.upbound.io/upbound/function-azresourcegraph:v0.6.0
11+
---
12+
apiVersion: pkg.crossplane.io/v1beta1
13+
kind: Function
14+
metadata:
15+
name: function-go-templating
16+
spec:
17+
package: xpkg.upbound.io/crossplane-contrib/function-go-templating:v0.9.2

0 commit comments

Comments
 (0)