Repository: kyverno/chainsaw
Pull request #116 (2023-10-20 15:01:20)

refactor: implement timeout on delete
Implement timeout on delete.

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/kyverno/chainsaw/pull/116?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kyverno) Report
> Merging [#116](https://app.codecov.io/gh/kyverno/chainsaw/pull/116?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kyverno) (dc689d3) into [main](https://app.codecov.io/gh/kyverno/chainsaw/commit/40df4ada69bb16ee2e84a0dd63fa1d8973246fb3?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kyverno) (40df4ad) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##             main     #116   +/-   ##
=======================================
  Coverage   74.81%   74.81%           
=======================================
  Files           9        9           
  Lines         409      409           
=======================================
  Hits          306      306           
  Misses         71       71           
  Partials       32       32           
```



:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=kyverno)


Patch:
diff --git a/pkg/apis/v1alpha1/delete.go b/pkg/apis/v1alpha1/delete.go
index 98770d49..2ffa7682 100644
--- a/pkg/apis/v1alpha1/delete.go
+++ b/pkg/apis/v1alpha1/delete.go
@@ -1,13 +1,21 @@
 package v1alpha1
 
-import corev1 "k8s.io/api/core/v1"
-
-// ObjectReference is a reference to an object that should be deleted
-type ObjectReference struct {
+// Delete is a reference to an object that should be deleted
+type Delete struct {
+	// API version of the referent.
+	APIVersion string `json:"apiVersion"`
+	// Kind of the referent.
+	// More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
+	Kind string `json:"kind"`
+	// Namespace of the referent.
+	// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/
+	// +optional
+	Namespace string `json:"namespace,omitempty"`
+	// Name of the referent.
+	// More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
+	// +optional
+	Name string `json:"name,omitempty"`
 	// Label selector to match objects to delete
 	// +optional
 	Labels map[string]string `json:"labels,omitempty"`
-	// Object reference to delete
-	// +optional
-	corev1.ObjectReference `json:",inline"`
 }
diff --git a/pkg/apis/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/v1alpha1/zz_generated.deepcopy.go
index 0f9364fe..63fd0876 100644
--- a/pkg/apis/v1alpha1/zz_generated.deepcopy.go
+++ b/pkg/apis/v1alpha1/zz_generated.deepcopy.go
@@ -124,58 +124,57 @@ func (in *ConfigurationSpec) DeepCopy() *ConfigurationSpec {
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *Error) DeepCopyInto(out *Error) {
+func (in *Delete) DeepCopyInto(out *Delete) {
 	*out = *in
-	out.FileRef = in.FileRef
+	if in.Labels != nil {
+		in, out := &in.Labels, &out.Labels
+		*out = make(map[string]string, len(*in))
+		for key, val := range *in {
+			(*out)[key] = val
+		}
+	}
 	return
 }
 
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Error.
-func (in *Error) DeepCopy() *Error {
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Delete.
+func (in *Delete) DeepCopy() *Delete {
 	if in == nil {
 		return nil
 	}
-	out := new(Error)
+	out := new(Delete)
 	in.DeepCopyInto(out)
 	return out
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *FileRef) DeepCopyInto(out *FileRef) {
+func (in *Error) DeepCopyInto(out *Error) {
 	*out = *in
+	out.FileRef = in.FileRef
 	return
 }
 
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FileRef.
-func (in *FileRef) DeepCopy() *FileRef {
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Error.
+func (in *Error) DeepCopy() *Error {
 	if in == nil {
 		return nil
 	}
-	out := new(FileRef)
+	out := new(Error)
 	in.DeepCopyInto(out)
 	return out
 }
 
 // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
-func (in *ObjectReference) DeepCopyInto(out *ObjectReference) {
+func (in *FileRef) DeepCopyInto(out *FileRef) {
 	*out = *in
-	if in.Labels != nil {
-		in, out := &in.Labels, &out.Labels
-		*out = make(map[string]string, len(*in))
-		for key, val := range *in {
-			(*out)[key] = val
-		}
-	}
-	out.ObjectReference = in.ObjectReference
 	return
 }
 
-// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ObjectReference.
-func (in *ObjectReference) DeepCopy() *ObjectReference {
+// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FileRef.
+func (in *FileRef) DeepCopy() *FileRef {
 	if in == nil {
 		return nil
 	}
-	out := new(ObjectReference)
+	out := new(FileRef)
 	in.DeepCopyInto(out)
 	return out
 }
@@ -277,7 +276,7 @@ func (in *TestStepSpec) DeepCopyInto(out *TestStepSpec) {
 	}
 	if in.Delete != nil {
 		in, out := &in.Delete, &out.Delete
-		*out = make([]ObjectReference, len(*in))
+		*out = make([]Delete, len(*in))
 		for i := range *in {
 			(*in)[i].DeepCopyInto(&(*out)[i])
 		}
diff --git a/pkg/client/delete.go b/pkg/client/delete.go
index f4c534f8..a6897a90 100644
--- a/pkg/client/delete.go
+++ b/pkg/client/delete.go
@@ -2,14 +2,9 @@ package client
 
 import (
 	"context"
-	"fmt"
-	"time"
 
-	"github.com/kyverno/chainsaw/pkg/apis/v1alpha1"
 	"k8s.io/apimachinery/pkg/api/errors"
 	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
-	"k8s.io/apimachinery/pkg/types"
-	"k8s.io/apimachinery/pkg/util/wait"
 	ctrlclient "sigs.k8s.io/controller-runtime/pkg/client"
 )
 
@@ -32,62 +27,4 @@ func BlockingDelete(ctx context.Context, client Client, obj ctrlclient.Object) e
 			return err
 		}
 	}
-	// TODO: context timeout
-	// return nil
-}
-
-func DeleteResource(ctx context.Context, client Client, delete *unstructured.Unstructured) error {
-	err := client.Delete(context.TODO(), delete)
-	if err != nil && !errors.IsNotFound(err) {
-		return err
-	}
-	// Wait for resources to be deleted.
-	return wait.PollUntilContextTimeout(ctx, 100*time.Millisecond, 1*time.Second, true, wait.ConditionWithContextFunc(func(ctx context.Context) (bool, error) {
-		actual := &unstructured.Unstructured{}
-		actual.SetGroupVersionKind(delete.GetObjectKind().GroupVersionKind())
-		err = client.Get(context.TODO(), types.NamespacedName{Name: delete.GetName(), Namespace: delete.GetNamespace()}, actual)
-		if err == nil || !errors.IsNotFound(err) {
-			return false, err
-		}
-		return true, nil
-	}))
-}
-
-func NewResource(apiVersion, kind, name, namespace string) *unstructured.Unstructured {
-	meta := map[string]interface{}{}
-
-	if name != "" {
-		meta["name"] = name
-	}
-	if namespace != "" {
-		meta["namespace"] = namespace
-	}
-
-	return &unstructured.Unstructured{
-		Object: map[string]interface{}{
-			"apiVersion": apiVersion,
-			"kind":       kind,
-			"metadata":   meta,
-		},
-	}
-}
-
-func ListResourcesToDelete(c Client, delete v1alpha1.ObjectReference) (*unstructured.UnstructuredList, error) {
-	u := &unstructured.UnstructuredList{}
-	u.SetGroupVersionKind(delete.GetObjectKind().GroupVersionKind())
-
-	listOptions := []ctrlclient.ListOption{}
-	if delete.Labels != nil {
-		listOptions = append(listOptions, ctrlclient.MatchingLabels(delete.Labels))
-	}
-
-	if delete.Namespace != "" {
-		listOptions = append(listOptions, ctrlclient.InNamespace(delete.Namespace))
-	}
-
-	err := c.List(context.TODO(), u, listOptions...)
-	if err != nil {
-		return nil, fmt.Errorf("listing matching resources: %v", err)
-	}
-	return u, nil
 }
diff --git a/pkg/client/key.go b/pkg/client/key.go
index cca1be24..1f308d11 100644
--- a/pkg/client/key.go
+++ b/pkg/client/key.go
@@ -22,6 +22,9 @@ func ObjectName(obj metav1.Object) string {
 
 func Name(key ctrlclient.ObjectKey) string {
 	name := key.Name
+	if name == "" {
+		name = "*"
+	}
 	if key.Namespace != "" {
 		name = key.Namespace + "/" + name
 	}
diff --git a/pkg/runner/operations/delete.go b/pkg/runner/operations/delete.go
new file mode 100644
index 00000000..64c93ed8
--- /dev/null
+++ b/pkg/runner/operations/delete.go
@@ -0,0 +1,48 @@
+package operations
+
+import (
+	"context"
+
+	"github.com/kyverno/chainsaw/pkg/client"
+	"k8s.io/apimachinery/pkg/api/errors"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
+	"k8s.io/apimachinery/pkg/util/wait"
+)
+
+func Delete(ctx context.Context, expected unstructured.Unstructured, c client.Client) error {
+	candidates, err := read(ctx, expected, c)
+	if err != nil {
+		if errors.IsNotFound(err) {
+			return nil
+		}
+		return err
+	}
+	for i := range candidates {
+		if candidates[i].GetName() != "kube-root-ca.crt" {
+			err := c.Delete(ctx, &candidates[i])
+			if err != nil && !errors.IsNotFound(err) {
+				return err
+			}
+		}
+	}
+	gvk := expected.GetObjectKind().GroupVersionKind()
+	for i := range candidates {
+		if candidates[i].GetName() != "kube-root-ca.crt" {
+			if err := wait.PollUntilContextCancel(ctx, interval, true, func(ctx context.Context) (bool, error) {
+				var actual unstructured.Unstructured
+				actual.SetGroupVersionKind(gvk)
+				err := c.Get(ctx, client.ObjectKey(&candidates[i]), &actual)
+				if err != nil {
+					if errors.IsNotFound(err) {
+						return true, nil
+					}
+					return false, err
+				}
+				return false, nil
+			}); err != nil {
+				return err
+			}
+		}
+	}
+	return nil
+}
diff --git a/pkg/runner/operations/interval.go b/pkg/runner/operations/interval.go
index 3175b1e4..a107dbb4 100644
--- a/pkg/runner/operations/interval.go
+++ b/pkg/runner/operations/interval.go
@@ -4,4 +4,4 @@ import (
 	"time"
 )
 
-const interval = 1 * time.Second
+const interval = 50 * time.Millisecond
diff --git a/pkg/runner/step.go b/pkg/runner/step.go
index 510adf63..80f89f1a 100644
--- a/pkg/runner/step.go
+++ b/pkg/runner/step.go
@@ -10,6 +10,7 @@ import (
 	"github.com/kyverno/chainsaw/pkg/resource"
 	"github.com/kyverno/chainsaw/pkg/runner/logging"
 	"github.com/kyverno/chainsaw/pkg/runner/operations"
+	"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
 )
 
 func executeStep(t *testing.T, logger logging.Logger, ctx Context, basePath string, step v1alpha1.TestStepSpec) {
@@ -21,27 +22,19 @@ func executeStep(t *testing.T, logger logging.Logger, ctx Context, basePath stri
 		defer cancel()
 		stepCtx = timeoutCtx
 	}
-	// Delete the Objects before the test step is executed
 	for _, delete := range step.Delete {
-		// Use your dynamic listing logic if the name is not provided
-		if delete.Name == "" {
-			u, err := client.ListResourcesToDelete(c, delete)
-			if err != nil {
-				t.Fatal(err)
-			}
-			for _, item := range u.Items {
-				currentItem := item
-				t.Logf("=== DELETE %s/%s", delete.APIVersion, delete.Kind)
-				if err := client.DeleteResource(stepCtx, c, &currentItem); err != nil {
-					t.Fatal(err)
-				}
-			}
-		} else {
-			resource := client.NewResource(delete.APIVersion, delete.Kind, delete.Name, delete.Namespace)
-			t.Logf("=== DELETE %s/%s", delete.APIVersion, delete.Kind)
-			if err := client.DeleteResource(stepCtx, c, resource); err != nil {
-				t.Fatal(err)
-			}
+		var resource unstructured.Unstructured
+		resource.SetAPIVersion(delete.APIVersion)
+		resource.SetKind(delete.Kind)
+		resource.SetName(delete.Name)
+		resource.SetNamespace(delete.Namespace)
+		resource.SetLabels(delete.Labels)
+		if err := ctx.namespacer.Apply(&resource); err != nil {
+			t.Fatal(err)
+		}
+		logging.ResourceOp(logger, "DELETE", client.ObjectKey(&resource), &resource)
+		if err := operations.Delete(stepCtx, resource, c); err != nil {
+			t.Fatal(err)
 		}
 	}
 	for _, apply := range step.Apply {
diff --git a/website/docs/apis/chainsaw.v1alpha1.md b/website/docs/apis/chainsaw.v1alpha1.md
index f52c6dd1..32b13f8c 100644
--- a/website/docs/apis/chainsaw.v1alpha1.md
+++ b/website/docs/apis/chainsaw.v1alpha1.md
@@ -103,6 +103,23 @@ during the testing process.</p>
 | `includeTestRegex` | `string` |  |  | <p>IncludeTestRegex is used to include tests based on a regular expression.</p> |
 | `repeatCount` | `int` |  |  | <p>RepeatCount indicates how many times the tests should be executed.</p> |
 
+## `Delete`     {#chainsaw-kyverno-io-v1alpha1-Delete}
+
+**Appears in:**
+    
+- [TestStepSpec](#chainsaw-kyverno-io-v1alpha1-TestStepSpec)
+
+<p>Delete is a reference to an object that should be deleted</p>
+
+
+| Field | Type | Required | Inline | Description |
+|---|---|---|---|---|
+| `apiVersion` | `string` | :white_check_mark: |  | <p>API version of the referent.</p> |
+| `kind` | `string` | :white_check_mark: |  | <p>Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds</p> |
+| `namespace` | `string` |  |  | <p>Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/</p> |
+| `name` | `string` |  |  | <p>Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names</p> |
+| `labels` | `map[string]string` |  |  | <p>Label selector to match objects to delete</p> |
+
 ## `Error`     {#chainsaw-kyverno-io-v1alpha1-Error}
 
 **Appears in:**
@@ -132,20 +149,6 @@ Instead of treating such an error as a test failure, it acknowledges it as expec
 |---|---|---|---|---|
 | `file` | `string` | :white_check_mark: |  | <p>File is the path to the referenced file.</p> |
 
-## `ObjectReference`     {#chainsaw-kyverno-io-v1alpha1-ObjectReference}
-
-**Appears in:**
-    
-- [TestStepSpec](#chainsaw-kyverno-io-v1alpha1-TestStepSpec)
-
-<p>ObjectReference is a reference to an object that should be deleted</p>
-
-
-| Field | Type | Required | Inline | Description |
-|---|---|---|---|---|
-| `labels` | `map[string]string` |  |  | <p>Label selector to match objects to delete</p> |
-| `ObjectReference` | [`core/v1.ObjectReference`](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#objectreference-v1-core) |  | :white_check_mark: | <p>Object reference to delete</p> |
-
 ## `ReportFormatType`     {#chainsaw-kyverno-io-v1alpha1-ReportFormatType}
 
 (Alias of `string`)
@@ -182,6 +185,6 @@ Instead of treating such an error as a test failure, it acknowledges it as expec
 | `assert` | [`[]Assert`](#chainsaw-kyverno-io-v1alpha1-Assert) |  |  | <p>Assert represents the assertions to be made for this test step. It checks whether the conditions specified in each assertion hold true.</p> |
 | `apply` | [`[]Apply`](#chainsaw-kyverno-io-v1alpha1-Apply) |  |  | <p>Apply lists the 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> |
 | `error` | [`[]Error`](#chainsaw-kyverno-io-v1alpha1-Error) |  |  | <p>Error lists the expected errors for this test step. If any of these errors occur, the test will consider them as expected; otherwise, they will be treated as test failures.</p> |
-| `delete` | [`[]ObjectReference`](#chainsaw-kyverno-io-v1alpha1-ObjectReference) |  |  | <p>Delete provides a list of objects that should be deleted before this test step is executed. This helps in ensuring that the environment is set up correctly before the test step runs.</p> |
+| `delete` | [`[]Delete`](#chainsaw-kyverno-io-v1alpha1-Delete) |  |  | <p>Delete provides a list of objects that should be deleted before this test step is executed. This helps in ensuring that the environment is set up correctly before the test step runs.</p> |
 
   
\ No newline at end of file


Test patch:
diff --git a/config/crds/chainsaw.kyverno.io_tests.yaml b/config/crds/chainsaw.kyverno.io_tests.yaml
index 54ae00bf..b68e11cd 100644
--- a/config/crds/chainsaw.kyverno.io_tests.yaml
+++ b/config/crds/chainsaw.kyverno.io_tests.yaml
@@ -77,26 +77,12 @@ spec:
                         that the environment is set up correctly before the test step
                         runs.
                       items:
-                        description: ObjectReference is a reference to an object that
-                          should be deleted
+                        description: Delete is a reference to an object that should
+                          be deleted
                         properties:
                           apiVersion:
                             description: API version of the referent.
                             type: string
-                          fieldPath:
-                            description: 'If referring to a piece of an object instead
-                              of an entire object, this string should contain a valid
-                              JSON/Go field access statement, such as desiredState.manifest.containers[2].
-                              For example, if the object reference is to a container
-                              within a pod, this would take on a value like: "spec.containers{name}"
-                              (where "name" refers to the name of the container that
-                              triggered the event) or if no container name is specified
-                              "spec.containers[2]" (container with index 2 in this
-                              pod). This syntax is chosen only to have some well-defined
-                              way of referencing a part of an object. TODO: this design
-                              is not final and this field is subject to change in
-                              the future.'
-                            type: string
                           kind:
                             description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                             type: string
@@ -111,15 +97,10 @@ spec:
                           namespace:
                             description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
                             type: string
-                          resourceVersion:
-                            description: 'Specific resourceVersion to which this reference
-                              is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
-                            type: string
-                          uid:
-                            description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
-                            type: string
+                        required:
+                        - apiVersion
+                        - kind
                         type: object
-                        x-kubernetes-map-type: atomic
                       type: array
                     error:
                       description: Error lists the expected errors for this test step.
diff --git a/config/crds/chainsaw.kyverno.io_teststeps.yaml b/config/crds/chainsaw.kyverno.io_teststeps.yaml
index 4fa086e5..0b087eeb 100644
--- a/config/crds/chainsaw.kyverno.io_teststeps.yaml
+++ b/config/crds/chainsaw.kyverno.io_teststeps.yaml
@@ -70,25 +70,11 @@ spec:
                   before this test step is executed. This helps in ensuring that the
                   environment is set up correctly before the test step runs.
                 items:
-                  description: ObjectReference is a reference to an object that should
-                    be deleted
+                  description: Delete is a reference to an object that should be deleted
                   properties:
                     apiVersion:
                       description: API version of the referent.
                       type: string
-                    fieldPath:
-                      description: 'If referring to a piece of an object instead of
-                        an entire object, this string should contain a valid JSON/Go
-                        field access statement, such as desiredState.manifest.containers[2].
-                        For example, if the object reference is to a container within
-                        a pod, this would take on a value like: "spec.containers{name}"
-                        (where "name" refers to the name of the container that triggered
-                        the event) or if no container name is specified "spec.containers[2]"
-                        (container with index 2 in this pod). This syntax is chosen
-                        only to have some well-defined way of referencing a part of
-                        an object. TODO: this design is not final and this field is
-                        subject to change in the future.'
-                      type: string
                     kind:
                       description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                       type: string
@@ -103,15 +89,10 @@ spec:
                     namespace:
                       description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
                       type: string
-                    resourceVersion:
-                      description: 'Specific resourceVersion to which this reference
-                        is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
-                      type: string
-                    uid:
-                      description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
-                      type: string
+                  required:
+                  - apiVersion
+                  - kind
                   type: object
-                  x-kubernetes-map-type: atomic
                 type: array
               error:
                 description: Error lists the expected errors for this test step. If
diff --git a/pkg/apis/v1alpha1/test_step_spec.go b/pkg/apis/v1alpha1/test_step_spec.go
index 53240eec..46a5dd39 100644
--- a/pkg/apis/v1alpha1/test_step_spec.go
+++ b/pkg/apis/v1alpha1/test_step_spec.go
@@ -20,5 +20,5 @@ type TestStepSpec struct {
 	// Delete provides a list of objects that should be deleted before this test step is executed.
 	// This helps in ensuring that the environment is set up correctly before the test step runs.
 	// +optional
-	Delete []ObjectReference `json:"delete,omitempty"`
+	Delete []Delete `json:"delete,omitempty"`
 }
diff --git a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
index 54ae00bf..b68e11cd 100644
--- a/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
+++ b/pkg/data/crds/chainsaw.kyverno.io_tests.yaml
@@ -77,26 +77,12 @@ spec:
                         that the environment is set up correctly before the test step
                         runs.
                       items:
-                        description: ObjectReference is a reference to an object that
-                          should be deleted
+                        description: Delete is a reference to an object that should
+                          be deleted
                         properties:
                           apiVersion:
                             description: API version of the referent.
                             type: string
-                          fieldPath:
-                            description: 'If referring to a piece of an object instead
-                              of an entire object, this string should contain a valid
-                              JSON/Go field access statement, such as desiredState.manifest.containers[2].
-                              For example, if the object reference is to a container
-                              within a pod, this would take on a value like: "spec.containers{name}"
-                              (where "name" refers to the name of the container that
-                              triggered the event) or if no container name is specified
-                              "spec.containers[2]" (container with index 2 in this
-                              pod). This syntax is chosen only to have some well-defined
-                              way of referencing a part of an object. TODO: this design
-                              is not final and this field is subject to change in
-                              the future.'
-                            type: string
                           kind:
                             description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                             type: string
@@ -111,15 +97,10 @@ spec:
                           namespace:
                             description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
                             type: string
-                          resourceVersion:
-                            description: 'Specific resourceVersion to which this reference
-                              is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
-                            type: string
-                          uid:
-                            description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
-                            type: string
+                        required:
+                        - apiVersion
+                        - kind
                         type: object
-                        x-kubernetes-map-type: atomic
                       type: array
                     error:
                       description: Error lists the expected errors for this test step.
diff --git a/pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml b/pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
index 4fa086e5..0b087eeb 100644
--- a/pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
+++ b/pkg/data/crds/chainsaw.kyverno.io_teststeps.yaml
@@ -70,25 +70,11 @@ spec:
                   before this test step is executed. This helps in ensuring that the
                   environment is set up correctly before the test step runs.
                 items:
-                  description: ObjectReference is a reference to an object that should
-                    be deleted
+                  description: Delete is a reference to an object that should be deleted
                   properties:
                     apiVersion:
                       description: API version of the referent.
                       type: string
-                    fieldPath:
-                      description: 'If referring to a piece of an object instead of
-                        an entire object, this string should contain a valid JSON/Go
-                        field access statement, such as desiredState.manifest.containers[2].
-                        For example, if the object reference is to a container within
-                        a pod, this would take on a value like: "spec.containers{name}"
-                        (where "name" refers to the name of the container that triggered
-                        the event) or if no container name is specified "spec.containers[2]"
-                        (container with index 2 in this pod). This syntax is chosen
-                        only to have some well-defined way of referencing a part of
-                        an object. TODO: this design is not final and this field is
-                        subject to change in the future.'
-                      type: string
                     kind:
                       description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
                       type: string
@@ -103,15 +89,10 @@ spec:
                     namespace:
                       description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
                       type: string
-                    resourceVersion:
-                      description: 'Specific resourceVersion to which this reference
-                        is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
-                      type: string
-                    uid:
-                      description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
-                      type: string
+                  required:
+                  - apiVersion
+                  - kind
                   type: object
-                  x-kubernetes-map-type: atomic
                 type: array
               error:
                 description: Error lists the expected errors for this test step. If