Skip to content

Commit

Permalink
fix: propagation policy
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
  • Loading branch information
eddycharly committed Jul 31, 2024
1 parent 6cfcb42 commit 4eb988d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 15 deletions.
16 changes: 9 additions & 7 deletions pkg/cleanup/cleaner/cleaner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/cleanup/cleaner/cleaner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/processors/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/processors/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pkg/runner/processors/tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4eb988d

Please sign in to comment.