You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+22-29Lines changed: 22 additions & 29 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,11 +7,11 @@ A Crossplane Composition Function for implementing manual approval workflows.
7
7
The `function-approve` provides a serverless approval mechanism at the Crossplane level that:
8
8
9
9
1. Tracks changes to a specified field by computing a hash
10
-
2. When changes need approval, overwrites Desired state with Observed state to prevent changes
10
+
2. When changes need approval, uses fatal results to halt pipeline execution
11
11
3. Requires explicit approval before allowing changes to proceed
12
12
4. Prevents drift by storing previously approved state
13
13
14
-
This function implements the approval workflow using entirely Crossplane-native mechanisms without external dependencies, making it lightweight and reliable.
14
+
This function implements the approval workflow using Crossplane's fatal result mechanism, ensuring that no changes are applied until explicitly approved.
15
15
16
16
## Usage
17
17
@@ -29,10 +29,10 @@ spec:
29
29
### How It Works
30
30
31
31
1. When a resource is created or updated, `function-approve` calculates a hash of the monitored field (e.g., `spec.resources`).
32
-
2. The function stores this hash in `status.newHash` (or specified field).
33
-
3. If there's a previous approved hash (`status.oldHash`) and it doesn't match the new hash, the function replaces Desired state with Observed state.
32
+
2. The function compares this hash with the previously approved hash stored in `status.currentHash`.
33
+
3. If the hashes don't match and approval is not granted, the function returns a fatal result to halt pipeline execution.
34
34
4. An operator must approve the change by setting `status.approved = true`.
35
-
5. After approval, the new hash is stored as the approved hash, the approval flag is reset, and changes are allowed to proceed.
35
+
5. After approval, the new hash is stored as `currentHash`, the approval flag is reset, and changes are allowed to proceed.
36
36
6. If a customer modifies an existing claim after approval, this will generate a new hash, requiring another approval.
37
37
38
38
## Example
@@ -55,9 +55,7 @@ spec:
55
55
kind: Input
56
56
dataField: "spec.resources" # Field to monitor for changes
57
57
approvalField: "status.approved"
58
-
newHashField: "status.newHash"
59
-
oldHashField: "status.oldHash"
60
-
pauseAnnotation: "crossplane.io/paused"
58
+
currentHashField: "status.currentHash"
61
59
detailedCondition: true
62
60
```
63
61
@@ -68,8 +66,7 @@ spec:
68
66
| `dataField` | string | **Required**. Field to monitor for changes (e.g., `spec.resources`) |
69
67
| `hashAlgorithm` | string | Algorithm to use for hash calculation. Supported values: `md5`, `sha256`, `sha512`. Default: `sha256` |
70
68
| `approvalField` | string | Status field to check for approval. Default: `status.approved`|
71
-
| `oldHashField` | string | Status field to store previously approved hash. Default: `status.oldHash`|
72
-
| `newHashField` | string | Status field to store current hash. Default: `status.newHash`|
69
+
| `currentHashField` | string | Status field to store the approved hash. Default: `status.currentHash`|
73
70
| `detailedCondition` | bool | Whether to add detailed information to conditions. Default: `true`|
74
71
| `approvalMessage` | string | Message to display when approval is required. Default: `Changes detected. Approval required.`|
75
72
@@ -107,32 +104,30 @@ spec:
107
104
approved:
108
105
type: boolean
109
106
description: "Whether the current changes are approved"
110
-
oldHash:
107
+
currentHash:
111
108
type: string
112
-
description: "Hash of previously approved resource state"
113
-
newHash:
114
-
type: string
115
-
description: "Hash of current resource state"
109
+
description: "Hash of the currently approved resource state"
116
110
```
117
111
118
112
## Approving Changes
119
113
120
-
When changes are detected, the Desired state is replaced with Observed state (preventing any changes from being applied), and the resource will show an `ApprovalRequired` condition. To approve the changes, patch the resource's status:
114
+
When changes are detected, the function returns a fatal result (halting pipeline execution) and the resource will show an `ApprovalRequired` condition. To approve the changes, patch the resource's status:
121
115
122
116
```yaml
123
117
kubectl patch xapproval example --type=merge --subresource=status -p '{"status":{"approved":true}}'
124
118
```
125
119
126
120
After approval, the function will:
127
-
1. Record the new state as the approved state
128
-
2. Allow the changes to proceed normally without overwriting the Desired state
121
+
1. Update `currentHash` to the new approved hash
122
+
2. Reset the approval flag to `false`
123
+
3. Allow the pipeline to continue normally
129
124
130
125
## Resetting Approval State
131
126
132
-
If you need to reset the approval state, you can clear the `oldHash` field:
127
+
If you need to reset the approval state, you can clear the `currentHash` field:
133
128
134
129
```yaml
135
-
kubectl patch xapproval example --type=merge --subresource=status -p '{"status":{"oldHash":""}}'
130
+
kubectl patch xapproval example --type=merge --subresource=status -p '{"status":{"currentHash":""}}'
0 commit comments