-
Notifications
You must be signed in to change notification settings - Fork 257
feat: Add CEL-based conditional function execution (#4388) #4469
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| # Ensure consistent LF line endings for test data files | ||
| *.patch text eol=lf | ||
| *.yaml text eol=lf | ||
| *.yml text eol=lf | ||
| *.sh text eol=lf | ||
| *.go text eol=lf | ||
| *.md text eol=lf |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| actualStripLines: | ||
| - " stderr: 'WARNING: The requested image''s platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested'" | ||
|
|
||
| stdErrStripLines: | ||
| - " Stderr:" | ||
| - " \"WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested\"" | ||
|
|
||
| stdErr: | | ||
| Package: "condition-met" | ||
| [RUNNING] "ghcr.io/kptdev/krm-functions-catalog/no-op:latest" | ||
| [PASS] "ghcr.io/kptdev/krm-functions-catalog/no-op:latest" in 0s | ||
| Successfully executed 1 function(s) in 1 package(s). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| diff --git a/Kptfile b/Kptfile | ||
| index eb90ac3..5ccde1c 100644 | ||
| --- a/Kptfile | ||
| +++ b/Kptfile | ||
| @@ -5,4 +5,13 @@ metadata: | ||
| pipeline: | ||
| mutators: | ||
| - image: ghcr.io/kptdev/krm-functions-catalog/no-op | ||
| - condition: "resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'app-config')" | ||
| + condition: resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'app-config') | ||
| +status: | ||
| + conditions: | ||
| + - type: Rendered | ||
| + status: "True" | ||
| + reason: RenderSuccess | ||
| + renderStatus: | ||
| + mutationSteps: | ||
| + - image: ghcr.io/kptdev/krm-functions-catalog/no-op:latest | ||
| + exitCode: 0 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .expected |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| apiVersion: kpt.dev/v1 | ||
| kind: Kptfile | ||
| metadata: | ||
| name: app | ||
| pipeline: | ||
| mutators: | ||
| - image: ghcr.io/kptdev/krm-functions-catalog/no-op | ||
| condition: "resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'app-config')" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| apiVersion: v1 | ||
| kind: ConfigMap | ||
| metadata: | ||
| name: app-config | ||
| data: | ||
| key: value | ||
| --- | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: my-app | ||
| spec: | ||
| replicas: 1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| actualStripLines: | ||
| - " stderr: 'WARNING: The requested image''s platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested'" | ||
|
|
||
| stdErrStripLines: | ||
| - " Stderr:" | ||
| - " \"WARNING: The requested image's platform (linux/amd64) does not match the detected host platform (linux/arm64/v8) and no specific platform was requested\"" | ||
|
|
||
| stdErr: | | ||
| Package: "condition-not-met" | ||
| [SKIPPED] "ghcr.io/kptdev/krm-functions-catalog/no-op:latest" (condition not met) | ||
| Successfully executed 0 function(s) in 1 package(s). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| diff --git a/Kptfile b/Kptfile | ||
| index eb90ac3..ac7ae33 100644 | ||
| --- a/Kptfile | ||
| +++ b/Kptfile | ||
| @@ -5,4 +5,14 @@ metadata: | ||
| pipeline: | ||
| mutators: | ||
| - image: ghcr.io/kptdev/krm-functions-catalog/no-op | ||
| - condition: "resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'app-config')" | ||
| + condition: resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'app-config') | ||
| +status: | ||
| + conditions: | ||
| + - type: Rendered | ||
| + status: "True" | ||
| + reason: RenderSuccess | ||
|
liamfallon marked this conversation as resolved.
|
||
| + renderStatus: | ||
| + mutationSteps: | ||
| + - image: ghcr.io/kptdev/krm-functions-catalog/no-op:latest | ||
| + exitCode: 0 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It would also be worth capturing the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree with @nagygergo and @aravindtga - the render condition should reflect the overall pipeline result, not individual function execution. Since the pipeline completed successfully (just with some functions skipped), keeping status: "True" makes sense. I can update the reason to RenderedWithSkippedFunctions when at least one function was skipped, so consumers can distinguish between a fully executed render and one with skipped functions. I can also add the condition field to status.renderStatus so the skip reason is recorded alongside the result. Let me know if you'd like me to go ahead with these changes
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
A condition field has been introduced in the mutation pipeline configuration: mutators:
- image: ghcr.io/kptdev/krm-functions-catalog/no-op
condition: resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'app-config')Can you also add the condition field to status.renderStatus.mutationSteps so it gets recorded when the pipeline execution is captured? e.g: status:
conditions:
- type: Rendered
status: "True"
reason: RenderSuccess
renderStatus:
mutationSteps:
- image: ghcr.io/kptdev/krm-functions-catalog/no-op:latest
condition: resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'app-config')
exitCode: 0
.... |
||
| + skipped: true | ||
| diff --git a/resources.yaml b/resources.yaml | ||
| index 7806994..c8cdecf 100644 | ||
| --- a/resources.yaml | ||
| +++ b/resources.yaml | ||
| @@ -3,4 +3,4 @@ kind: Deployment | ||
| metadata: | ||
| name: my-app | ||
| spec: | ||
| - replicas: 1 | ||
| \ No newline at end of file | ||
| + replicas: 1 | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| .expected |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| apiVersion: kpt.dev/v1 | ||
| kind: Kptfile | ||
| metadata: | ||
| name: app | ||
| pipeline: | ||
| mutators: | ||
| - image: ghcr.io/kptdev/krm-functions-catalog/no-op | ||
| condition: "resources.exists(r, r.kind == 'ConfigMap' && r.metadata.name == 'app-config')" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| apiVersion: apps/v1 | ||
| kind: Deployment | ||
| metadata: | ||
| name: my-app | ||
| spec: | ||
| replicas: 1 |
Uh oh!
There was an error while loading. Please reload this page.