Skip to content

Commit c6440e1

Browse files
feat: add bindings support to step templates (#1985) (#1993)
* feat: add bindings support to step templates * fix comment --------- Signed-off-by: Charles-Edouard Brétéché <[email protected]> Co-authored-by: Charles-Edouard Brétéché <[email protected]>
1 parent 41029f5 commit c6440e1

File tree

11 files changed

+200
-9
lines changed

11 files changed

+200
-9
lines changed

.crds/chainsaw.kyverno.io_tests.yaml

+23
Original file line numberDiff line numberDiff line change
@@ -4625,6 +4625,29 @@ spec:
46254625
template:
46264626
description: Template references a step template.
46274627
type: string
4628+
with:
4629+
default: {}
4630+
description: With defines arguments passed to the step template.
4631+
properties:
4632+
bindings:
4633+
description: Bindings defines additional binding key/values.
4634+
items:
4635+
description: Binding represents a key/value set as
4636+
a binding in an executing test.
4637+
properties:
4638+
name:
4639+
description: Name the name of the binding.
4640+
pattern: ^(?:\w+|\(.+\))$
4641+
type: string
4642+
value:
4643+
description: Value value of the binding.
4644+
x-kubernetes-preserve-unknown-fields: true
4645+
required:
4646+
- name
4647+
- value
4648+
type: object
4649+
type: array
4650+
type: object
46284651
required:
46294652
- template
46304653
type: object

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

+41
Original file line numberDiff line numberDiff line change
@@ -9192,6 +9192,47 @@
91929192
"template": {
91939193
"description": "Template references a step template.",
91949194
"type": "string"
9195+
},
9196+
"with": {
9197+
"description": "With defines arguments passed to the step template.",
9198+
"type": [
9199+
"object",
9200+
"null"
9201+
],
9202+
"default": {},
9203+
"properties": {
9204+
"bindings": {
9205+
"description": "Bindings defines additional binding key/values.",
9206+
"type": [
9207+
"array",
9208+
"null"
9209+
],
9210+
"items": {
9211+
"description": "Binding represents a key/value set as a binding in an executing test.",
9212+
"type": [
9213+
"object",
9214+
"null"
9215+
],
9216+
"required": [
9217+
"name",
9218+
"value"
9219+
],
9220+
"properties": {
9221+
"name": {
9222+
"description": "Name the name of the binding.",
9223+
"type": "string",
9224+
"pattern": "^(?:\\w+|\\(.+\\))$"
9225+
},
9226+
"value": {
9227+
"description": "Value value of the binding.",
9228+
"x-kubernetes-preserve-unknown-fields": true
9229+
}
9230+
},
9231+
"additionalProperties": false
9232+
}
9233+
}
9234+
},
9235+
"additionalProperties": false
91959236
}
91969237
},
91979238
"additionalProperties": false

pkg/apis/v1alpha1/step.go

+12
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,18 @@ type TestStep struct {
6363
type Use struct {
6464
// Template references a step template.
6565
Template string `json:"template"`
66+
67+
// With defines arguments passed to the step template.
68+
// +optional
69+
// +kubebuilder:default:={}
70+
With With `json:"with"`
71+
}
72+
73+
// With defines arguments passed to step templates.
74+
type With struct {
75+
// Bindings defines additional binding key/values.
76+
// +optional
77+
Bindings []Binding `json:"bindings,omitempty"`
6678
}
6779

6880
// TestStepSpec defines the desired state and behavior for each test step.

pkg/apis/v1alpha1/zz_generated.deepcopy.go

+25-1
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

+23
Original file line numberDiff line numberDiff line change
@@ -4625,6 +4625,29 @@ spec:
46254625
template:
46264626
description: Template references a step template.
46274627
type: string
4628+
with:
4629+
default: {}
4630+
description: With defines arguments passed to the step template.
4631+
properties:
4632+
bindings:
4633+
description: Bindings defines additional binding key/values.
4634+
items:
4635+
description: Binding represents a key/value set as
4636+
a binding in an executing test.
4637+
properties:
4638+
name:
4639+
description: Name the name of the binding.
4640+
pattern: ^(?:\w+|\(.+\))$
4641+
type: string
4642+
value:
4643+
description: Value value of the binding.
4644+
x-kubernetes-preserve-unknown-fields: true
4645+
required:
4646+
- name
4647+
- value
4648+
type: object
4649+
type: array
4650+
type: object
46284651
required:
46294652
- template
46304653
type: object

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

+41
Original file line numberDiff line numberDiff line change
@@ -9192,6 +9192,47 @@
91929192
"template": {
91939193
"description": "Template references a step template.",
91949194
"type": "string"
9195+
},
9196+
"with": {
9197+
"description": "With defines arguments passed to the step template.",
9198+
"type": [
9199+
"object",
9200+
"null"
9201+
],
9202+
"default": {},
9203+
"properties": {
9204+
"bindings": {
9205+
"description": "Bindings defines additional binding key/values.",
9206+
"type": [
9207+
"array",
9208+
"null"
9209+
],
9210+
"items": {
9211+
"description": "Binding represents a key/value set as a binding in an executing test.",
9212+
"type": [
9213+
"object",
9214+
"null"
9215+
],
9216+
"required": [
9217+
"name",
9218+
"value"
9219+
],
9220+
"properties": {
9221+
"name": {
9222+
"description": "Name the name of the binding.",
9223+
"type": "string",
9224+
"pattern": "^(?:\\w+|\\(.+\\))$"
9225+
},
9226+
"value": {
9227+
"description": "Value value of the binding.",
9228+
"x-kubernetes-preserve-unknown-fields": true
9229+
}
9230+
},
9231+
"additionalProperties": false
9232+
}
9233+
}
9234+
},
9235+
"additionalProperties": false
91959236
}
91969237
},
91979238
"additionalProperties": false

