diff --git a/pkg/cleanup/cleaner/cleaner.go b/pkg/cleanup/cleaner/cleaner.go index 3f5cc78f8..457949030 100644 --- a/pkg/cleanup/cleaner/cleaner.go +++ b/pkg/cleanup/cleaner/cleaner.go @@ -24,17 +24,19 @@ type Cleaner interface { Run(ctx context.Context) []error } -func New(timeout time.Duration, delay *time.Duration) Cleaner { +func New(timeout time.Duration, delay *time.Duration, propagation metav1.DeletionPropagation) Cleaner { return &cleaner{ - delay: delay, - timeout: timeout, + delay: delay, + timeout: timeout, + propagation: propagation, } } type cleaner struct { - delay *time.Duration - timeout time.Duration - entries []cleanupEntry + delay *time.Duration + timeout time.Duration + propagation metav1.DeletionPropagation + entries []cleanupEntry } func (c *cleaner) Add(client client.Client, object client.Object) { @@ -64,7 +66,7 @@ func (c *cleaner) Run(ctx context.Context) []error { func (c *cleaner) delete(ctx context.Context, entry cleanupEntry) error { ctx, cancel := context.WithTimeout(ctx, c.timeout) defer cancel() - if err := entry.client.Delete(ctx, entry.object, client.PropagationPolicy(metav1.DeletePropagationForeground)); err != nil { + if err := entry.client.Delete(ctx, entry.object, client.PropagationPolicy(c.propagation)); err != nil { if !kerrors.IsNotFound(err) { return err } diff --git a/pkg/cleanup/cleaner/cleaner_test.go b/pkg/cleanup/cleaner/cleaner_test.go index bfb759498..54e414837 100644 --- a/pkg/cleanup/cleaner/cleaner_test.go +++ b/pkg/cleanup/cleaner/cleaner_test.go @@ -27,21 +27,23 @@ func TestNew(t *testing.T) { timeout: time.Minute, delay: nil, want: &cleaner{ - timeout: time.Minute, - delay: nil, + timeout: time.Minute, + delay: nil, + propagation: metav1.DeletePropagationBackground, }, }, { name: "with delay", timeout: time.Minute, delay: ptr.To(10 * time.Second), want: &cleaner{ - timeout: time.Minute, - delay: ptr.To(10 * time.Second), + timeout: time.Minute, + delay: ptr.To(10 * time.Second), + propagation: metav1.DeletePropagationBackground, }, }} for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - got := New(tt.timeout, tt.delay) + got := New(tt.timeout, tt.delay, metav1.DeletePropagationBackground) assert.Equal(t, tt.want, got) }) } diff --git a/pkg/runner/processors/step.go b/pkg/runner/processors/step.go index f4015d22d..adf0b1104 100644 --- a/pkg/runner/processors/step.go +++ b/pkg/runner/processors/step.go @@ -109,7 +109,7 @@ func (p *stepProcessor) Run(ctx context.Context, namespacer namespacer.Namespace logging.Log(ctx, logging.Internal, logging.ErrorStatus, color.BoldRed, logging.ErrSection(err)) failer.FailNow(ctx) } - cleaner := cleaner.New(p.timeouts.Cleanup.Duration, p.delayBeforeCleanup) + cleaner := cleaner.New(p.timeouts.Cleanup.Duration, p.delayBeforeCleanup, p.deletionPropagationPolicy) t.Cleanup(func() { if !cleaner.Empty() || len(p.step.Cleanup) != 0 { logger.Log(logging.Cleanup, logging.RunStatus, color.BoldFgCyan) diff --git a/pkg/runner/processors/test.go b/pkg/runner/processors/test.go index 4fd9372f8..ce083348f 100644 --- a/pkg/runner/processors/test.go +++ b/pkg/runner/processors/test.go @@ -105,7 +105,7 @@ func (p *testProcessor) Run(ctx context.Context, nspacer namespacer.Namespacer, } }) } - mainCleaner := cleaner.New(p.timeouts.Cleanup.Duration, nil) + mainCleaner := cleaner.New(p.timeouts.Cleanup.Duration, nil, p.deletionPropagationPolicy) t.Cleanup(func() { if !mainCleaner.Empty() { logging.Log(ctx, logging.Cleanup, logging.RunStatus, color.BoldFgCyan) diff --git a/pkg/runner/processors/tests.go b/pkg/runner/processors/tests.go index e2455ee07..d04ac3cb1 100644 --- a/pkg/runner/processors/tests.go +++ b/pkg/runner/processors/tests.go @@ -46,7 +46,7 @@ func (p *testsProcessor) Run(ctx context.Context, tc engine.Context, tests ...di p.report.SetEndTime(time.Now()) }) } - mainCleaner := cleaner.New(p.config.Timeouts.Cleanup.Duration, nil) + mainCleaner := cleaner.New(p.config.Timeouts.Cleanup.Duration, nil, p.config.Deletion.Propagation) t.Cleanup(func() { if !mainCleaner.Empty() { logging.Log(ctx, logging.Cleanup, logging.RunStatus, color.BoldFgCyan)