diff --git a/.crds/chainsaw.kyverno.io_tests.yaml b/.crds/chainsaw.kyverno.io_tests.yaml index a4dbe727a..2fccf1f24 100644 --- a/.crds/chainsaw.kyverno.io_tests.yaml +++ b/.crds/chainsaw.kyverno.io_tests.yaml @@ -4625,6 +4625,29 @@ spec: template: description: Template references a step template. type: string + with: + default: {} + description: With defines arguments passed to the step template. + properties: + bindings: + description: Bindings defines additional binding key/values. + items: + description: Binding represents a key/value set as + a binding in an executing test. + properties: + name: + description: Name the name of the binding. + pattern: ^(?:\w+|\(.+\))$ + type: string + value: + description: Value value of the binding. + x-kubernetes-preserve-unknown-fields: true + required: + - name + - value + type: object + type: array + type: object required: - template type: object diff --git a/.schemas/json/test-chainsaw-v1alpha1.json b/.schemas/json/test-chainsaw-v1alpha1.json index a7b2dc182..258912dc4 100644 --- a/.schemas/json/test-chainsaw-v1alpha1.json +++ b/.schemas/json/test-chainsaw-v1alpha1.json @@ -9192,6 +9192,47 @@ "template": { "description": "Template references a step template.", "type": "string" + }, + "with": { + "description": "With defines arguments passed to the step template.", + "type": [ + "object", + "null" + ], + "default": {}, + "properties": { + "bindings": { + "description": "Bindings defines additional binding key/values.", + "type": [ + "array", + "null" + ], + "items": { + "description": "Binding represents a key/value set as a binding in an executing test.", + "type": [ + "object", + "null" + ], + "required": [ + "name", + "value" + ], + "properties": { + "name": { + "description": "Name the name of the binding.", + "type": "string", + "pattern": "^(?:\\w+|\\(.+\\))$" + }, + "value": { + "description": "Value value of the binding.", + "x-kubernetes-preserve-unknown-fields": true + } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false } }, "additionalProperties": false diff --git a/pkg/apis/v1alpha1/step.go b/pkg/apis/v1alpha1/step.go index 00918c0a1..6be982132 100644 --- a/pkg/apis/v1alpha1/step.go +++ b/pkg/apis/v1alpha1/step.go @@ -63,6 +63,18 @@ type TestStep struct { type Use struct { // Template references a step template. Template string `json:"template"` + + // With defines arguments passed to the step template. + // +optional + // +kubebuilder:default:={} + With With `json:"with"` +} + +// With defines arguments passed to step templates. +type With struct { + // Bindings defines additional binding key/values. + // +optional + Bindings []Binding `json:"bindings,omitempty"` } // TestStepSpec defines the desired state and behavior for each test step. diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go index 8c4b2b007..389808182 100644 --- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go @@ -1352,7 +1352,7 @@ func (in *TestStep) DeepCopyInto(out *TestStep) { if in.Use != nil { in, out := &in.Use, &out.Use *out = new(Use) - **out = **in + (*in).DeepCopyInto(*out) } in.TestStepSpec.DeepCopyInto(&out.TestStepSpec) return @@ -1523,6 +1523,7 @@ func (in *Update) DeepCopy() *Update { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Use) DeepCopyInto(out *Use) { *out = *in + in.With.DeepCopyInto(&out.With) return } @@ -1645,3 +1646,26 @@ func (in *WaitForJsonPath) DeepCopy() *WaitForJsonPath { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *With) DeepCopyInto(out *With) { + *out = *in + if in.Bindings != nil { + in, out := &in.Bindings, &out.Bindings + *out = make([]Binding, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new With. +func (in *With) DeepCopy() *With { + if in == nil { + return nil + } + out := new(With) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml index a4dbe727a..2fccf1f24 100644 --- a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml +++ b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml @@ -4625,6 +4625,29 @@ spec: template: description: Template references a step template. type: string + with: + default: {} + description: With defines arguments passed to the step template. + properties: + bindings: + description: Bindings defines additional binding key/values. + items: + description: Binding represents a key/value set as + a binding in an executing test. + properties: + name: + description: Name the name of the binding. + pattern: ^(?:\w+|\(.+\))$ + type: string + value: + description: Value value of the binding. + x-kubernetes-preserve-unknown-fields: true + required: + - name + - value + type: object + type: array + type: object required: - template type: object diff --git a/pkg/data/schemas/json/test-chainsaw-v1alpha1.json b/pkg/data/schemas/json/test-chainsaw-v1alpha1.json index a7b2dc182..258912dc4 100644 --- a/pkg/data/schemas/json/test-chainsaw-v1alpha1.json +++ b/pkg/data/schemas/json/test-chainsaw-v1alpha1.json @@ -9192,6 +9192,47 @@ "template": { "description": "Template references a step template.", "type": "string" + }, + "with": { + "description": "With defines arguments passed to the step template.", + "type": [ + "object", + "null" + ], + "default": {}, + "properties": { + "bindings": { + "description": "Bindings defines additional binding key/values.", + "type": [ + "array", + "null" + ], + "items": { + "description": "Binding represents a key/value set as a binding in an executing test.", + "type": [ + "object", + "null" + ], + "required": [ + "name", + "value" + ], + "properties": { + "name": { + "description": "Name the name of the binding.", + "type": "string", + "pattern": "^(?:\\w+|\\(.+\\))$" + }, + "value": { + "description": "Value value of the binding.", + "x-kubernetes-preserve-unknown-fields": true + } + }, + "additionalProperties": false + } + } + }, + "additionalProperties": false } }, "additionalProperties": false diff --git a/pkg/discovery/load.go b/pkg/discovery/load.go index 876f3fa43..7fc3bfdfb 100644 --- a/pkg/discovery/load.go +++ b/pkg/discovery/load.go @@ -66,12 +66,14 @@ func LoadTest(fileName string, path string, remarshal bool) ([]Test, error) { if len(steptpl) != 1 { return nil, errors.New("step template not found or multiple templates exist") } + template := steptpl[0] + step.Bindings = append(step.Bindings, step.Use.With.Bindings...) + step.Bindings = append(step.Bindings, template.Spec.Bindings...) + step.Try = append(step.Try, template.Spec.Try...) + step.Catch = append(step.Catch, template.Spec.Catch...) + step.Finally = append(step.Finally, template.Spec.Finally...) + step.Cleanup = append(step.Cleanup, template.Spec.Cleanup...) step.Use = nil - step.Bindings = append(step.Bindings, steptpl[0].Spec.Bindings...) - step.Try = append(step.Try, steptpl[0].Spec.Try...) - step.Catch = append(step.Catch, steptpl[0].Spec.Catch...) - step.Finally = append(step.Finally, steptpl[0].Spec.Finally...) - step.Cleanup = append(step.Cleanup, steptpl[0].Spec.Cleanup...) } } } diff --git a/testdata/e2e/examples/step-template/README.md b/testdata/e2e/examples/step-template/README.md index 388ff0b90..a0804a960 100644 --- a/testdata/e2e/examples/step-template/README.md +++ b/testdata/e2e/examples/step-template/README.md @@ -6,12 +6,18 @@ | # | Name | Bindings | Try | Catch | Finally | Cleanup | |:-:|---|:-:|:-:|:-:|:-:| -| 1 | [step-1](#step-step-1) | 0 | 2 | 0 | 0 | 0 | +| 1 | [step-1](#step-step-1) | 1 | 2 | 0 | 0 | 0 | ### Step: `step-1` *No description* +#### Bindings + +| # | Name | Value | +|:-:|---|---| +| 1 | `file` | "configmap.yaml" | + #### Try | # | Operation | Bindings | Outputs | Description | diff --git a/testdata/e2e/examples/step-template/chainsaw-test.yaml b/testdata/e2e/examples/step-template/chainsaw-test.yaml index 3121eb2b3..12bb5a058 100644 --- a/testdata/e2e/examples/step-template/chainsaw-test.yaml +++ b/testdata/e2e/examples/step-template/chainsaw-test.yaml @@ -7,3 +7,7 @@ spec: steps: - use: template: step-template.yaml + with: + bindings: + - name: file + value: configmap.yaml diff --git a/testdata/e2e/examples/step-template/step-template.yaml b/testdata/e2e/examples/step-template/step-template.yaml index f18be9370..2aa1f417d 100644 --- a/testdata/e2e/examples/step-template/step-template.yaml +++ b/testdata/e2e/examples/step-template/step-template.yaml @@ -8,8 +8,8 @@ spec: # first operation: create the config map - apply: # file is relative to the test folder - file: configmap.yaml + file: ($file) # second operation: verify the config map exists and contains the expected data - assert: # file is relative to the test folder - file: configmap.yaml + file: ($file) diff --git a/website/docs/reference/apis/chainsaw.v1alpha1.md b/website/docs/reference/apis/chainsaw.v1alpha1.md index 18cad9354..ad7b934af 100644 --- a/website/docs/reference/apis/chainsaw.v1alpha1.md +++ b/website/docs/reference/apis/chainsaw.v1alpha1.md @@ -336,6 +336,7 @@ during the testing process.

- [StepTemplateSpec](#chainsaw-kyverno-io-v1alpha1-StepTemplateSpec) - [TestSpec](#chainsaw-kyverno-io-v1alpha1-TestSpec) - [TestStepSpec](#chainsaw-kyverno-io-v1alpha1-TestStepSpec) +- [With](#chainsaw-kyverno-io-v1alpha1-With)

Binding represents a key/value set as a binding in an executing test.

@@ -982,6 +983,7 @@ If a resource does not exist in the cluster it will fail.

| Field | Type | Required | Inline | Description | |---|---|---|---|---| | `template` | `string` | :white_check_mark: | |

Template references a step template.

| +| `with` | [`With`](#chainsaw-kyverno-io-v1alpha1-With) | | |

With defines arguments passed to the step template.

| ## Wait {#chainsaw-kyverno-io-v1alpha1-Wait} @@ -1053,4 +1055,17 @@ If a resource does not exist in the cluster it will fail.

| `path` | [`Expression`](#chainsaw-kyverno-io-v1alpha1-Expression) | :white_check_mark: | |

Path defines the json path to wait for, e.g. '{.status.phase}'.

| | `value` | [`Expression`](#chainsaw-kyverno-io-v1alpha1-Expression) | | |

Value defines the expected value to wait for, e.g., "Running".

| +## With {#chainsaw-kyverno-io-v1alpha1-With} + +**Appears in:** + +- [Use](#chainsaw-kyverno-io-v1alpha1-Use) + +

With defines arguments passed to step templates.

+ + +| Field | Type | Required | Inline | Description | +|---|---|---|---|---| +| `bindings` | [`[]Binding`](#chainsaw-kyverno-io-v1alpha1-Binding) | | |

Bindings defines additional binding key/values.

| + \ No newline at end of file