From b7c35d2a0f2ba8920cbae41dab5b054ac6e61c53 Mon Sep 17 00:00:00 2001 From: Marcin Owsiany Date: Tue, 12 Jul 2022 10:14:35 +0200 Subject: [PATCH] During deletion, explicitly log already deleted resource name. Unfortunately errors from the API server do not always (do they ever?) contain the name of the resource in question. Deletions for multiple resources are processed concurrently, so in a resulting log, a preceding "Starting delete" line might be for a different object. Signed-off-by: Marcin Owsiany --- pkg/kube/client.go | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/pkg/kube/client.go b/pkg/kube/client.go index 38c8b93f2..5e75c34e4 100644 --- a/pkg/kube/client.go +++ b/pkg/kube/client.go @@ -308,16 +308,20 @@ func (c *Client) Delete(resources ResourceList) (*Result, []error) { mtx := sync.Mutex{} err := perform(resources, func(info *resource.Info) error { c.Log("Starting delete for %q %s", info.Name, info.Mapping.GroupVersionKind.Kind) - if err := c.skipIfNotFound(deleteResource(info)); err != nil { - mtx.Lock() - defer mtx.Unlock() - // Collect the error and continue on - errs = append(errs, err) - } else { + err := deleteResource(info) + if err == nil || apierrors.IsNotFound(err) { + if err != nil { + c.Log("Ignoring delete failure for %q %s: %v", info.Name, info.Mapping.GroupVersionKind, err) + } mtx.Lock() defer mtx.Unlock() res.Deleted = append(res.Deleted, info) + return nil } + mtx.Lock() + defer mtx.Unlock() + // Collect the error and continue on + errs = append(errs, err) return nil }) if err != nil { @@ -334,14 +338,6 @@ func (c *Client) Delete(resources ResourceList) (*Result, []error) { return res, nil } -func (c *Client) skipIfNotFound(err error) error { - if apierrors.IsNotFound(err) { - c.Log("%v", err) - return nil - } - return err -} - func (c *Client) watchTimeout(t time.Duration) func(*resource.Info) error { return func(info *resource.Info) error { return c.watchUntilReady(t, info)