pkg/discovery/load.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,14 @@ func LoadTest(fileName string, path string, remarshal bool) ([]Test, error) {
6666
if len(steptpl) != 1 {
6767
return nil, errors.New("step template not found or multiple templates exist")
6868
}
69+
template := steptpl[0]
70+
step.Bindings = append(step.Bindings, step.Use.With.Bindings...)
71+
step.Bindings = append(step.Bindings, template.Spec.Bindings...)
72+
step.Try = append(step.Try, template.Spec.Try...)
73+
step.Catch = append(step.Catch, template.Spec.Catch...)
74+
step.Finally = append(step.Finally, template.Spec.Finally...)
75+
step.Cleanup = append(step.Cleanup, template.Spec.Cleanup...)
6976
step.Use = nil
70-
step.Bindings = append(step.Bindings, steptpl[0].Spec.Bindings...)
71-
step.Try = append(step.Try, steptpl[0].Spec.Try...)
72-
step.Catch = append(step.Catch, steptpl[0].Spec.Catch...)
73-
step.Finally = append(step.Finally, steptpl[0].Spec.Finally...)
74-
step.Cleanup = append(step.Cleanup, steptpl[0].Spec.Cleanup...)
7577
}
7678
}
7779
}

testdata/e2e/examples/step-template/README.md

+7-1
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66

77
| # | Name | Bindings | Try | Catch | Finally | Cleanup |
88
|:-:|---|:-:|:-:|:-:|:-:|
9-
| 1 | [step-1](#step-step-1) | 0 | 2 | 0 | 0 | 0 |
9+
| 1 | [step-1](#step-step-1) | 1 | 2 | 0 | 0 | 0 |
1010

1111
### Step: `step-1`
1212

1313
*No description*
1414

15+
#### Bindings
16+
17+
| # | Name | Value |
18+
|:-:|---|---|
19+
| 1 | `file` | "configmap.yaml" |
20+
1521
#### Try
1622

1723
| # | Operation | Bindings | Outputs | Description |

testdata/e2e/examples/step-template/chainsaw-test.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ spec:
77
steps:
88
- use:
99
template: step-template.yaml
10+
with:
11+
bindings:
12+
- name: file
13+
value: configmap.yaml

testdata/e2e/examples/step-template/step-template.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ spec:
88
# first operation: create the config map
99
- apply:
1010
# file is relative to the test folder
11-
file: configmap.yaml
11+
file: ($file)
1212
# second operation: verify the config map exists and contains the expected data
1313
- assert:
1414
# file is relative to the test folder
15-
file: configmap.yaml
15+
file: ($file)

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

+15
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,7 @@ during the testing process.</p>
336336
- [StepTemplateSpec](#chainsaw-kyverno-io-v1alpha1-StepTemplateSpec)
337337
- [TestSpec](#chainsaw-kyverno-io-v1alpha1-TestSpec)
338338
- [TestStepSpec](#chainsaw-kyverno-io-v1alpha1-TestStepSpec)
339+
- [With](#chainsaw-kyverno-io-v1alpha1-With)
339340

340341
<p>Binding represents a key/value set as a binding in an executing test.</p>
341342

@@ -982,6 +983,7 @@ If a resource does not exist in the cluster it will fail.</p>
982983
| Field | Type | Required | Inline | Description |
983984
|---|---|---|---|---|
984985
| `template` | `string` | :white_check_mark: | | <p>Template references a step template.</p> |
986+
| `with` | [`With`](#chainsaw-kyverno-io-v1alpha1-With) | | | <p>With defines arguments passed to the step template.</p> |
985987

986988
## Wait {#chainsaw-kyverno-io-v1alpha1-Wait}
987989

@@ -1053,4 +1055,17 @@ If a resource does not exist in the cluster it will fail.</p>
10531055
| `path` | [`Expression`](#chainsaw-kyverno-io-v1alpha1-Expression) | :white_check_mark: | | <p>Path defines the json path to wait for, e.g. '{.status.phase}'.</p> |
10541056
| `value` | [`Expression`](#chainsaw-kyverno-io-v1alpha1-Expression) | | | <p>Value defines the expected value to wait for, e.g., "Running".</p> |
10551057

1058+
## With {#chainsaw-kyverno-io-v1alpha1-With}
1059+
1060+
**Appears in:**
1061+
1062+
- [Use](#chainsaw-kyverno-io-v1alpha1-Use)
1063+
1064+
<p>With defines arguments passed to step templates.</p>
1065+
1066+
1067+
| Field | Type | Required | Inline | Description |
1068+
|---|---|---|---|---|
1069+
| `bindings` | [`[]Binding`](#chainsaw-kyverno-io-v1alpha1-Binding) | | | <p>Bindings defines additional binding key/values.</p> |
1070+
10561071

0 commit comments

Comments
 (0)