Skip to content

Commit df3a774

Browse files
feat: add type for string expressions (#1837) (#1838)
Signed-off-by: Charles-Edouard Brétéché <[email protected]> Co-authored-by: Charles-Edouard Brétéché <[email protected]>
1 parent 5a959cc commit df3a774

File tree

6 files changed

+34
-19
lines changed

6 files changed

+34
-19
lines changed

pkg/apis/v1alpha1/action.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ type FileRef struct {
112112
// File is the path to the referenced file. This can be a direct path to a file
113113
// or an expression that matches multiple files, such as "manifest/*.yaml" for all YAML
114114
// files within the "manifest" directory.
115-
File string `json:"file,omitempty"`
115+
File Expression `json:"file,omitempty"`
116116
}
117117

118118
// ActionResourceRef contains resource reference options for an action.
@@ -204,7 +204,7 @@ type Delete struct {
204204
// or an expression that matches multiple files, such as "manifest/*.yaml" for all YAML
205205
// files within the "manifest" directory.
206206
// +optional
207-
File string `json:"file,omitempty"`
207+
File Expression `json:"file,omitempty"`
208208

209209
// Ref determines objects to be deleted.
210210
// +optional

pkg/apis/v1alpha1/types.go

+3
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,9 @@ type Expectation struct {
5959
Check Check `json:"check"`
6060
}
6161

62+
// Expression defines an expression to be used in string fields.
63+
type Expression string
64+
6265
// Format determines the output format (json or yaml).
6366
// +kubebuilder:validation:Pattern=`^(?:json|yaml|\(.+\))$`
6467
type Format string

pkg/commands/migrate/kuttl/tests/command.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
157157
Apply: &v1alpha1.Apply{
158158
ActionResourceRef: v1alpha1.ActionResourceRef{
159159
FileRef: v1alpha1.FileRef{
160-
File: file,
160+
File: v1alpha1.Expression(file),
161161
},
162162
},
163163
},
@@ -199,7 +199,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
199199
Apply: &v1alpha1.Apply{
200200
ActionResourceRef: v1alpha1.ActionResourceRef{
201201
FileRef: v1alpha1.FileRef{
202-
File: file,
202+
File: v1alpha1.Expression(file),
203203
},
204204
},
205205
},
@@ -224,7 +224,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
224224
Assert: &v1alpha1.Assert{
225225
ActionCheckRef: v1alpha1.ActionCheckRef{
226226
FileRef: v1alpha1.FileRef{
227-
File: file,
227+
File: v1alpha1.Expression(file),
228228
},
229229
},
230230
},
@@ -260,7 +260,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
260260
Assert: &v1alpha1.Assert{
261261
ActionCheckRef: v1alpha1.ActionCheckRef{
262262
FileRef: v1alpha1.FileRef{
263-
File: file,
263+
File: v1alpha1.Expression(file),
264264
},
265265
},
266266
},
@@ -285,7 +285,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
285285
Error: &v1alpha1.Error{
286286
ActionCheckRef: v1alpha1.ActionCheckRef{
287287
FileRef: v1alpha1.FileRef{
288-
File: file,
288+
File: v1alpha1.Expression(file),
289289
},
290290
},
291291
},
@@ -321,7 +321,7 @@ func processStep(stderr io.Writer, step *v1alpha1.TestStep, s discovery.Step, fo
321321
Error: &v1alpha1.Error{
322322
ActionCheckRef: v1alpha1.ActionCheckRef{
323323
FileRef: v1alpha1.FileRef{
324-
File: file,
324+
File: v1alpha1.Expression(file),
325325
},
326326
},
327327
},
@@ -422,7 +422,7 @@ func testStep(to *v1alpha1.TestStepSpec, in unstructured.Unstructured) error {
422422
Apply: &v1alpha1.Apply{
423423
ActionResourceRef: v1alpha1.ActionResourceRef{
424424
FileRef: v1alpha1.FileRef{
425-
File: operation,
425+
File: v1alpha1.Expression(operation),
426426
},
427427
},
428428
},
@@ -433,7 +433,7 @@ func testStep(to *v1alpha1.TestStepSpec, in unstructured.Unstructured) error {
433433
Assert: &v1alpha1.Assert{
434434
ActionCheckRef: v1alpha1.ActionCheckRef{
435435
FileRef: v1alpha1.FileRef{
436-
File: operation,
436+
File: v1alpha1.Expression(operation),
437437
},
438438
},
439439
},
@@ -444,7 +444,7 @@ func testStep(to *v1alpha1.TestStepSpec, in unstructured.Unstructured) error {
444444
Error: &v1alpha1.Error{
445445
ActionCheckRef: v1alpha1.ActionCheckRef{
446446
FileRef: v1alpha1.FileRef{
447-
File: operation,
447+
File: v1alpha1.Expression(operation),
448448
},
449449
},
450450
},

pkg/discovery/load.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func LoadTest(fileName string, path string, remarshal bool) ([]Test, error) {
113113
Apply: &v1alpha1.Apply{
114114
ActionResourceRef: v1alpha1.ActionResourceRef{
115115
FileRef: v1alpha1.FileRef{
116-
File: file,
116+
File: v1alpha1.Expression(file),
117117
},
118118
},
119119
},
@@ -124,7 +124,7 @@ func LoadTest(fileName string, path string, remarshal bool) ([]Test, error) {
124124
Assert: &v1alpha1.Assert{
125125
ActionCheckRef: v1alpha1.ActionCheckRef{
126126
FileRef: v1alpha1.FileRef{
127-
File: file,
127+
File: v1alpha1.Expression(file),
128128
},
129129
},
130130
},
@@ -135,7 +135,7 @@ func LoadTest(fileName string, path string, remarshal bool) ([]Test, error) {
135135
Error: &v1alpha1.Error{
136136
ActionCheckRef: v1alpha1.ActionCheckRef{
137137
FileRef: v1alpha1.FileRef{
138-
File: file,
138+
File: v1alpha1.Expression(file),
139139
},
140140
},
141141
},

pkg/runner/processors/step.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (p *stepProcessor) finallyOperation(id int, namespacer namespacer.Namespace
376376
func (p *stepProcessor) applyOperation(id int, namespacer namespacer.Namespacer, cleaner cleaner.CleanerCollector, bindings binding.Bindings, op v1alpha1.Apply) ([]operation, error) {
377377
var operationReport *report.OperationReport
378378
if p.report != nil {
379-
operationReport = p.report.ForOperation("Apply "+op.File, report.OperationTypeApply)
379+
operationReport = p.report.ForOperation("Apply "+string(op.File), report.OperationTypeApply)
380380
}
381381
resources, err := p.fileRefOrResource(context.TODO(), op.ActionResourceRef, bindings)
382382
if err != nil {
@@ -1087,7 +1087,7 @@ func (p *stepProcessor) fileRefOrCheck(ctx context.Context, ref v1alpha1.ActionC
10871087
}
10881088
}
10891089
if ref.File != "" {
1090-
ref, err := templating.String(ctx, ref.File, bindings)
1090+
ref, err := templating.String(ctx, string(ref.File), bindings)
10911091
if err != nil {
10921092
return nil, err
10931093
}
@@ -1106,7 +1106,7 @@ func (p *stepProcessor) fileRefOrResource(ctx context.Context, ref v1alpha1.Acti
11061106
return []unstructured.Unstructured{*ref.Resource}, nil
11071107
}
11081108
if ref.File != "" {
1109-
ref, err := templating.String(ctx, ref.File, bindings)
1109+
ref, err := templating.String(ctx, string(ref.File), bindings)
11101110
if err != nil {
11111111
return nil, err
11121112
}

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

+14-2
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ If a resource already exists in the cluster it will fail.</p>
492492
| `ActionExpectations` | [`ActionExpectations`](#chainsaw-kyverno-io-v1alpha1-ActionExpectations) | :white_check_mark: | :white_check_mark: | *No description provided.* |
493493
| `ActionTimeout` | [`ActionTimeout`](#chainsaw-kyverno-io-v1alpha1-ActionTimeout) | :white_check_mark: | :white_check_mark: | *No description provided.* |
494494
| `template` | `bool` | | | <p>Template determines whether resources should be considered for templating.</p> |
495-
| `file` | `string` | | | <p>File is the path to the referenced file. This can be a direct path to a file or an expression that matches multiple files, such as "manifest/*.yaml" for all YAML files within the "manifest" directory.</p> |
495+
| `file` | [`Expression`](#chainsaw-kyverno-io-v1alpha1-Expression) | | | <p>File is the path to the referenced file. This can be a direct path to a file or an expression that matches multiple files, such as "manifest/*.yaml" for all YAML files within the "manifest" directory.</p> |
496496
| `ref` | [`ObjectReference`](#chainsaw-kyverno-io-v1alpha1-ObjectReference) | | | <p>Ref determines objects to be deleted.</p> |
497497
| `deletionPropagationPolicy` | [`meta/v1.DeletionPropagation`](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#deletionpropagation-v1-meta) | | | <p>DeletionPropagationPolicy decides if a deletion will propagate to the dependents of the object, and how the garbage collector will handle the propagation. Overrides the deletion propagation policy set in the Configuration, the Test and the TestStep.</p> |
498498

@@ -562,6 +562,18 @@ with a match filter to determine if the verification should be considered.</p>
562562
| `match` | `policy/v1alpha1.Any` | | | <p>Match defines the matching statement.</p> |
563563
| `check` | `policy/v1alpha1.Any` | :white_check_mark: | | <p>Check defines the verification statement.</p> |
564564

565+
## Expression {#chainsaw-kyverno-io-v1alpha1-Expression}
566+
567+
(Alias of `string`)
568+
569+
**Appears in:**
570+
571+
- [Delete](#chainsaw-kyverno-io-v1alpha1-Delete)
572+
- [FileRef](#chainsaw-kyverno-io-v1alpha1-FileRef)
573+
574+
<p>Expression defines an expression to be used in string fields.</p>
575+
576+
565577
## FileRef {#chainsaw-kyverno-io-v1alpha1-FileRef}
566578

567579
**Appears in:**
@@ -574,7 +586,7 @@ with a match filter to determine if the verification should be considered.</p>
574586

575587
| Field | Type | Required | Inline | Description |
576588
|---|---|---|---|---|
577-
| `file` | `string` | :white_check_mark: | | <p>File is the path to the referenced file. This can be a direct path to a file or an expression that matches multiple files, such as "manifest/*.yaml" for all YAML files within the "manifest" directory.</p> |
589+
| `file` | [`Expression`](#chainsaw-kyverno-io-v1alpha1-Expression) | :white_check_mark: | | <p>File is the path to the referenced file. This can be a direct path to a file or an expression that matches multiple files, such as "manifest/*.yaml" for all YAML files within the "manifest" directory.</p> |
578590

579591
## Format {#chainsaw-kyverno-io-v1alpha1-Format}
580592

0 commit comments

Comments
 (0)