From 7de69bf5fa87096b511137fbddece7b8ba5f3639 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?= Date: Sun, 29 Sep 2024 15:20:18 +0200 Subject: [PATCH] feat: add compiler to the namespace template api 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_configurations.yaml | 14 ++++++++++++++ .crds/chainsaw.kyverno.io_tests.yaml | 7 +++++++ .../json/configuration-chainsaw-v1alpha1.json | 11 +++++++++++ .../json/configuration-chainsaw-v1alpha2.json | 11 +++++++++++ .schemas/json/test-chainsaw-v1alpha1.json | 11 +++++++++++ pkg/apis/conversion/configuration.go | 2 ++ pkg/apis/v1alpha1/configuration.go | 4 ++++ pkg/apis/v1alpha1/test.go | 4 ++++ pkg/apis/v1alpha1/types.go | 4 +++- pkg/apis/v1alpha1/zz_generated.deepcopy.go | 10 ++++++++++ pkg/apis/v1alpha2/options.go | 6 +++++- pkg/apis/v1alpha2/zz_generated.deepcopy.go | 6 ++++++ .../crds/chainsaw.kyverno.io_configurations.yaml | 14 ++++++++++++++ pkg/data/crds/chainsaw.kyverno.io_tests.yaml | 7 +++++++ .../json/configuration-chainsaw-v1alpha1.json | 11 +++++++++++ .../json/configuration-chainsaw-v1alpha2.json | 11 +++++++++++ .../schemas/json/test-chainsaw-v1alpha1.json | 11 +++++++++++ pkg/runner/processors/context.go | 10 ++++++---- pkg/runner/processors/namespace.go | 5 +++-- pkg/runner/processors/test.go | 16 +++++++++++++--- pkg/runner/processors/test_test.go | 1 + pkg/runner/processors/tests.go | 13 ++++++++++--- testdata/e2e/config.yaml | 3 ++- website/docs/reference/apis/chainsaw.v1alpha1.md | 2 ++ website/docs/reference/apis/chainsaw.v1alpha2.md | 1 + 25 files changed, 180 insertions(+), 15 deletions(-) diff --git a/.crds/chainsaw.kyverno.io_configurations.yaml b/.crds/chainsaw.kyverno.io_configurations.yaml index 0aab44bc6..cf43acd44 100644 --- a/.crds/chainsaw.kyverno.io_configurations.yaml +++ b/.crds/chainsaw.kyverno.io_configurations.yaml @@ -860,6 +860,13 @@ spec: description: NamespaceTemplate defines a template to create the test namespace. x-kubernetes-preserve-unknown-fields: true + namespaceTemplateCompiler: + description: NamespaceTemplateCompiler defines the default compiler + to use when evaluating expressions. + enum: + - jp + - cel + type: string parallel: description: The maximum number of tests to run at once. format: int @@ -1833,6 +1840,13 @@ spec: description: Namespace contains properties for the namespace to use for tests. properties: + compiler: + description: Compiler defines the default compiler to use when + evaluating expressions. + enum: + - jp + - cel + type: string name: description: |- Name defines the namespace to use for tests. diff --git a/.crds/chainsaw.kyverno.io_tests.yaml b/.crds/chainsaw.kyverno.io_tests.yaml index b046446cc..cbf2c68a3 100644 --- a/.crds/chainsaw.kyverno.io_tests.yaml +++ b/.crds/chainsaw.kyverno.io_tests.yaml @@ -881,6 +881,13 @@ spec: description: NamespaceTemplate defines a template to create the test namespace. x-kubernetes-preserve-unknown-fields: true + namespaceTemplateCompiler: + description: NamespaceTemplateCompiler defines the default compiler + to use when evaluating expressions. + enum: + - jp + - cel + type: string scenarios: description: Scenarios defines test scenarios. items: diff --git a/.schemas/json/configuration-chainsaw-v1alpha1.json b/.schemas/json/configuration-chainsaw-v1alpha1.json index 2479ca944..922864772 100644 --- a/.schemas/json/configuration-chainsaw-v1alpha1.json +++ b/.schemas/json/configuration-chainsaw-v1alpha1.json @@ -1698,6 +1698,17 @@ "description": "NamespaceTemplate defines a template to create the test namespace.", "x-kubernetes-preserve-unknown-fields": true }, + "namespaceTemplateCompiler": { + "description": "NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions.", + "type": [ + "string", + "null" + ], + "enum": [ + "jp", + "cel" + ] + }, "parallel": { "description": "The maximum number of tests to run at once.", "type": [ diff --git a/.schemas/json/configuration-chainsaw-v1alpha2.json b/.schemas/json/configuration-chainsaw-v1alpha2.json index 2c6bdb123..43dc90e7d 100644 --- a/.schemas/json/configuration-chainsaw-v1alpha2.json +++ b/.schemas/json/configuration-chainsaw-v1alpha2.json @@ -1783,6 +1783,17 @@ ], "default": {}, "properties": { + "compiler": { + "description": "Compiler defines the default compiler to use when evaluating expressions.", + "type": [ + "string", + "null" + ], + "enum": [ + "jp", + "cel" + ] + }, "name": { "description": "Name defines the namespace to use for tests.\nIf not specified, every test will execute in a random ephemeral namespace\nunless the namespace is overridden in a the test spec.", "type": [ diff --git a/.schemas/json/test-chainsaw-v1alpha1.json b/.schemas/json/test-chainsaw-v1alpha1.json index 1832ac367..3fe4c368d 100644 --- a/.schemas/json/test-chainsaw-v1alpha1.json +++ b/.schemas/json/test-chainsaw-v1alpha1.json @@ -1741,6 +1741,17 @@ "description": "NamespaceTemplate defines a template to create the test namespace.", "x-kubernetes-preserve-unknown-fields": true }, + "namespaceTemplateCompiler": { + "description": "NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions.", + "type": [ + "string", + "null" + ], + "enum": [ + "jp", + "cel" + ] + }, "scenarios": { "description": "Scenarios defines test scenarios.", "type": [ diff --git a/pkg/apis/conversion/configuration.go b/pkg/apis/conversion/configuration.go index a05e49a5c..4d558ea10 100644 --- a/pkg/apis/conversion/configuration.go +++ b/pkg/apis/conversion/configuration.go @@ -22,6 +22,7 @@ func Convert_v1alpha2_ConfigurationSpec_To_v1alpha1_ConfigurationSpec(in *v1alph out.ForceTerminationGracePeriod = in.Execution.ForceTerminationGracePeriod out.Namespace = in.Namespace.Name out.NamespaceTemplate = in.Namespace.Template + out.NamespaceTemplateCompiler = in.Namespace.Compiler if in := in.Report; in != nil { out.ReportFormat = v1alpha1.ReportFormatType(in.Format) out.ReportPath = in.Path @@ -58,6 +59,7 @@ func Convert_v1alpha1_ConfigurationSpec_To_v1alpha2_ConfigurationSpec(in *v1alph } out.Namespace = v1alpha2.NamespaceOptions{ Name: in.Namespace, + Compiler: in.NamespaceTemplateCompiler, Template: in.NamespaceTemplate, } out.Report = &v1alpha2.ReportOptions{ diff --git a/pkg/apis/v1alpha1/configuration.go b/pkg/apis/v1alpha1/configuration.go index ed0879be1..0ad7e004f 100644 --- a/pkg/apis/v1alpha1/configuration.go +++ b/pkg/apis/v1alpha1/configuration.go @@ -75,6 +75,10 @@ type ConfigurationSpec struct { // +optional Namespace string `json:"namespace,omitempty"` + // NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions. + // +optional + NamespaceTemplateCompiler *Compiler `json:"namespaceTemplateCompiler,omitempty"` + // NamespaceTemplate defines a template to create the test namespace. // +optional NamespaceTemplate *Projection `json:"namespaceTemplate,omitempty"` diff --git a/pkg/apis/v1alpha1/test.go b/pkg/apis/v1alpha1/test.go index e154d4b06..d464b9764 100644 --- a/pkg/apis/v1alpha1/test.go +++ b/pkg/apis/v1alpha1/test.go @@ -68,6 +68,10 @@ type TestSpec struct { // +optional NamespaceTemplate *Projection `json:"namespaceTemplate,omitempty"` + // NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions. + // +optional + NamespaceTemplateCompiler *Compiler `json:"namespaceTemplateCompiler,omitempty"` + // Scenarios defines test scenarios. // +optional Scenarios []Scenario `json:"scenarios,omitempty"` diff --git a/pkg/apis/v1alpha1/types.go b/pkg/apis/v1alpha1/types.go index 6332b44ce..59086daa4 100644 --- a/pkg/apis/v1alpha1/types.go +++ b/pkg/apis/v1alpha1/types.go @@ -20,6 +20,8 @@ var ( NewMatch = v1alpha1.NewAssertionTree ) +type Compiler = v1alpha1.Compiler + // Binding represents a key/value set as a binding in an executing test. type Binding struct { // Name the name of the binding. @@ -29,7 +31,7 @@ type Binding struct { // Compiler defines the default compiler to use when evaluating expressions. // +optional - Compiler *v1alpha1.Compiler `json:"compiler,omitempty"` + Compiler *Compiler `json:"compiler,omitempty"` // Value value of the binding. Value Projection `json:"value"` diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go index 62496aecb..90860d04c 100644 --- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go @@ -564,6 +564,11 @@ func (in *ConfigurationSpec) DeepCopyInto(out *ConfigurationSpec) { *out = new(int) **out = **in } + if in.NamespaceTemplateCompiler != nil { + in, out := &in.NamespaceTemplateCompiler, &out.NamespaceTemplateCompiler + *out = new(policyv1alpha1.Compiler) + **out = **in + } if in.NamespaceTemplate != nil { in, out := &in.NamespaceTemplate, &out.NamespaceTemplate *out = (*in).DeepCopy() @@ -1296,6 +1301,11 @@ func (in *TestSpec) DeepCopyInto(out *TestSpec) { in, out := &in.NamespaceTemplate, &out.NamespaceTemplate *out = (*in).DeepCopy() } + if in.NamespaceTemplateCompiler != nil { + in, out := &in.NamespaceTemplateCompiler, &out.NamespaceTemplateCompiler + *out = new(policyv1alpha1.Compiler) + **out = **in + } if in.Scenarios != nil { in, out := &in.Scenarios, &out.Scenarios *out = make([]Scenario, len(*in)) diff --git a/pkg/apis/v1alpha2/options.go b/pkg/apis/v1alpha2/options.go index 82ac84f6c..7c211bc2b 100644 --- a/pkg/apis/v1alpha2/options.go +++ b/pkg/apis/v1alpha2/options.go @@ -2,7 +2,7 @@ package v1alpha2 import ( "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" - _ "github.com/kyverno/kyverno-json/pkg/apis/policy/v1alpha1" + kjson "github.com/kyverno/kyverno-json/pkg/apis/policy/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -87,6 +87,10 @@ type NamespaceOptions struct { // +optional Name string `json:"name,omitempty"` + // Compiler defines the default compiler to use when evaluating expressions. + // +optional + Compiler *kjson.Compiler `json:"compiler,omitempty"` + // Template defines a template to create the test namespace. // +optional Template *Projection `json:"template,omitempty"` diff --git a/pkg/apis/v1alpha2/zz_generated.deepcopy.go b/pkg/apis/v1alpha2/zz_generated.deepcopy.go index 850aa76b7..afe512272 100644 --- a/pkg/apis/v1alpha2/zz_generated.deepcopy.go +++ b/pkg/apis/v1alpha2/zz_generated.deepcopy.go @@ -23,6 +23,7 @@ package v1alpha2 import ( v1alpha1 "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" + policyv1alpha1 "github.com/kyverno/kyverno-json/pkg/apis/policy/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" ) @@ -200,6 +201,11 @@ func (in *ExecutionOptions) DeepCopy() *ExecutionOptions { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NamespaceOptions) DeepCopyInto(out *NamespaceOptions) { *out = *in + if in.Compiler != nil { + in, out := &in.Compiler, &out.Compiler + *out = new(policyv1alpha1.Compiler) + **out = **in + } if in.Template != nil { in, out := &in.Template, &out.Template *out = (*in).DeepCopy() diff --git a/pkg/data/crds/chainsaw.kyverno.io_configurations.yaml b/pkg/data/crds/chainsaw.kyverno.io_configurations.yaml index 0aab44bc6..cf43acd44 100644 --- a/pkg/data/crds/chainsaw.kyverno.io_configurations.yaml +++ b/pkg/data/crds/chainsaw.kyverno.io_configurations.yaml @@ -860,6 +860,13 @@ spec: description: NamespaceTemplate defines a template to create the test namespace. x-kubernetes-preserve-unknown-fields: true + namespaceTemplateCompiler: + description: NamespaceTemplateCompiler defines the default compiler + to use when evaluating expressions. + enum: + - jp + - cel + type: string parallel: description: The maximum number of tests to run at once. format: int @@ -1833,6 +1840,13 @@ spec: description: Namespace contains properties for the namespace to use for tests. properties: + compiler: + description: Compiler defines the default compiler to use when + evaluating expressions. + enum: + - jp + - cel + type: string name: description: |- Name defines the namespace to use for tests. diff --git a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml index b046446cc..cbf2c68a3 100644 --- a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml +++ b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml @@ -881,6 +881,13 @@ spec: description: NamespaceTemplate defines a template to create the test namespace. x-kubernetes-preserve-unknown-fields: true + namespaceTemplateCompiler: + description: NamespaceTemplateCompiler defines the default compiler + to use when evaluating expressions. + enum: + - jp + - cel + type: string scenarios: description: Scenarios defines test scenarios. items: diff --git a/pkg/data/schemas/json/configuration-chainsaw-v1alpha1.json b/pkg/data/schemas/json/configuration-chainsaw-v1alpha1.json index 2479ca944..922864772 100644 --- a/pkg/data/schemas/json/configuration-chainsaw-v1alpha1.json +++ b/pkg/data/schemas/json/configuration-chainsaw-v1alpha1.json @@ -1698,6 +1698,17 @@ "description": "NamespaceTemplate defines a template to create the test namespace.", "x-kubernetes-preserve-unknown-fields": true }, + "namespaceTemplateCompiler": { + "description": "NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions.", + "type": [ + "string", + "null" + ], + "enum": [ + "jp", + "cel" + ] + }, "parallel": { "description": "The maximum number of tests to run at once.", "type": [ diff --git a/pkg/data/schemas/json/configuration-chainsaw-v1alpha2.json b/pkg/data/schemas/json/configuration-chainsaw-v1alpha2.json index 2c6bdb123..43dc90e7d 100644 --- a/pkg/data/schemas/json/configuration-chainsaw-v1alpha2.json +++ b/pkg/data/schemas/json/configuration-chainsaw-v1alpha2.json @@ -1783,6 +1783,17 @@ ], "default": {}, "properties": { + "compiler": { + "description": "Compiler defines the default compiler to use when evaluating expressions.", + "type": [ + "string", + "null" + ], + "enum": [ + "jp", + "cel" + ] + }, "name": { "description": "Name defines the namespace to use for tests.\nIf not specified, every test will execute in a random ephemeral namespace\nunless the namespace is overridden in a the test spec.", "type": [ diff --git a/pkg/data/schemas/json/test-chainsaw-v1alpha1.json b/pkg/data/schemas/json/test-chainsaw-v1alpha1.json index 1832ac367..3fe4c368d 100644 --- a/pkg/data/schemas/json/test-chainsaw-v1alpha1.json +++ b/pkg/data/schemas/json/test-chainsaw-v1alpha1.json @@ -1741,6 +1741,17 @@ "description": "NamespaceTemplate defines a template to create the test namespace.", "x-kubernetes-preserve-unknown-fields": true }, + "namespaceTemplateCompiler": { + "description": "NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions.", + "type": [ + "string", + "null" + ], + "enum": [ + "jp", + "cel" + ] + }, "scenarios": { "description": "Scenarios defines test scenarios.", "type": [ diff --git a/pkg/runner/processors/context.go b/pkg/runner/processors/context.go index e3d9579bf..181f3d098 100644 --- a/pkg/runner/processors/context.go +++ b/pkg/runner/processors/context.go @@ -7,14 +7,16 @@ import ( "github.com/kyverno/chainsaw/pkg/cleanup/cleaner" "github.com/kyverno/chainsaw/pkg/client" "github.com/kyverno/chainsaw/pkg/engine" + "github.com/kyverno/kyverno-json/pkg/core/compilers" corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/api/errors" ) type namespaceData struct { - name string - template *v1alpha1.Projection - cleaner cleaner.CleanerCollector + name string + compilers compilers.Compilers + template *v1alpha1.Projection + cleaner cleaner.CleanerCollector } type contextData struct { @@ -40,7 +42,7 @@ func setupContextData(ctx context.Context, tc engine.Context, data contextData) } var ns *corev1.Namespace if data.namespace != nil { - if namespace, err := buildNamespace(ctx, data.namespace.name, data.namespace.template, tc.Bindings()); err != nil { + if namespace, err := buildNamespace(ctx, data.namespace.compilers, data.namespace.name, data.namespace.template, tc.Bindings()); err != nil { return tc, nil, err } else if _, clusterClient, err := tc.CurrentClusterClient(); err != nil { return tc, nil, err diff --git a/pkg/runner/processors/namespace.go b/pkg/runner/processors/namespace.go index da55f2d3f..6535843c1 100644 --- a/pkg/runner/processors/namespace.go +++ b/pkg/runner/processors/namespace.go @@ -8,11 +8,12 @@ import ( "github.com/kyverno/chainsaw/pkg/engine/bindings" "github.com/kyverno/chainsaw/pkg/engine/templating" "github.com/kyverno/chainsaw/pkg/utils/kube" + "github.com/kyverno/kyverno-json/pkg/core/compilers" "github.com/kyverno/pkg/ext/resource/convert" corev1 "k8s.io/api/core/v1" ) -func buildNamespace(ctx context.Context, name string, template *v1alpha1.Projection, tc apis.Bindings) (*corev1.Namespace, error) { +func buildNamespace(ctx context.Context, compilers compilers.Compilers, name string, template *v1alpha1.Projection, tc apis.Bindings) (*corev1.Namespace, error) { namespace := kube.Namespace(name) if template == nil { return &namespace, nil @@ -22,7 +23,7 @@ func buildNamespace(ctx context.Context, name string, template *v1alpha1.Project } object := kube.ToUnstructured(&namespace) tc = bindings.RegisterBinding(ctx, tc, "namespace", object.GetName()) - merged, err := templating.TemplateAndMerge(ctx, apis.DefaultCompilers, object, tc, *template) + merged, err := templating.TemplateAndMerge(ctx, compilers, object, tc, *template) if err != nil { return nil, err } diff --git a/pkg/runner/processors/test.go b/pkg/runner/processors/test.go index b24a7aade..66c9c4080 100644 --- a/pkg/runner/processors/test.go +++ b/pkg/runner/processors/test.go @@ -6,6 +6,7 @@ import ( "time" petname "github.com/dustinkirkland/golang-petname" + "github.com/kyverno/chainsaw/pkg/apis" "github.com/kyverno/chainsaw/pkg/apis/v1alpha1" "github.com/kyverno/chainsaw/pkg/cleanup/cleaner" "github.com/kyverno/chainsaw/pkg/discovery" @@ -29,6 +30,7 @@ func NewTestProcessor( size int, clock clock.PassiveClock, nsTemplate *v1alpha1.Projection, + nsTemplateCompiler *v1alpha1.Compiler, delayBeforeCleanup *time.Duration, terminationGracePeriod *metav1.Duration, timeouts v1alpha1.DefaultTimeouts, @@ -39,6 +41,7 @@ func NewTestProcessor( ) TestProcessor { if template := test.Test.Spec.NamespaceTemplate; template != nil && template.Value() != nil { nsTemplate = template + nsTemplateCompiler = test.Test.Spec.NamespaceTemplateCompiler } if test.Test.Spec.DelayBeforeCleanup != nil { delayBeforeCleanup = &test.Test.Spec.DelayBeforeCleanup.Duration @@ -64,6 +67,7 @@ func NewTestProcessor( size: size, clock: clock, nsTemplate: nsTemplate, + nsTemplateCompiler: nsTemplateCompiler, delayBeforeCleanup: delayBeforeCleanup, terminationGracePeriod: terminationGracePeriod, timeouts: timeouts, @@ -79,6 +83,7 @@ type testProcessor struct { size int clock clock.PassiveClock nsTemplate *v1alpha1.Projection + nsTemplateCompiler *v1alpha1.Compiler delayBeforeCleanup *time.Duration terminationGracePeriod *metav1.Duration timeouts v1alpha1.DefaultTimeouts @@ -143,10 +148,15 @@ func (p *testProcessor) Run(ctx context.Context, nspacer namespacer.Namespacer, if !p.skipDelete { nsCleaner = mainCleaner } + compilers := apis.DefaultCompilers + if p.nsTemplateCompiler != nil { + compilers = compilers.WithDefaultCompiler(string(*p.nsTemplateCompiler)) + } contextData.namespace = &namespaceData{ - name: nsName, - template: p.nsTemplate, - cleaner: nsCleaner, + name: nsName, + template: p.nsTemplate, + compilers: compilers, + cleaner: nsCleaner, } } tc, namespace, err := setupContextData(ctx, tc, contextData) diff --git a/pkg/runner/processors/test_test.go b/pkg/runner/processors/test_test.go index 42f5c804e..9df3d28f1 100644 --- a/pkg/runner/processors/test_test.go +++ b/pkg/runner/processors/test_test.go @@ -290,6 +290,7 @@ func TestTestProcessor_Run(t *testing.T) { tc.clock, config.Spec.Namespace.Template, nil, + nil, config.Spec.Execution.ForceTerminationGracePeriod, config.Spec.Timeouts, config.Spec.Deletion.Propagation, diff --git a/pkg/runner/processors/tests.go b/pkg/runner/processors/tests.go index e8ed6cd39..78e4b4ff7 100644 --- a/pkg/runner/processors/tests.go +++ b/pkg/runner/processors/tests.go @@ -5,6 +5,7 @@ import ( "fmt" "time" + "github.com/kyverno/chainsaw/pkg/apis" "github.com/kyverno/chainsaw/pkg/cleanup/cleaner" "github.com/kyverno/chainsaw/pkg/discovery" "github.com/kyverno/chainsaw/pkg/engine" @@ -59,10 +60,15 @@ func (p *testsProcessor) Run(ctx context.Context, tc engine.Context, tests ...di if !p.config.Cleanup.SkipDelete { nsCleaner = mainCleaner } + compilers := apis.DefaultCompilers + if p.config.Namespace.Compiler != nil { + compilers = compilers.WithDefaultCompiler(string(*p.config.Namespace.Compiler)) + } contextData.namespace = &namespaceData{ - name: p.config.Namespace.Name, - template: p.config.Namespace.Template, - cleaner: nsCleaner, + name: p.config.Namespace.Name, + template: p.config.Namespace.Template, + compilers: compilers, + cleaner: nsCleaner, } } tc, namespace, err := setupContextData(ctx, tc, contextData) @@ -153,6 +159,7 @@ func (p *testsProcessor) createTestProcessor(test discovery.Test, size int) Test size, p.clock, p.config.Namespace.Template, + p.config.Namespace.Compiler, delayBeforeCleanup, p.config.Execution.ForceTerminationGracePeriod, p.config.Timeouts, diff --git a/testdata/e2e/config.yaml b/testdata/e2e/config.yaml index f2019be3e..f09528a82 100644 --- a/testdata/e2e/config.yaml +++ b/testdata/e2e/config.yaml @@ -11,7 +11,8 @@ spec: forceTerminationGracePeriod: 5s parallel: 1 namespace: + compiler: cel template: metadata: annotations: - from-config-file: hello + from-config-file: ("hello") diff --git a/website/docs/reference/apis/chainsaw.v1alpha1.md b/website/docs/reference/apis/chainsaw.v1alpha1.md index 95d307dbd..30699a09e 100644 --- a/website/docs/reference/apis/chainsaw.v1alpha1.md +++ b/website/docs/reference/apis/chainsaw.v1alpha1.md @@ -429,6 +429,7 @@ during the testing process.

| `reportPath` | `string` | | |

ReportPath defines the path.

| | `reportName` | `string` | | |

ReportName defines the name of report to create. It defaults to "chainsaw-report".

| | `namespace` | `string` | | |

Namespace defines the namespace to use for tests. If not specified, every test will execute in a random ephemeral namespace unless the namespace is overridden in a the test spec.

| +| `namespaceTemplateCompiler` | `policy/v1alpha1.Compiler` | | |

NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions.

| | `namespaceTemplate` | [`Projection`](#chainsaw-kyverno-io-v1alpha1-Projection) | | |

NamespaceTemplate defines a template to create the test namespace.

| | `fullName` | `bool` | | |

FullName makes use of the full test case folder path instead of the folder name.

| | `excludeTestRegex` | `string` | | |

ExcludeTestRegex is used to exclude tests based on a regular expression.

| @@ -901,6 +902,7 @@ If a resource doesn't exist yet in the cluster it will fail.

| `template` | `bool` | | |

Template determines whether resources should be considered for templating.

| | `namespace` | `string` | | |

Namespace determines whether the test should run in a random ephemeral namespace or not.

| | `namespaceTemplate` | [`Projection`](#chainsaw-kyverno-io-v1alpha1-Projection) | | |

NamespaceTemplate defines a template to create the test namespace.

| +| `namespaceTemplateCompiler` | `policy/v1alpha1.Compiler` | | |

NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions.

| | `scenarios` | [`[]Scenario`](#chainsaw-kyverno-io-v1alpha1-Scenario) | | |

Scenarios defines test scenarios.

| | `bindings` | [`[]Binding`](#chainsaw-kyverno-io-v1alpha1-Binding) | | |

Bindings defines additional binding key/values.

| | `steps` | [`[]TestStep`](#chainsaw-kyverno-io-v1alpha1-TestStep) | :white_check_mark: | |

Steps defining the test.

| diff --git a/website/docs/reference/apis/chainsaw.v1alpha2.md b/website/docs/reference/apis/chainsaw.v1alpha2.md index 022a27a41..b0c400024 100644 --- a/website/docs/reference/apis/chainsaw.v1alpha2.md +++ b/website/docs/reference/apis/chainsaw.v1alpha2.md @@ -130,6 +130,7 @@ auto_generated: true | Field | Type | Required | Inline | Description | |---|---|---|---|---| | `name` | `string` | | |

Name defines the namespace to use for tests. If not specified, every test will execute in a random ephemeral namespace unless the namespace is overridden in a the test spec.

| +| `compiler` | `policy/v1alpha1.Compiler` | | |

Compiler defines the default compiler to use when evaluating expressions.

| | `template` | [`Projection`](#chainsaw-kyverno-io-v1alpha1-Projection) | | |

Template defines a template to create the test namespace.

| ## ReportFormatType {#chainsaw-kyverno-io-v1alpha2-ReportFormatType}