Skip to content

Commit b7c3753

Browse files
feat: add default compiler at the test api level (#2041) (#2042)
Signed-off-by: Charles-Edouard Brétéché <[email protected]> Co-authored-by: Charles-Edouard Brétéché <[email protected]>
1 parent 2189aa4 commit b7c3753

File tree

8 files changed

+51
-0
lines changed

8 files changed

+51
-0
lines changed

.crds/chainsaw.kyverno.io_tests.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,13 @@ spec:
844844
description: Clusters holds a registry to clusters to support multi-cluster
845845
tests.
846846
type: object
847+
compiler:
848+
description: Compiler defines the default compiler to use when evaluating
849+
expressions.
850+
enum:
851+
- jp
852+
- cel
853+
type: string
847854
concurrent:
848855
description: Concurrent determines whether the test should run concurrently
849856
with other tests.

.schemas/json/test-chainsaw-v1alpha1.json

+11
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,17 @@
16831683
"additionalProperties": false
16841684
}
16851685
},
1686+
"compiler": {
1687+
"description": "Compiler defines the default compiler to use when evaluating expressions.",
1688+
"type": [
1689+
"string",
1690+
"null"
1691+
],
1692+
"enum": [
1693+
"jp",
1694+
"cel"
1695+
]
1696+
},
16861697
"concurrent": {
16871698
"description": "Concurrent determines whether the test should run concurrently with other tests.",
16881699
"type": [

pkg/apis/v1alpha1/test.go

+4
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ type TestSpec struct {
6060
// +optional
6161
Template *bool `json:"template,omitempty"`
6262

63+
// Compiler defines the default compiler to use when evaluating expressions.
64+
// +optional
65+
Compiler *Compiler `json:"compiler,omitempty"`
66+
6367
// Namespace determines whether the test should run in a random ephemeral namespace or not.
6468
// +optional
6569
Namespace string `json:"namespace,omitempty"`

pkg/apis/v1alpha1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/data/crds/chainsaw.kyverno.io_tests.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -844,6 +844,13 @@ spec:
844844
description: Clusters holds a registry to clusters to support multi-cluster
845845
tests.
846846
type: object
847+
compiler:
848+
description: Compiler defines the default compiler to use when evaluating
849+
expressions.
850+
enum:
851+
- jp
852+
- cel
853+
type: string
847854
concurrent:
848855
description: Concurrent determines whether the test should run concurrently
849856
with other tests.

pkg/data/schemas/json/test-chainsaw-v1alpha1.json

+11
Original file line numberDiff line numberDiff line change
@@ -1683,6 +1683,17 @@
16831683
"additionalProperties": false
16841684
}
16851685
},
1686+
"compiler": {
1687+
"description": "Compiler defines the default compiler to use when evaluating expressions.",
1688+
"type": [
1689+
"string",
1690+
"null"
1691+
],
1692+
"enum": [
1693+
"jp",
1694+
"cel"
1695+
]
1696+
},
16861697
"concurrent": {
16871698
"description": "Concurrent determines whether the test should run concurrently with other tests.",
16881699
"type": [

pkg/runner/processors/test.go

+5
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,9 @@ func (p *testProcessor) Run(ctx context.Context, nspacer namespacer.Namespacer,
132132
}
133133
}
134134
})
135+
if p.test.Test.Spec.Compiler != nil {
136+
tc = tc.WithDefaultCompiler(string(*p.test.Test.Spec.Compiler))
137+
}
135138
contextData := contextData{
136139
basePath: p.test.BasePath,
137140
clusters: p.test.Test.Spec.Clusters,
@@ -147,6 +150,8 @@ func (p *testProcessor) Run(ctx context.Context, nspacer namespacer.Namespacer,
147150
if !p.skipDelete {
148151
nsCleaner = mainCleaner
149152
}
153+
// TODO this may not use the right default compiler if the template is coming from the config
154+
// but the default compiler is specified at the test level
150155
compilers := tc.Compilers()
151156
if p.nsTemplateCompiler != nil {
152157
compilers = compilers.WithDefaultCompiler(string(*p.nsTemplateCompiler))

website/docs/reference/apis/chainsaw.v1alpha1.md

+1
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,7 @@ If a resource doesn't exist yet in the cluster it will fail.</p>
901901
| `concurrent` | `bool` | | | <p>Concurrent determines whether the test should run concurrently with other tests.</p> |
902902
| `skipDelete` | `bool` | | | <p>SkipDelete determines whether the resources created by the test should be deleted after the test is executed.</p> |
903903
| `template` | `bool` | | | <p>Template determines whether resources should be considered for templating.</p> |
904+
| `compiler` | `policy/v1alpha1.Compiler` | | | <p>Compiler defines the default compiler to use when evaluating expressions.</p> |
904905
| `namespace` | `string` | | | <p>Namespace determines whether the test should run in a random ephemeral namespace or not.</p> |
905906
| `namespaceTemplate` | [`Projection`](#chainsaw-kyverno-io-v1alpha1-Projection) | | | <p>NamespaceTemplate defines a template to create the test namespace.</p> |
906907
| `namespaceTemplateCompiler` | `policy/v1alpha1.Compiler` | | | <p>NamespaceTemplateCompiler defines the default compiler to use when evaluating expressions.</p> |

0 commit comments

Comments
 (0)