-
Notifications
You must be signed in to change notification settings - Fork 257
DO NOT MERGE: Test PR to debug cel condition tests #4472
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
Changes from 2 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 | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -375,6 +375,68 @@ will merge each function pipeline list as an associative list, using | |||||||
| `name` as the merge key. An unspecified `name` or duplicated names may | ||||||||
| result in unexpected merges. | ||||||||
|
|
||||||||
| ### Specifying `condition` | ||||||||
|
|
||||||||
| The `condition` field lets you skip a function based on the current state of the resources in the package. | ||||||||
| It takes a [CEL](https://cel.dev/) expression that is evaluated against the resource list. If the expression | ||||||||
| returns `true`, the function runs. If it returns `false`, the function is skipped. | ||||||||
|
|
||||||||
| The expression receives a variable called `resources`, which is a list of all KRM resources passed to | ||||||||
| this function step (after `selectors` and `exclude` have been applied). Each resource is a map with | ||||||||
| the standard fields: `apiVersion`, `kind`, `metadata`, `spec`, `status`. | ||||||||
|
||||||||
| the standard fields: `apiVersion`, `kind`, `metadata`, `spec`, `status`. | |
| the standard fields `apiVersion`, `kind`, and `metadata`. Depending on the resource, fields such as | |
| `spec` and `status` may also be present. |
Copilot
AI
Apr 9, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the “condition not met” example, the output says Successfully executed 1 function(s) even though skipped functions are not counted as executed (and the e2e expectations show 0 function(s)). Please update the example output to match the CLI behavior.
| Successfully executed 1 function(s) in 1 package(s). | |
| Successfully executed 0 function(s) in 1 package(s). |
| 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..a13955d 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 | ||
| + 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 | ||
| + renderStatus: | ||
| + mutationSteps: | ||
| + - image: ghcr.io/kptdev/krm-functions-catalog/no-op:latest | ||
| + 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
InitDefaultsignores theInitCELEnvironment()error, but conditions in Kptfiles will fail later ifRunnerOptions.CELEnvironmentis nil (seefnruntime.NewRunner). Either propagate the init error here or adjust the surrounding logic/comments so a CEL init failure can’t lead to confusing runtime behavior.