Skip to content

Commit

Permalink
feat: add timeout support to catch and finally (#489)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Nov 24, 2023
1 parent afaafd2 commit a3e6532
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 10 deletions.
8 changes: 8 additions & 0 deletions .crds/chainsaw.kyverno.io_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ spec:
noise.
type: boolean
type: object
timeout:
description: Timeout for the operation. Overrides the
global timeout set in the Configuration.
type: string
type: object
type: array
finally:
Expand Down Expand Up @@ -238,6 +242,10 @@ spec:
noise.
type: boolean
type: object
timeout:
description: Timeout for the operation. Overrides the
global timeout set in the Configuration.
type: string
type: object
type: array
name:
Expand Down
8 changes: 8 additions & 0 deletions .crds/chainsaw.kyverno.io_teststeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ spec:
Useful for sensitive logs or to reduce noise.
type: boolean
type: object
timeout:
description: Timeout for the operation. Overrides the global
timeout set in the Configuration.
type: string
type: object
type: array
finally:
Expand Down Expand Up @@ -198,6 +202,10 @@ spec:
Useful for sensitive logs or to reduce noise.
type: boolean
type: object
timeout:
description: Timeout for the operation. Overrides the global
timeout set in the Configuration.
type: string
type: object
type: array
skipDelete:
Expand Down
6 changes: 4 additions & 2 deletions .release-notes/main.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ Release notes for `TODO`.
<!--
## :bangbang: Breaking chages :bangbang:
## :dizzy: New features :dizzy:
## :sparkles: UI changes :sparkles:
## :star: Examples :star:
Expand All @@ -20,6 +18,10 @@ Release notes for `TODO`.
## :guitar: Misc :guitar:
-->

## :dizzy: New features :dizzy:

- Added timeout support in `try` and `catch` handlers

## :wrench: Fixes :wrench:

- Fixed a kuttl migration failure in case of unsupported file name
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/v1alpha1/catch.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Catch defines actions to be executed on failure.
type Catch struct {
// Timeout for the operation. Overrides the global timeout set in the Configuration.
// +optional
Timeout *metav1.Duration `json:"timeout,omitempty"`

// PodLogs determines the pod logs collector to execute.
// +optional
PodLogs *PodLogs `json:"podLogs,omitempty"`
Expand Down
8 changes: 8 additions & 0 deletions pkg/apis/v1alpha1/finally.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// Finally defines actions to be executed at the end of a test.
type Finally struct {
// Timeout for the operation. Overrides the global timeout set in the Configuration.
// +optional
Timeout *metav1.Duration `json:"timeout,omitempty"`

// PodLogs determines the pod logs collector to execute.
// +optional
PodLogs *PodLogs `json:"podLogs,omitempty"`
Expand Down
10 changes: 10 additions & 0 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.

8 changes: 8 additions & 0 deletions pkg/data/crds/chainsaw.kyverno.io_tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ spec:
noise.
type: boolean
type: object
timeout:
description: Timeout for the operation. Overrides the
global timeout set in the Configuration.
type: string
type: object
type: array
finally:
Expand Down Expand Up @@ -238,6 +242,10 @@ spec:
noise.
type: boolean
type: object
timeout:
description: Timeout for the operation. Overrides the
global timeout set in the Configuration.
type: string
type: object
type: array
name:
Expand Down
8 changes: 8 additions & 0 deletions pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ spec:
Useful for sensitive logs or to reduce noise.
type: boolean
type: object
timeout:
description: Timeout for the operation. Overrides the global
timeout set in the Configuration.
type: string
type: object
type: array
finally:
Expand Down Expand Up @@ -198,6 +202,10 @@ spec:
Useful for sensitive logs or to reduce noise.
type: boolean
type: object
timeout:
description: Timeout for the operation. Overrides the global
timeout set in the Configuration.
type: string
type: object
type: array
skipDelete:
Expand Down
16 changes: 8 additions & 8 deletions pkg/runner/processors/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,17 +184,17 @@ func (p *stepProcessor) catchOperations(ctx context.Context, handlers ...v1alpha
if err != nil {
return nil, err
}
register(p.commandOperation(ctx, *cmd, nil))
register(p.commandOperation(ctx, *cmd, handler.Timeout))
} else if handler.Events != nil {
cmd, err := collect.Events(handler.Events)
if err != nil {
return nil, err
}
register(p.commandOperation(ctx, *cmd, nil))
register(p.commandOperation(ctx, *cmd, handler.Timeout))
} else if handler.Command != nil {
register(p.commandOperation(ctx, *handler.Command, nil))
register(p.commandOperation(ctx, *handler.Command, handler.Timeout))
} else if handler.Script != nil {
register(p.scriptOperation(ctx, *handler.Script, nil))
register(p.scriptOperation(ctx, *handler.Script, handler.Timeout))
} else {
return nil, errors.New("no operation found")
}
Expand All @@ -216,17 +216,17 @@ func (p *stepProcessor) finallyOperations(ctx context.Context, handlers ...v1alp
if err != nil {
return nil, err
}
register(p.commandOperation(ctx, *cmd, nil))
register(p.commandOperation(ctx, *cmd, handler.Timeout))
} else if handler.Events != nil {
cmd, err := collect.Events(handler.Events)
if err != nil {
return nil, err
}
register(p.commandOperation(ctx, *cmd, nil))
register(p.commandOperation(ctx, *cmd, handler.Timeout))
} else if handler.Command != nil {
register(p.commandOperation(ctx, *handler.Command, nil))
register(p.commandOperation(ctx, *handler.Command, handler.Timeout))
} else if handler.Script != nil {
register(p.scriptOperation(ctx, *handler.Script, nil))
register(p.scriptOperation(ctx, *handler.Script, handler.Timeout))
} else {
return nil, errors.New("no operation found")
}
Expand Down
2 changes: 2 additions & 0 deletions website/docs/apis/chainsaw.v1alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ during the testing process.</p>

| Field | Type | Required | Inline | Description |
|---|---|---|---|---|
| `timeout` | [`meta/v1.Duration`](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration) | | | <p>Timeout for the operation. Overrides the global timeout set in the Configuration.</p> |
| `podLogs` | [`PodLogs`](#chainsaw-kyverno-io-v1alpha1-PodLogs) | | | <p>PodLogs determines the pod logs collector to execute.</p> |
| `events` | [`Events`](#chainsaw-kyverno-io-v1alpha1-Events) | | | <p>Events determines the events collector to execute.</p> |
| `command` | [`Command`](#chainsaw-kyverno-io-v1alpha1-Command) | | | <p>Command defines a command to run.</p> |
Expand Down Expand Up @@ -239,6 +240,7 @@ Instead of treating such an error as a test failure, it acknowledges it as expec

| Field | Type | Required | Inline | Description |
|---|---|---|---|---|
| `timeout` | [`meta/v1.Duration`](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration) | | | <p>Timeout for the operation. Overrides the global timeout set in the Configuration.</p> |
| `podLogs` | [`PodLogs`](#chainsaw-kyverno-io-v1alpha1-PodLogs) | | | <p>PodLogs determines the pod logs collector to execute.</p> |
| `events` | [`Events`](#chainsaw-kyverno-io-v1alpha1-Events) | | | <p>Events determines the events collector to execute.</p> |
| `command` | [`Command`](#chainsaw-kyverno-io-v1alpha1-Command) | | | <p>Command defines a command to run.</p> |
Expand Down

0 comments on commit a3e6532

Please sign in to comment.