diff --git a/pkg/background/generate/cleanup.go b/pkg/background/generate/cleanup.go index 489806c761..10bf58d0fc 100644 --- a/pkg/background/generate/cleanup.go +++ b/pkg/background/generate/cleanup.go @@ -11,6 +11,7 @@ import ( kubeutils "github.com/kyverno/kyverno/pkg/utils/kube" "go.uber.org/multierr" apierrors "k8s.io/apimachinery/pkg/api/errors" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" ) @@ -21,7 +22,7 @@ func (c *GenerateController) deleteDownstream(policy kyvernov1.PolicyInterface, var errs []error failedDownstreams := []kyvernov1.ResourceSpec{} for _, e := range ur.Status.GeneratedResources { - if err := c.client.DeleteResource(context.TODO(), e.GetAPIVersion(), e.GetKind(), e.GetNamespace(), e.GetName(), false); err != nil && !apierrors.IsNotFound(err) { + if err := c.client.DeleteResource(context.TODO(), e.GetAPIVersion(), e.GetKind(), e.GetNamespace(), e.GetName(), false, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { failedDownstreams = append(failedDownstreams, e) errs = append(errs, err) } @@ -73,7 +74,7 @@ func (c *GenerateController) handleNonPolicyChanges(policy kyvernov1.PolicyInter failedDownstreams := []kyvernov1.ResourceSpec{} for _, downstream := range downstreams { spec := common.ResourceSpecFromUnstructured(downstream) - if err := c.client.DeleteResource(context.TODO(), downstream.GetAPIVersion(), downstream.GetKind(), downstream.GetNamespace(), downstream.GetName(), false); err != nil && !apierrors.IsNotFound(err) { + if err := c.client.DeleteResource(context.TODO(), downstream.GetAPIVersion(), downstream.GetKind(), downstream.GetNamespace(), downstream.GetName(), false, metav1.DeleteOptions{}); err != nil && !apierrors.IsNotFound(err) { failedDownstreams = append(failedDownstreams, spec) errs = append(errs, err) } else { diff --git a/pkg/clients/dclient/client.go b/pkg/clients/dclient/client.go index 818bb8000d..f823db91ef 100644 --- a/pkg/clients/dclient/client.go +++ b/pkg/clients/dclient/client.go @@ -41,7 +41,7 @@ type Interface interface { // Access items using []Items ListResource(ctx context.Context, apiVersion string, kind string, namespace string, lselector *metav1.LabelSelector) (*unstructured.UnstructuredList, error) // DeleteResource deletes the specified resource - DeleteResource(ctx context.Context, apiVersion string, kind string, namespace string, name string, dryRun bool) error + DeleteResource(ctx context.Context, apiVersion string, kind string, namespace string, name string, dryRun bool, options metav1.DeleteOptions) error // CreateResource creates object for the specified resource/namespace CreateResource(ctx context.Context, apiVersion string, kind string, namespace string, obj interface{}, dryRun bool) (*unstructured.Unstructured, error) // UpdateResource updates object for the specified resource/namespace @@ -183,8 +183,7 @@ func (c *client) ListResource(ctx context.Context, apiVersion string, kind strin } // DeleteResource deletes the specified resource -func (c *client) DeleteResource(ctx context.Context, apiVersion string, kind string, namespace string, name string, dryRun bool) error { - options := metav1.DeleteOptions{} +func (c *client) DeleteResource(ctx context.Context, apiVersion string, kind string, namespace string, name string, dryRun bool, options metav1.DeleteOptions) error { if dryRun { options = metav1.DeleteOptions{DryRun: []string{metav1.DryRunAll}} } diff --git a/pkg/clients/dclient/client_test.go b/pkg/clients/dclient/client_test.go index e988cfc734..9e320e8d25 100644 --- a/pkg/clients/dclient/client_test.go +++ b/pkg/clients/dclient/client_test.go @@ -103,7 +103,7 @@ func TestCRUDResource(t *testing.T) { t.Errorf("ListResource not working: %s", err) } // DeleteResouce - err = f.client.DeleteResource(context.TODO(), "", "thekind", "ns-foo", "name-bar", false) + err = f.client.DeleteResource(context.TODO(), "", "thekind", "ns-foo", "name-bar", false, metav1.DeleteOptions{}) if err != nil { t.Errorf("DeleteResouce not working: %s", err) } diff --git a/pkg/controllers/cleanup/controller.go b/pkg/controllers/cleanup/controller.go index f0b88a7c2f..165c3273d8 100644 --- a/pkg/controllers/cleanup/controller.go +++ b/pkg/controllers/cleanup/controller.go @@ -309,7 +309,7 @@ func (c *controller) cleanup(ctx context.Context, logger logr.Logger, policy kyv labels = append(labels, attribute.String("deletion_policy", string(*deleteOptions.PropagationPolicy))) } logger.WithValues("name", name, "namespace", namespace).Info("resource matched, it will be deleted...") - if err := c.client.DeleteResource(ctx, resource.GetAPIVersion(), resource.GetKind(), namespace, name, false); err != nil { + if err := c.client.DeleteResource(ctx, resource.GetAPIVersion(), resource.GetKind(), namespace, name, false, metav1.DeleteOptions{}); err != nil { if c.metrics.cleanupFailuresTotal != nil { c.metrics.cleanupFailuresTotal.Add(ctx, 1, metric.WithAttributes(labels...)) } diff --git a/pkg/utils/fuzz/fuzz_interface.go b/pkg/utils/fuzz/fuzz_interface.go index f2abdc84e3..181cbb6bc6 100644 --- a/pkg/utils/fuzz/fuzz_interface.go +++ b/pkg/utils/fuzz/fuzz_interface.go @@ -60,7 +60,7 @@ func (fi FuzzInterface) ListResource(ctx context.Context, apiVersion string, kin return nil, fmt.Errorf("Not implemented") } -func (fi FuzzInterface) DeleteResource(ctx context.Context, apiVersion string, kind string, namespace string, name string, dryRun bool) error { +func (fi FuzzInterface) DeleteResource(ctx context.Context, apiVersion string, kind string, namespace string, name string, dryRun bool, options metav1.DeleteOptions) error { return fmt.Errorf("Not implemented") }