Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed error when deleting already deleted object #45

Merged
merged 2 commits into from
May 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import (
type Engine interface {
RunTask(context.Context, *config.Task) error
Reset(context.Context) error
DeleteAllObjects(context.Context) error
DeleteAllObjects(context.Context)
}

type Eng struct {
Expand Down Expand Up @@ -263,11 +263,23 @@ func (eng *Eng) Reset(ctx context.Context) error {
ctx, cancel := context.WithTimeout(ctx, eng.cleanup.Timeout)
defer cancel()

return eng.DeleteAllObjects(ctx)
stop := make(chan struct{})

go func() {
eng.DeleteAllObjects(ctx)
stop <- struct{}{}
}()

select {
case <-stop:
return nil
case <-ctx.Done():
return ctx.Err()
}
}

// DeleteAllObjects deletes all objects
func (eng *Eng) DeleteAllObjects(ctx context.Context) error {
func (eng *Eng) DeleteAllObjects(ctx context.Context) {
deletePolicy := metav1.DeletePropagationBackground
deletions := metav1.DeleteOptions{
PropagationPolicy: &deletePolicy,
Expand All @@ -278,11 +290,10 @@ func (eng *Eng) DeleteAllObjects(ctx context.Context) error {
for _, name := range objInfo.Names {
err := eng.dynamicClient.Resource(objInfo.GVR).Namespace(ns).Delete(ctx, name, deletions)
if err != nil {
return err
eng.log.Info("Warning: cannot delete object", "name", name, "err", err.Error())
dmitsh marked this conversation as resolved.
Show resolved Hide resolved
}
}
}

eng.log.Info("Deleted all objects")
return nil
}
9 changes: 3 additions & 6 deletions pkg/engine/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,8 @@ var (
)

type testEngine struct {
execErr error
resetErr error
deleteErr error
execErr error
resetErr error
}

func (eng *testEngine) RunTask(context.Context, *config.Task) error {
Expand All @@ -53,9 +52,7 @@ func (eng *testEngine) Reset(context.Context) error {
return eng.resetErr
}

func (eng *testEngine) DeleteAllObjects(context.Context) error {
return eng.deleteErr
}
func (eng *testEngine) DeleteAllObjects(context.Context) {}

func TestRunEngine(t *testing.T) {
testCases := []struct {
Expand Down
Loading