This is an automated email from the ASF dual-hosted git repository.

astefanutti pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-k.git


The following commit(s) were added to refs/heads/main by this push:
     new 8edc77c  chore(build): Cancel s2i Build on context cancellation or 
timeout
8edc77c is described below

commit 8edc77c8236f8d9c31bcda5815864bd13806e975
Author: Antonin Stefanutti <anto...@stefanutti.fr>
AuthorDate: Fri Jun 11 15:15:00 2021 +0200

    chore(build): Cancel s2i Build on context cancellation or timeout
---
 pkg/builder/s2i.go | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/pkg/builder/s2i.go b/pkg/builder/s2i.go
index 469be63..428901a 100644
--- a/pkg/builder/s2i.go
+++ b/pkg/builder/s2i.go
@@ -41,6 +41,7 @@ import (
        v1 "github.com/apache/camel-k/pkg/apis/camel/v1"
        "github.com/apache/camel-k/pkg/client"
        "github.com/apache/camel-k/pkg/util/kubernetes/customclient"
+       "github.com/apache/camel-k/pkg/util/log"
        "github.com/apache/camel-k/pkg/util/zip"
 )
 
@@ -195,6 +196,11 @@ func (t *s2iTask) Do(ctx context.Context) v1.BuildStatus {
 
        err = t.waitForS2iBuildCompletion(ctx, t.c, &s2iBuild)
        if err != nil {
+               if err == context.Canceled || err == context.DeadlineExceeded {
+                       if err := t.cancelBuild(context.Background(), 
&s2iBuild); err != nil {
+                               log.Errorf(err, "cannot cancel s2i Build: 
%s/%s", s2iBuild.Namespace, s2iBuild.Name)
+                       }
+               }
                return status.Failed(err)
        }
        if s2iBuild.Status.Output.To != nil {
@@ -259,3 +265,13 @@ func (t *s2iTask) waitForS2iBuildCompletion(ctx 
context.Context, c client.Client
                }
        }
 }
+
+func (t *s2iTask) cancelBuild(ctx context.Context, build *buildv1.Build) error 
{
+       target := build.DeepCopy()
+       target.Status.Cancelled = true
+       if err := t.c.Patch(ctx, target, ctrl.MergeFrom(build)); err != nil {
+               return err
+       }
+       *build = *target
+       return nil
+}

Reply via email to