Skip to content

Commit 184b7a2

Browse files
committed
Test Operations, add capabilities
1 parent c02d2f1 commit 184b7a2

File tree

7 files changed

+207
-3
lines changed

7 files changed

+207
-3
lines changed

README.md

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,97 @@ identity:
365365
type: AzureWorkloadIdentityCredentials
366366
```
367367

368+
## Operations support
369+
function-msgraph support every kind of [operations](https://docs.crossplane.io/latest/operations/operation/), however CronOperations and WatchOperations are the most useful in context of graph queries.
370+
Check [examples](./example/operations/)
371+
372+
### CronOperation
373+
CronOperation may be used to forcefully update XR's status in a predefined interval.
374+
That functionality may be especially useful for XRs that are business critical and should have the data refreshed without worrying about throttling.
375+
Supports only singular resource reference.
376+
377+
```yaml
378+
apiVersion: ops.crossplane.io/v1alpha1
379+
kind: CronOperation
380+
metadata:
381+
name: update-user-validation-for-critical-xr
382+
spec:
383+
schedule: "*/5 * * * *" # Every 5 minutes
384+
concurrencyPolicy: Forbid
385+
successfulHistoryLimit: 5
386+
failedHistoryLimit: 3
387+
operationTemplate:
388+
spec:
389+
mode: Pipeline
390+
pipeline:
391+
- step: user-validation
392+
functionRef:
393+
name: function-msgraph
394+
input:
395+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
396+
kind: Input
397+
queryType: UserValidation
398+
# Replace these with actual users in your directory
399+
users:
400+
- "admin@example.onmicrosoft.com"
401+
- "user@example.onmicrosoft.com"
402+
- "yury@upbound.io"
403+
target: "status.validatedUsers"
404+
skipQueryWhenTargetHasData: false # Always query even if data is in status
405+
credentials:
406+
- name: azure-creds
407+
source: Secret
408+
secretRef:
409+
namespace: upbound-system
410+
name: azure-account-creds
411+
requirements:
412+
requiredResources:
413+
- requirementName: ops.crossplane.io/watched-resource
414+
apiVersion: example.crossplane.io/v1
415+
kind: XR
416+
name: business-critical-xr
417+
```
418+
### WatchOperation
419+
WatchOperation may be used to forcefully update XR's status based on match condition.
420+
For example it may be useful to refresh status in business critical XR's that are labeled with label `always-update: "true"`.
421+
```yaml
422+
apiVersion: ops.crossplane.io/v1alpha1
423+
kind: WatchOperation
424+
metadata:
425+
name: update-user-validation-for-critical-xrs
426+
spec:
427+
watch:
428+
apiVersion: example.crossplane.io/v1
429+
kind: XR
430+
matchLabels:
431+
always-update: "true"
432+
concurrencyPolicy: Allow
433+
operationTemplate:
434+
spec:
435+
mode: Pipeline
436+
pipeline:
437+
- step: user-validation
438+
functionRef:
439+
name: function-msgraph
440+
input:
441+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
442+
kind: Input
443+
queryType: UserValidation
444+
# Replace these with actual users in your directory
445+
users:
446+
- "admin@example.onmicrosoft.com"
447+
- "user@example.onmicrosoft.com"
448+
- "yury@upbound.io"
449+
target: "status.validatedUsers"
450+
skipQueryWhenTargetHasData: false # Always query even if data is in status
451+
credentials:
452+
- name: azure-creds
453+
source: Secret
454+
secretRef:
455+
namespace: upbound-system
456+
name: azure-account-creds
457+
```
458+
368459
## References
369460
370461
- [Microsoft Graph API Overview](https://learn.microsoft.com/en-us/graph/api/overview?view=graph-rest-1.0)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
apiVersion: ops.crossplane.io/v1alpha1
2+
kind: CronOperation
3+
metadata:
4+
name: update-user-validation-for-critical-xr
5+
spec:
6+
schedule: "*/1 * * * *" # Every minute
7+
concurrencyPolicy: Forbid
8+
successfulHistoryLimit: 5
9+
failedHistoryLimit: 3
10+
operationTemplate:
11+
spec:
12+
mode: Pipeline
13+
pipeline:
14+
- step: user-validation
15+
functionRef:
16+
name: function-msgraph
17+
input:
18+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
19+
kind: Input
20+
queryType: UserValidation
21+
# Replace these with actual users in your directory
22+
users:
23+
- "admin@example.onmicrosoft.com"
24+
- "user@example.onmicrosoft.com"
25+
- "yury@upbound.io"
26+
target: "status.validatedUsers"
27+
skipQueryWhenTargetHasData: false # Always query even if data is in status
28+
credentials:
29+
- name: azure-creds
30+
source: Secret
31+
secretRef:
32+
namespace: upbound-system
33+
name: azure-account-creds
34+
requirements:
35+
requiredResources:
36+
- requirementName: ops.crossplane.io/watched-resource
37+
apiVersion: example.crossplane.io/v1
38+
kind: XR
39+
name: business-critical-xr

example/operations/operation.yaml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
apiVersion: ops.crossplane.io/v1alpha1
2+
kind: Operation
3+
metadata:
4+
name: update-user-validation-for-critical-xr-once
5+
spec:
6+
spec:
7+
mode: Pipeline
8+
pipeline:
9+
- step: user-validation
10+
functionRef:
11+
name: function-msgraph
12+
input:
13+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
14+
kind: Input
15+
queryType: UserValidation
16+
# Replace these with actual users in your directory
17+
users:
18+
- "admin@example.onmicrosoft.com"
19+
- "user@example.onmicrosoft.com"
20+
- "yury@upbound.io"
21+
target: "status.validatedUsers"
22+
skipQueryWhenTargetHasData: false # Always query even if data is in status
23+
credentials:
24+
- name: azure-creds
25+
source: Secret
26+
secretRef:
27+
namespace: upbound-system
28+
name: azure-account-creds
29+
requirements:
30+
requiredResources:
31+
- requirementName: ops.crossplane.io/watched-resource
32+
apiVersion: example.crossplane.io/v1
33+
kind: XR
34+
name: example-xr
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
apiVersion: ops.crossplane.io/v1alpha1
2+
kind: WatchOperation
3+
metadata:
4+
name: update-user-validation-for-critical-xrs
5+
spec:
6+
watch:
7+
apiVersion: example.crossplane.io/v1
8+
kind: XR
9+
matchLabels:
10+
always-update: "true"
11+
concurrencyPolicy: Allow
12+
operationTemplate:
13+
spec:
14+
mode: Pipeline
15+
pipeline:
16+
- step: user-validation
17+
functionRef:
18+
name: function-msgraph
19+
input:
20+
apiVersion: msgraph.fn.crossplane.io/v1alpha1
21+
kind: Input
22+
queryType: UserValidation
23+
# Replace these with actual users in your directory
24+
users:
25+
- "admin@example.onmicrosoft.com"
26+
- "user@example.onmicrosoft.com"
27+
- "yury@upbound.io"
28+
target: "status.validatedUsers"
29+
skipQueryWhenTargetHasData: false # Always query even if data is in status
30+
credentials:
31+
- name: azure-creds
32+
source: Secret
33+
secretRef:
34+
namespace: upbound-system
35+
name: azure-account-creds

fn.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ func (f *Function) getXRAndStatus(req *fnv1.RunFunctionRequest) (map[string]inte
140140
// getObservedAndDesired gets both observed and desired XR resources
141141
func (f *Function) getObservedAndDesired(req *fnv1.RunFunctionRequest) (*resource.Composite, *resource.Composite, error) {
142142
if req.GetObserved().GetComposite() != nil {
143+
f.log.Debug("triggered by composite resource")
143144
return getObservedAndDesiredInComposition(req)
144145
}
146+
f.log.Debug("triggered by operation")
145147
return getObservedAndDesiredInOperation(req)
146148
}
147149

package/crossplane.yaml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
apiVersion: meta.pkg.crossplane.io/v1beta1
2+
apiVersion: meta.pkg.crossplane.io/v1
33
kind: Function
44
metadata:
55
name: function-msgraph
@@ -13,4 +13,7 @@ metadata:
1313
to validate Azure AD users, get group memberships, group object IDs, and service principal details.
1414
1515
The secret for Azure credentials is compatible with the [Official Azure Provider](https://marketplace.upbound.io/providers/upbound/provider-family-azure/latest).
16-
spec: {}
16+
spec:
17+
capabilities:
18+
- composition
19+
- operation

package/input/msgraph.fn.crossplane.io_inputs.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ apiVersion: apiextensions.k8s.io/v1
33
kind: CustomResourceDefinition
44
metadata:
55
annotations:
6-
controller-gen.kubebuilder.io/version: v0.18.0
6+
controller-gen.kubebuilder.io/version: v0.19.0
77
name: inputs.msgraph.fn.crossplane.io
88
spec:
99
group: msgraph.fn.crossplane.io

0 commit comments

Comments
 (0)