-
Notifications
You must be signed in to change notification settings - Fork 4
Issue#51/support operations #54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ytsarev
merged 8 commits into
upbound:main
from
jonasz-lasut:issue#51/support-operations
Sep 9, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c02d2f1
Initial operations support
jonasz-lasut 184b7a2
Test Operations, add capabilities
jonasz-lasut c81fe0f
prepare failing tests with required operation fixes, removed connecti…
jonasz-lasut b673f3c
Support for operations with annotation-based notification mechanism
jonasz-lasut 61e086a
Fix rsp.Desired, run manual tests and confirm the correct annotations…
jonasz-lasut d20482f
Fix linter
jonasz-lasut adfce38
update readme
jonasz-lasut ddef4bd
Update README.md
jonasz-lasut File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -365,6 +365,125 @@ identity: | |
| type: AzureWorkloadIdentityCredentials | ||
| ``` | ||
|
|
||
| ## Operations support | ||
| function-msgraph support every kind of [operations](https://docs.crossplane.io/latest/operations/operation/) but it only allows targeting Composite Resources | ||
| Function omits the input.skipQueryWhenTargetHasData parameter when running in operation mode to enforce compability with Cron/Watch modes. | ||
| CronOperations and WatchOperations are the most useful in context of graph queries, please check [examples](./example/operations/). | ||
| ### Operations and Compositions Working Together | ||
|
|
||
| **Important**: Operations and Compositions work in conjunction to provide a self-healing mechanism: | ||
|
|
||
| 1. **Operations Role (Drift Detection)**: | ||
| - Query Microsoft Graph API on schedule/watch events | ||
| - Compare results with current XR status | ||
| - Set drift detection annotations (but don't update status directly) | ||
|
|
||
| 2. **Compositions Role (Drift Correction)**: | ||
| - Run when XR is reconciled (triggered by annotation changes) | ||
| - Check drift detection annotation | ||
| - If drift detected, ignore `skipQueryWhenTargetHasData` flag and update status | ||
| - Reset drift annotation to "false" after successful update | ||
|
|
||
| This creates a **two-phase self-healing system** where Operations monitor for changes and Compositions perform the actual data updates. | ||
| ### Operations results | ||
| function-msgraph operations result in two annotations set on the XR: | ||
| ```yaml | ||
| apiVersion: "example.org/v1" | ||
| kind: XR | ||
| metadata: | ||
| name: "cool-xr" | ||
| annotations: | ||
| "function-msgraph/last-execution": "2025-01-01T00:00:00+01:00" | ||
| "function-msgraph/last-execution-query-drift-detected": "false" | ||
| ``` | ||
| function-msgraph/last-execution sets RFC3339 timestamp informing about last succesful Operation run. | ||
| function-msgraph/last-execution-query-drift-detected sets a boolean if there's a drift between input.target field's value and query result, which is used by function-msgraph in Composition context for self-healing. skipQueryWhenTargetHasData input parameter is ommited when drift detected annotation is set which leads to XR update and after that next Operation run sets the annotation back to "false". | ||
|
|
||
| ### CronOperation | ||
| CronOperation may be used to forcefully update XR's status in a predefined interval. | ||
| That functionality may be especially useful for XRs that are business critical and should have the data refreshed without worrying about throttling. | ||
| Supports only singular resource reference. | ||
|
|
||
| ```yaml | ||
| apiVersion: ops.crossplane.io/v1alpha1 | ||
| kind: CronOperation | ||
| metadata: | ||
| name: update-user-validation-for-critical-xr | ||
| spec: | ||
| schedule: "*/5 * * * *" # Every 5 minutes | ||
| concurrencyPolicy: Forbid | ||
| successfulHistoryLimit: 5 | ||
| failedHistoryLimit: 3 | ||
| operationTemplate: | ||
| spec: | ||
| mode: Pipeline | ||
| pipeline: | ||
| - step: user-validation | ||
| functionRef: | ||
| name: function-msgraph | ||
| input: | ||
| apiVersion: msgraph.fn.crossplane.io/v1alpha1 | ||
| kind: Input | ||
| queryType: UserValidation | ||
| # Replace these with actual users in your directory | ||
| users: | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| target: "status.validatedUsers" | ||
| credentials: | ||
| - name: azure-creds | ||
| source: Secret | ||
| secretRef: | ||
| namespace: upbound-system | ||
| name: azure-account-creds | ||
| requirements: | ||
| requiredResources: | ||
| - requirementName: ops.crossplane.io/watched-resource | ||
| apiVersion: example.crossplane.io/v1 | ||
| kind: XR | ||
| name: business-critical-xr | ||
| ``` | ||
| ### WatchOperation | ||
| WatchOperation may be used to forcefully update XR's status based on match condition. | ||
| For example it may be useful to refresh status in business critical XR's that are labeled with label `always-update: "true"`. | ||
| ```yaml | ||
| apiVersion: ops.crossplane.io/v1alpha1 | ||
| kind: WatchOperation | ||
| metadata: | ||
| name: update-user-validation-for-critical-xrs | ||
| spec: | ||
| watch: | ||
| apiVersion: example.crossplane.io/v1 | ||
| kind: XR | ||
| matchLabels: | ||
| always-update: "true" | ||
| concurrencyPolicy: Allow | ||
| operationTemplate: | ||
| spec: | ||
| mode: Pipeline | ||
| pipeline: | ||
| - step: user-validation | ||
| functionRef: | ||
| name: function-msgraph | ||
| input: | ||
| apiVersion: msgraph.fn.crossplane.io/v1alpha1 | ||
| kind: Input | ||
| queryType: UserValidation | ||
| # Replace these with actual users in your directory | ||
| users: | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| target: "status.validatedUsers" | ||
| credentials: | ||
| - name: azure-creds | ||
| source: Secret | ||
| secretRef: | ||
| namespace: upbound-system | ||
| name: azure-account-creds | ||
| ``` | ||
|
|
||
| ## References | ||
|
|
||
| - [Microsoft Graph API Overview](https://learn.microsoft.com/en-us/graph/api/overview?view=graph-rest-1.0) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| apiVersion: ops.crossplane.io/v1alpha1 | ||
| kind: CronOperation | ||
| metadata: | ||
| name: update-user-validation-for-critical-xr | ||
| spec: | ||
| schedule: "*/1 * * * *" # Every minute | ||
| concurrencyPolicy: Forbid | ||
| successfulHistoryLimit: 5 | ||
| failedHistoryLimit: 3 | ||
| operationTemplate: | ||
| spec: | ||
| mode: Pipeline | ||
| pipeline: | ||
| - step: user-validation | ||
| functionRef: | ||
| name: function-msgraph | ||
| input: | ||
| apiVersion: msgraph.fn.crossplane.io/v1alpha1 | ||
| kind: Input | ||
| queryType: UserValidation | ||
| # Replace these with actual users in your directory | ||
| users: | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| target: "status.validatedUsers" | ||
| credentials: | ||
| - name: azure-creds | ||
| source: Secret | ||
| secretRef: | ||
| namespace: upbound-system | ||
| name: azure-account-creds | ||
| requirements: | ||
| requiredResources: | ||
| - requirementName: ops.crossplane.io/watched-resource | ||
| apiVersion: example.crossplane.io/v1 | ||
| kind: XR | ||
| name: business-critical-xr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| apiVersion: ops.crossplane.io/v1alpha1 | ||
| kind: Operation | ||
| metadata: | ||
| name: update-user-validation-for-critical-xr-once | ||
| spec: | ||
| spec: | ||
| mode: Pipeline | ||
| pipeline: | ||
| - step: user-validation | ||
| functionRef: | ||
| name: function-msgraph | ||
| input: | ||
| apiVersion: msgraph.fn.crossplane.io/v1alpha1 | ||
| kind: Input | ||
| queryType: UserValidation | ||
| # Replace these with actual users in your directory | ||
| users: | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| target: "status.validatedUsers" | ||
| credentials: | ||
| - name: azure-creds | ||
| source: Secret | ||
| secretRef: | ||
| namespace: upbound-system | ||
| name: azure-account-creds | ||
| requirements: | ||
| requiredResources: | ||
| - requirementName: ops.crossplane.io/watched-resource | ||
| apiVersion: example.crossplane.io/v1 | ||
| kind: XR | ||
| name: example-xr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| apiVersion: ops.crossplane.io/v1alpha1 | ||
| kind: WatchOperation | ||
| metadata: | ||
| name: update-user-validation-for-critical-xrs | ||
| spec: | ||
| watch: | ||
| apiVersion: example.crossplane.io/v1 | ||
| kind: XR | ||
| matchLabels: | ||
| always-update: "true" | ||
| concurrencyPolicy: Allow | ||
| operationTemplate: | ||
| spec: | ||
| mode: Pipeline | ||
| pipeline: | ||
| - step: user-validation | ||
| functionRef: | ||
| name: function-msgraph | ||
| input: | ||
| apiVersion: msgraph.fn.crossplane.io/v1alpha1 | ||
| kind: Input | ||
| queryType: UserValidation | ||
| # Replace these with actual users in your directory | ||
| users: | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| - "[email protected]" | ||
| target: "status.validatedUsers" | ||
| credentials: | ||
| - name: azure-creds | ||
| source: Secret | ||
| secretRef: | ||
| namespace: upbound-system | ||
| name: azure-account-creds |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.