From a3e6532a3c61b29132e5a939dd58ba24e4560aab Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Charles-Edouard=20Br=C3=A9t=C3=A9ch=C3=A9?=
Date: Fri, 24 Nov 2023 23:33:11 +0100
Subject: [PATCH] feat: add timeout support to catch and finally (#489)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Charles-Edouard Brétéché
---
.crds/chainsaw.kyverno.io_tests.yaml | 8 ++++++++
.crds/chainsaw.kyverno.io_teststeps.yaml | 8 ++++++++
.release-notes/main.md | 6 ++++--
pkg/apis/v1alpha1/catch.go | 8 ++++++++
pkg/apis/v1alpha1/finally.go | 8 ++++++++
pkg/apis/v1alpha1/zz_generated.deepcopy.go | 10 ++++++++++
pkg/data/crds/chainsaw.kyverno.io_tests.yaml | 8 ++++++++
pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml | 8 ++++++++
pkg/runner/processors/step.go | 16 ++++++++--------
website/docs/apis/chainsaw.v1alpha1.md | 2 ++
10 files changed, 72 insertions(+), 10 deletions(-)
diff --git a/.crds/chainsaw.kyverno.io_tests.yaml b/.crds/chainsaw.kyverno.io_tests.yaml
index 2c48990f1..94161aa26 100644
--- a/.crds/chainsaw.kyverno.io_tests.yaml
+++ b/.crds/chainsaw.kyverno.io_tests.yaml
@@ -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:
@@ -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:
diff --git a/.crds/chainsaw.kyverno.io_teststeps.yaml b/.crds/chainsaw.kyverno.io_teststeps.yaml
index 4d092c413..9cfb734e6 100644
--- a/.crds/chainsaw.kyverno.io_teststeps.yaml
+++ b/.crds/chainsaw.kyverno.io_teststeps.yaml
@@ -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:
@@ -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:
diff --git a/.release-notes/main.md b/.release-notes/main.md
index 0edf53fb1..546c183a4 100644
--- a/.release-notes/main.md
+++ b/.release-notes/main.md
@@ -5,8 +5,6 @@ Release notes for `TODO`.
+## :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
diff --git a/pkg/apis/v1alpha1/catch.go b/pkg/apis/v1alpha1/catch.go
index 9b597b483..c3ee6a319 100644
--- a/pkg/apis/v1alpha1/catch.go
+++ b/pkg/apis/v1alpha1/catch.go
@@ -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"`
diff --git a/pkg/apis/v1alpha1/finally.go b/pkg/apis/v1alpha1/finally.go
index 0c92f2957..353dd15b1 100644
--- a/pkg/apis/v1alpha1/finally.go
+++ b/pkg/apis/v1alpha1/finally.go
@@ -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"`
diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go
index ebc20ca0f..d5a6d808f 100644
--- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go
@@ -72,6 +72,11 @@ func (in *Assert) DeepCopy() *Assert {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Catch) DeepCopyInto(out *Catch) {
*out = *in
+ if in.Timeout != nil {
+ in, out := &in.Timeout, &out.Timeout
+ *out = new(v1.Duration)
+ **out = **in
+ }
if in.PodLogs != nil {
in, out := &in.PodLogs, &out.PodLogs
*out = new(PodLogs)
@@ -305,6 +310,11 @@ func (in *FileRefOrResource) DeepCopy() *FileRefOrResource {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *Finally) DeepCopyInto(out *Finally) {
*out = *in
+ if in.Timeout != nil {
+ in, out := &in.Timeout, &out.Timeout
+ *out = new(v1.Duration)
+ **out = **in
+ }
if in.PodLogs != nil {
in, out := &in.PodLogs, &out.PodLogs
*out = new(PodLogs)
diff --git a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
index 2c48990f1..94161aa26 100644
--- a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
+++ b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
@@ -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:
@@ -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:
diff --git a/pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml b/pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
index 4d092c413..9cfb734e6 100644
--- a/pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
+++ b/pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
@@ -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:
@@ -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:
diff --git a/pkg/runner/processors/step.go b/pkg/runner/processors/step.go
index a8bd62c7f..dc275616e 100644
--- a/pkg/runner/processors/step.go
+++ b/pkg/runner/processors/step.go
@@ -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")
}
@@ -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")
}
diff --git a/website/docs/apis/chainsaw.v1alpha1.md b/website/docs/apis/chainsaw.v1alpha1.md
index 0ef31d176..30cbeaebc 100644
--- a/website/docs/apis/chainsaw.v1alpha1.md
+++ b/website/docs/apis/chainsaw.v1alpha1.md
@@ -91,6 +91,7 @@ during the testing process.
| Field | Type | Required | Inline | Description |
|---|---|---|---|---|
+| `timeout` | [`meta/v1.Duration`](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration) | | | Timeout for the operation. Overrides the global timeout set in the Configuration.
|
| `podLogs` | [`PodLogs`](#chainsaw-kyverno-io-v1alpha1-PodLogs) | | | PodLogs determines the pod logs collector to execute.
|
| `events` | [`Events`](#chainsaw-kyverno-io-v1alpha1-Events) | | | Events determines the events collector to execute.
|
| `command` | [`Command`](#chainsaw-kyverno-io-v1alpha1-Command) | | | Command defines a command to run.
|
@@ -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) | | | Timeout for the operation. Overrides the global timeout set in the Configuration.
|
| `podLogs` | [`PodLogs`](#chainsaw-kyverno-io-v1alpha1-PodLogs) | | | PodLogs determines the pod logs collector to execute.
|
| `events` | [`Events`](#chainsaw-kyverno-io-v1alpha1-Events) | | | Events determines the events collector to execute.
|
| `command` | [`Command`](#chainsaw-kyverno-io-v1alpha1-Command) | | | Command defines a command to run.
|