From e876efe102360719205e8ecb3568fe4b31d6cee8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?=
Date: Mon, 30 Sep 2024 11:13:34 +0200
Subject: [PATCH] feat: add compiler at the step api level (#2043)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Charles-Edouard Brétéché
---
.crds/chainsaw.kyverno.io_tests.yaml | 7 +++++++
.schemas/json/test-chainsaw-v1alpha1.json | 11 +++++++++++
pkg/apis/v1alpha1/step.go | 4 ++++
pkg/apis/v1alpha1/zz_generated.deepcopy.go | 5 +++++
pkg/data/crds/chainsaw.kyverno.io_tests.yaml | 7 +++++++
pkg/data/schemas/json/test-chainsaw-v1alpha1.json | 11 +++++++++++
pkg/runner/processors/step.go | 3 +++
website/docs/reference/apis/chainsaw.v1alpha1.md | 1 +
8 files changed, 49 insertions(+)
diff --git a/.crds/chainsaw.kyverno.io_tests.yaml b/.crds/chainsaw.kyverno.io_tests.yaml
index 5ad16d407..6b58bf5c7 100644
--- a/.crds/chainsaw.kyverno.io_tests.yaml
+++ b/.crds/chainsaw.kyverno.io_tests.yaml
@@ -2556,6 +2556,13 @@ spec:
description: Clusters holds a registry to clusters to support
multi-cluster tests.
type: object
+ compiler:
+ description: Compiler defines the default compiler to use when
+ evaluating expressions.
+ enum:
+ - jp
+ - cel
+ type: string
deletionPropagationPolicy:
description: |-
DeletionPropagationPolicy decides if a deletion will propagate to the dependents of
diff --git a/.schemas/json/test-chainsaw-v1alpha1.json b/.schemas/json/test-chainsaw-v1alpha1.json
index 6c448c868..da73a9fa9 100644
--- a/.schemas/json/test-chainsaw-v1alpha1.json
+++ b/.schemas/json/test-chainsaw-v1alpha1.json
@@ -4499,6 +4499,17 @@
"additionalProperties": false
}
},
+ "compiler": {
+ "description": "Compiler defines the default compiler to use when evaluating expressions.",
+ "type": [
+ "string",
+ "null"
+ ],
+ "enum": [
+ "jp",
+ "cel"
+ ]
+ },
"deletionPropagationPolicy": {
"description": "DeletionPropagationPolicy decides if a deletion will propagate to the dependents of\nthe object, and how the garbage collector will handle the propagation.\nOverrides the deletion propagation policy set in both the Configuration and the Test.",
"type": [
diff --git a/pkg/apis/v1alpha1/step.go b/pkg/apis/v1alpha1/step.go
index 6be982132..5ad379c23 100644
--- a/pkg/apis/v1alpha1/step.go
+++ b/pkg/apis/v1alpha1/step.go
@@ -110,6 +110,10 @@ type TestStepSpec struct {
// +optional
Template *bool `json:"template,omitempty"`
+ // Compiler defines the default compiler to use when evaluating expressions.
+ // +optional
+ Compiler *Compiler `json:"compiler,omitempty"`
+
// Bindings defines additional binding key/values.
// +optional
Bindings []Binding `json:"bindings,omitempty"`
diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go
index 0c8e6e909..46949eb2b 100644
--- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go
@@ -1429,6 +1429,11 @@ func (in *TestStepSpec) DeepCopyInto(out *TestStepSpec) {
*out = new(bool)
**out = **in
}
+ if in.Compiler != nil {
+ in, out := &in.Compiler, &out.Compiler
+ *out = new(policyv1alpha1.Compiler)
+ **out = **in
+ }
if in.Bindings != nil {
in, out := &in.Bindings, &out.Bindings
*out = make([]Binding, len(*in))
diff --git a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
index 5ad16d407..6b58bf5c7 100644
--- a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
+++ b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
@@ -2556,6 +2556,13 @@ spec:
description: Clusters holds a registry to clusters to support
multi-cluster tests.
type: object
+ compiler:
+ description: Compiler defines the default compiler to use when
+ evaluating expressions.
+ enum:
+ - jp
+ - cel
+ type: string
deletionPropagationPolicy:
description: |-
DeletionPropagationPolicy decides if a deletion will propagate to the dependents of
diff --git a/pkg/data/schemas/json/test-chainsaw-v1alpha1.json b/pkg/data/schemas/json/test-chainsaw-v1alpha1.json
index 6c448c868..da73a9fa9 100644
--- a/pkg/data/schemas/json/test-chainsaw-v1alpha1.json
+++ b/pkg/data/schemas/json/test-chainsaw-v1alpha1.json
@@ -4499,6 +4499,17 @@
"additionalProperties": false
}
},
+ "compiler": {
+ "description": "Compiler defines the default compiler to use when evaluating expressions.",
+ "type": [
+ "string",
+ "null"
+ ],
+ "enum": [
+ "jp",
+ "cel"
+ ]
+ },
"deletionPropagationPolicy": {
"description": "DeletionPropagationPolicy decides if a deletion will propagate to the dependents of\nthe object, and how the garbage collector will handle the propagation.\nOverrides the deletion propagation policy set in both the Configuration and the Test.",
"type": [
diff --git a/pkg/runner/processors/step.go b/pkg/runner/processors/step.go
index 6e9830c05..38abcd7e3 100644
--- a/pkg/runner/processors/step.go
+++ b/pkg/runner/processors/step.go
@@ -104,6 +104,9 @@ func (p *stepProcessor) Run(ctx context.Context, namespacer namespacer.Namespace
p.report.Add(report)
}()
logger := logging.FromContext(ctx)
+ if p.step.Compiler != nil {
+ tc = tc.WithDefaultCompiler(string(*p.step.Compiler))
+ }
tc, _, err := setupContextData(ctx, tc, contextData{
basePath: p.basePath,
bindings: p.step.Bindings,
diff --git a/website/docs/reference/apis/chainsaw.v1alpha1.md b/website/docs/reference/apis/chainsaw.v1alpha1.md
index 56fd29556..a64ba0162 100644
--- a/website/docs/reference/apis/chainsaw.v1alpha1.md
+++ b/website/docs/reference/apis/chainsaw.v1alpha1.md
@@ -946,6 +946,7 @@ If a resource doesn't exist yet in the cluster it will fail.
| `clusters` | [`Clusters`](#chainsaw-kyverno-io-v1alpha1-Clusters) | | | Clusters holds a registry to clusters to support multi-cluster tests.
|
| `skipDelete` | `bool` | | | SkipDelete determines whether the resources created by the step should be deleted after the test step is executed.
|
| `template` | `bool` | | | Template determines whether resources should be considered for templating.
|
+| `compiler` | `policy/v1alpha1.Compiler` | | | Compiler defines the default compiler to use when evaluating expressions.
|
| `bindings` | [`[]Binding`](#chainsaw-kyverno-io-v1alpha1-Binding) | | | Bindings defines additional binding key/values.
|
| `try` | [`[]Operation`](#chainsaw-kyverno-io-v1alpha1-Operation) | | | Try defines what the step will try to execute.
|
| `catch` | [`[]CatchFinally`](#chainsaw-kyverno-io-v1alpha1-CatchFinally) | | | Catch defines what the step will execute when an error happens.
|