Skip to content

Commit c1bcc31

Browse files
authored
fix(kaniko): delete kaniko pod on graceful shutdown (#9270)
* fix(kaniko): delete kaniko pod on graceful shutdown * added comment to explain why we need to create a new context
1 parent 56746fe commit c1bcc31

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/skaffold/build/cluster/kaniko.go

+7
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,17 @@ func (b *Builder) buildWithKaniko(ctx context.Context, out io.Writer, workspace
7777
}
7878

7979
pod, err := pods.Create(ctx, podSpec, metav1.CreateOptions{})
80+
8081
if err != nil {
8182
return "", fmt.Errorf("creating kaniko pod: %w", err)
8283
}
84+
8385
defer func() {
86+
// if build interrupted the original context is cancelled
87+
// and pod deletion will not be called, so we need a new ctx
88+
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
89+
defer cancel()
90+
8491
if err := pods.Delete(ctx, pod.Name, metav1.DeleteOptions{
8592
GracePeriodSeconds: new(int64),
8693
}); err != nil {

0 commit comments

Comments
 (0)