Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: introduce operation base (cherry-pick #1462) #1464

Merged
merged 1 commit into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/apis/v1alpha1/operation.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package v1alpha1

// Operation defines a single operation, only one action is permitted for a given operation.
type Operation struct {
// OperationBase defines common elements to all operations.
type OperationBase struct {
// Description contains a description of the operation.
// +optional
Description string `json:"description,omitempty"`
Expand All @@ -10,6 +10,13 @@ type Operation struct {
// Even if the test continues executing, it will still be reported as failed.
// +optional
ContinueOnError *bool `json:"continueOnError,omitempty"`
}

// Operation defines a single operation, only one action is permitted for a given operation.
type Operation struct {
// OperationBase defines common elements to all operations.
// +optional
OperationBase `json:",inline"`

// Apply represents resources that should be applied for this test step. This can include things
// like configuration settings or any other resources that need to be available during the test.
Expand Down
27 changes: 22 additions & 5 deletions pkg/apis/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions pkg/commands/create/test/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,9 @@ func sampleSteps(description bool) []v1alpha1.TestStep {
TestStepSpec: v1alpha1.TestStepSpec{
Description: getDescription(description, "sample step 1"),
Try: []v1alpha1.Operation{{
Description: getDescription(description, "sample apply operation"),
OperationBase: v1alpha1.OperationBase{
Description: getDescription(description, "sample apply operation"),
},
Apply: &v1alpha1.Apply{
FileRefOrResource: v1alpha1.FileRefOrResource{
FileRef: v1alpha1.FileRef{
Expand All @@ -79,7 +81,9 @@ func sampleSteps(description bool) []v1alpha1.TestStep {
},
},
}, {
Description: getDescription(description, "sample assert operation"),
OperationBase: v1alpha1.OperationBase{
Description: getDescription(description, "sample assert operation"),
},
Assert: &v1alpha1.Assert{
FileRefOrCheck: v1alpha1.FileRefOrCheck{
FileRef: v1alpha1.FileRef{
Expand All @@ -88,7 +92,9 @@ func sampleSteps(description bool) []v1alpha1.TestStep {
},
},
}, {
Description: getDescription(description, "sample error operation"),
OperationBase: v1alpha1.OperationBase{
Description: getDescription(description, "sample error operation"),
},
Error: &v1alpha1.Error{
FileRefOrCheck: v1alpha1.FileRefOrCheck{
FileRef: v1alpha1.FileRef{
Expand All @@ -97,7 +103,9 @@ func sampleSteps(description bool) []v1alpha1.TestStep {
},
},
}, {
Description: getDescription(description, "sample delete operation"),
OperationBase: v1alpha1.OperationBase{
Description: getDescription(description, "sample delete operation"),
},
Delete: &v1alpha1.Delete{
ObjectReference: v1alpha1.ObjectReference{
ObjectSelector: v1alpha1.ObjectSelector{
Expand All @@ -110,7 +118,9 @@ func sampleSteps(description bool) []v1alpha1.TestStep {
},
},
}, {
Description: getDescription(description, "sample script operation"),
OperationBase: v1alpha1.OperationBase{
Description: getDescription(description, "sample script operation"),
},
Script: &v1alpha1.Script{
Content: `echo "test namespace = $NAMESPACE"`,
},
Expand Down
17 changes: 15 additions & 2 deletions website/docs/reference/apis/chainsaw.v1alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -563,8 +563,7 @@ For multiple objects use labels.</p>

| Field | Type | Required | Inline | Description |
|---|---|---|---|---|
| `description` | `string` | | | <p>Description contains a description of the operation.</p> |
| `continueOnError` | `bool` | | | <p>ContinueOnError determines whether a test should continue or not in case the operation was not successful. Even if the test continues executing, it will still be reported as failed.</p> |
| `OperationBase` | [`OperationBase`](#chainsaw-kyverno-io-v1alpha1-OperationBase) | | :white_check_mark: | <p>OperationBase defines common elements to all operations.</p> |
| `apply` | [`Apply`](#chainsaw-kyverno-io-v1alpha1-Apply) | | | <p>Apply represents resources that should be applied for this test step. This can include things like configuration settings or any other resources that need to be available during the test.</p> |
| `assert` | [`Assert`](#chainsaw-kyverno-io-v1alpha1-Assert) | | | <p>Assert represents an assertion to be made. It checks whether the conditions specified in the assertion hold true.</p> |
| `command` | [`Command`](#chainsaw-kyverno-io-v1alpha1-Command) | | | <p>Command defines a command to run.</p> |
Expand All @@ -577,6 +576,20 @@ For multiple objects use labels.</p>
| `update` | [`Update`](#chainsaw-kyverno-io-v1alpha1-Update) | | | <p>Update represents an update operation.</p> |
| `wait` | [`Wait`](#chainsaw-kyverno-io-v1alpha1-Wait) | | | <p>Wait determines the resource wait collector to execute.</p> |

## `OperationBase` {#chainsaw-kyverno-io-v1alpha1-OperationBase}

**Appears in:**

- [Operation](#chainsaw-kyverno-io-v1alpha1-Operation)

<p>OperationBase defines common elements to all operations.</p>


| Field | Type | Required | Inline | Description |
|---|---|---|---|---|
| `description` | `string` | | | <p>Description contains a description of the operation.</p> |
| `continueOnError` | `bool` | | | <p>ContinueOnError determines whether a test should continue or not in case the operation was not successful. Even if the test continues executing, it will still be reported as failed.</p> |

## `Output` {#chainsaw-kyverno-io-v1alpha1-Output}

**Appears in:**
Expand Down
Loading