Skip to content

Commit fc3bcad

Browse files
refactor: remove unused opcodes and simplify FdSet clearing logic
2 parents d76daec + d3188cf commit fc3bcad

218 files changed

Lines changed: 9653 additions & 5480 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

chart-sync/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.0
44

55
toolchain go1.24.3
66

7-
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20251217072256-6c8429c6cc72
7+
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260408094056-e2d5c635d7db
88

99
require (
1010
github.com/caarlos0/env v3.5.0+incompatible

chart-sync/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
4343
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4444
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
4545
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
46-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20251217072256-6c8429c6cc72 h1:L1XupZ+tdjzcMjtzncAszzTeDZKUm7h9HThDIFYkTz4=
47-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20251217072256-6c8429c6cc72/go.mod h1:CqHnvltrng2O40hNGVl56qcAhv7tiXK3SKx47LKyE/A=
46+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260408094056-e2d5c635d7db h1:S+heJTGVdAiDcLwnau4pugYOzjmjYC87wXLsyC1PqzY=
47+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260408094056-e2d5c635d7db/go.mod h1:d6awSGcXQc57s4PJlwcyACovJ4PgBmR9jZJ7h6CScUM=
4848
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78=
4949
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc=
5050
github.com/distribution/distribution/v3 v3.0.0 h1:q4R8wemdRQDClzoNNStftB2ZAfqOiN6UX90KJc4HjyM=

chart-sync/vendor/modules.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ github.com/containerd/platforms
9595
# github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
9696
## explicit
9797
github.com/davecgh/go-spew/spew
98-
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20251217072256-6c8429c6cc72
98+
# github.com/devtron-labs/common-lib v0.19.1 => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260408094056-e2d5c635d7db
9999
## explicit; go 1.24.0
100100
github.com/devtron-labs/common-lib/constants
101101
github.com/devtron-labs/common-lib/fetchAllEnv
@@ -975,4 +975,4 @@ sigs.k8s.io/structured-merge-diff/v4/value
975975
sigs.k8s.io/yaml
976976
sigs.k8s.io/yaml/goyaml.v2
977977
sigs.k8s.io/yaml/goyaml.v3
978-
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20251217072256-6c8429c6cc72
978+
# github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260408094056-e2d5c635d7db

ci-runner/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.0
44

55
toolchain go1.24.3
66

7-
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20251217072256-6c8429c6cc72
7+
replace github.com/devtron-labs/common-lib => github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260408094056-e2d5c635d7db
88

99
require (
1010
github.com/Knetic/govaluate v3.0.0+incompatible
@@ -136,12 +136,12 @@ require (
136136
go.uber.org/zap v1.27.0 // indirect
137137
go.yaml.in/yaml/v2 v2.4.2 // indirect
138138
golang.org/x/crypto v0.40.0 // indirect
139-
golang.org/x/net v0.41.0 // indirect
139+
golang.org/x/net v0.42.0 // indirect
140140
golang.org/x/oauth2 v0.30.0 // indirect
141141
golang.org/x/sys v0.34.0 // indirect
142142
golang.org/x/term v0.33.0 // indirect
143143
golang.org/x/text v0.27.0 // indirect
144-
golang.org/x/time v0.11.0 // indirect
144+
golang.org/x/time v0.12.0 // indirect
145145
google.golang.org/api v0.234.0 // indirect
146146
google.golang.org/genproto v0.0.0-20250519155744-55703ea1f237 // indirect
147147
google.golang.org/genproto/googleapis/api v0.0.0-20250519155744-55703ea1f237 // indirect

ci-runner/go.sum

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
114114
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
115115
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
116116
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
117-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20251217072256-6c8429c6cc72 h1:L1XupZ+tdjzcMjtzncAszzTeDZKUm7h9HThDIFYkTz4=
118-
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20251217072256-6c8429c6cc72/go.mod h1:CqHnvltrng2O40hNGVl56qcAhv7tiXK3SKx47LKyE/A=
117+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260408094056-e2d5c635d7db h1:S+heJTGVdAiDcLwnau4pugYOzjmjYC87wXLsyC1PqzY=
118+
github.com/devtron-labs/devtron-services/common-lib v0.0.0-20260408094056-e2d5c635d7db/go.mod h1:d6awSGcXQc57s4PJlwcyACovJ4PgBmR9jZJ7h6CScUM=
119119
github.com/distribution/reference v0.6.0 h1:0IXCQ5g4/QMHHkarYzh5l+u8T3t73zM5QvfrDyIgxBk=
120120
github.com/distribution/reference v0.6.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
121121
github.com/docker/cli v28.1.1+incompatible h1:eyUemzeI45DY7eDPuwUcmDyDj1pM98oD5MdSpiItp8k=
@@ -393,8 +393,8 @@ golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
393393
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
394394
golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk=
395395
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
396-
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
397-
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
396+
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
397+
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
398398
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
399399
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
400400
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -450,8 +450,8 @@ golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
450450
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
451451
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
452452
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
453-
golang.org/x/time v0.11.0 h1:/bpjEDfN9tkoN/ryeYHnv5hcMlc8ncjMcM4XBk5NWV0=
454-
golang.org/x/time v0.11.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
453+
golang.org/x/time v0.12.0 h1:ScB/8o8olJvc+CQPWrK3fPZNfh7qgwCrY0zJmoEQLSE=
454+
golang.org/x/time v0.12.0/go.mod h1:CDIdPxbZBQxdj6cxyCIdrNogrJKMJ7pr37NYpMcMDSg=
455455
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
456456
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
457457
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=

ci-runner/helper/DockerHelper.go

Lines changed: 78 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,19 @@ import (
2323
"encoding/json"
2424
"errors"
2525
"fmt"
26+
"io"
27+
"io/ioutil"
28+
"log"
29+
"os"
30+
"os/exec"
31+
"path"
32+
"path/filepath"
33+
"strconv"
34+
"strings"
35+
"sync"
36+
"syscall"
37+
"time"
38+
2639
"github.com/aws/aws-sdk-go/aws"
2740
"github.com/aws/aws-sdk-go/aws/credentials"
2841
"github.com/aws/aws-sdk-go/aws/credentials/ec2rolecreds"
@@ -38,18 +51,6 @@ import (
3851
"github.com/devtron-labs/common-lib/utils/dockerOperations"
3952
"github.com/devtron-labs/common-lib/utils/retryFunc"
4053
"golang.org/x/sync/errgroup"
41-
"io"
42-
"io/ioutil"
43-
"log"
44-
"os"
45-
"os/exec"
46-
"path"
47-
"path/filepath"
48-
"strconv"
49-
"strings"
50-
"sync"
51-
"syscall"
52-
"time"
5354
)
5455

5556
const (
@@ -74,15 +75,23 @@ type DockerHelper interface {
7475
GetDockerAuthConfigForPrivateRegistries(workflowRequest *CommonWorkflowRequest) *bean.DockerAuthConfig
7576
}
7677

78+
// BuildxK8sClientFactory creates a BuildxK8sInterface from deployment names.
79+
// Abstracted for testability — production code uses newBuildxK8sClient as the default.
80+
type BuildxK8sClientFactory func(deploymentNames []string) (BuildxK8sInterface, error)
81+
7782
type DockerHelperImpl struct {
7883
DockerCommandEnv []string
7984
cmdExecutor CommandExecutor
85+
k8sClientFactory BuildxK8sClientFactory
8086
}
8187

8288
func NewDockerHelperImpl(cmdExecutor CommandExecutor) *DockerHelperImpl {
8389
return &DockerHelperImpl{
8490
DockerCommandEnv: os.Environ(),
8591
cmdExecutor: cmdExecutor,
92+
k8sClientFactory: func(names []string) (BuildxK8sInterface, error) {
93+
return newBuildxK8sClient(names)
94+
},
8695
}
8796
}
8897

@@ -300,9 +309,27 @@ func (impl *DockerHelperImpl) DockerLogin(ciContext cicxt.CiContext, dockerCrede
300309
return performDockerLogin()
301310
}
302311

312+
// waitForBuilderPods waits until all buildx k8s driver pods reach Running state,
313+
// or returns an error if the deadline is exceeded. Extracted for testability.
314+
func waitForBuilderPods(ctx context.Context, k8sClient BuildxK8sInterface, duration time.Duration) error {
315+
log.Println(util.DEVTRON, fmt.Sprintf("waiting for builder pods to be ready (timeout: %v)", duration))
316+
initDone := make(chan bool, 1)
317+
initCtx, initCancel := context.WithTimeout(ctx, duration)
318+
defer initCancel()
319+
go k8sClient.WaitUntilBuilderPodLive(initCtx, initDone)
320+
select {
321+
case <-initDone:
322+
log.Println(util.DEVTRON, "builder pods are ready for build")
323+
return nil
324+
case <-initCtx.Done():
325+
return fmt.Errorf("builder pods did not reach Running state within %v", duration)
326+
}
327+
}
328+
303329
func (impl *DockerHelperImpl) executeDockerReBuild(ciContext cicxt.CiContext, k8sClient BuildxK8sInterface,
304330
useBuildxK8sDriver bool, dockerBuild string, deploymentNames []string,
305-
dockerBuildStageMetadata bean2.DockerBuildStageMetadata, reBuildLogs []any) error {
331+
dockerBuildStageMetadata bean2.DockerBuildStageMetadata, reBuildLogs []any,
332+
builderPodWaitDuration time.Duration) error {
306333
if !useBuildxK8sDriver {
307334
return nil
308335
}
@@ -311,7 +338,7 @@ func (impl *DockerHelperImpl) executeDockerReBuild(ciContext cicxt.CiContext, k8
311338
log.Println(util.DEVTRON, fmt.Sprintf(" error in RestartBuilders : %s", k8sErr.Error()))
312339
return k8sErr
313340
}
314-
k8sClient, err := newBuildxK8sClient(deploymentNames)
341+
k8sClient, err := impl.k8sClientFactory(deploymentNames)
315342
if err != nil {
316343
log.Println(util.DEVTRON, " error in creating buildxK8sClient , err : ", err.Error())
317344
return err
@@ -324,18 +351,15 @@ func (impl *DockerHelperImpl) executeDockerReBuild(ciContext cicxt.CiContext, k8
324351
rebuildImageStage := func() error {
325352
// wait for the builder pod to be up again
326353
startTime := time.Now()
327-
util.LogInfo("Waiting for builder pod to be ready,", "timeout: 2 minutes")
328-
done := make(chan bool)
329-
ctx, cancel := context.WithCancel(ciContext)
354+
util.LogInfo("Waiting for builder pod to be ready,", fmt.Sprintf("timeout: %v", builderPodWaitDuration))
355+
done := make(chan bool, 1) // buffered to prevent goroutine leak on timeout
356+
ctx, cancel := context.WithTimeout(ciContext, builderPodWaitDuration)
330357
defer cancel()
331358
go k8sClient.WaitUntilBuilderPodLive(ctx, done)
332359
select {
333360
case <-done:
334361
// builder pod is up again, continue with the build
335-
cancel()
336-
case <-time.After(2 * time.Minute):
337-
// timeout after 2 minutes
338-
cancel()
362+
case <-ctx.Done():
339363
return BuilderPodDeletedError
340364
}
341365
util.LogInfo("DONE -->", time.Since(startTime).Seconds())
@@ -403,6 +427,10 @@ func (impl *DockerHelperImpl) BuildArtifact(ciRequest *CommonWorkflowRequest) (s
403427
if err != nil {
404428
log.Println("Error while parsing environment variables", err)
405429
}
430+
builderPodWaitDuration := 2 * time.Minute // backward-compat default
431+
if ciRequest.BuildxBuilderPodWaitDurationSecs > 0 {
432+
builderPodWaitDuration = time.Duration(ciRequest.BuildxBuilderPodWaitDurationSecs) * time.Second
433+
}
406434
if ciRequest.DockerImageTag == "" {
407435
ciRequest.DockerImageTag = "latest"
408436
}
@@ -453,12 +481,12 @@ func (impl *DockerHelperImpl) BuildArtifact(ciRequest *CommonWorkflowRequest) (s
453481
}
454482
useBuildxK8sDriver, eligibleK8sDriverNodes = dockerBuildConfig.CheckForBuildXK8sDriver()
455483
if useBuildxK8sDriver {
456-
deploymentNames, err = impl.createBuildxBuilderWithK8sDriver(ciContext, ciRequest.PropagateLabelsInBuildxPod, ciRequest.DockerConnection, dockerBuildConfig.BuildxDriverImage, eligibleK8sDriverNodes, ciRequest.PipelineId, ciRequest.WorkflowId)
484+
deploymentNames, err = impl.createBuildxBuilderWithK8sDriver(ciContext, ciRequest.PropagateLabelsInBuildxPod, ciRequest.DockerConnection, dockerBuildConfig.BuildxDriverImage, eligibleK8sDriverNodes, ciRequest.PipelineId, ciRequest.WorkflowId, builderPodWaitDuration)
457485
if err != nil {
458486
log.Println(util.DEVTRON, " error in creating buildxDriver , err : ", err.Error())
459487
return err
460488
}
461-
k8sClient, err = newBuildxK8sClient(deploymentNames)
489+
k8sClient, err = impl.k8sClientFactory(deploymentNames)
462490
if err != nil {
463491
log.Println(util.DEVTRON, " error in creating buildxK8sClient , err : ", err.Error())
464492
return err
@@ -469,6 +497,11 @@ func (impl *DockerHelperImpl) BuildArtifact(ciRequest *CommonWorkflowRequest) (s
469497
log.Println(util.DEVTRON, " error in registering builder pods ", " err: ", err)
470498
return err
471499
}
500+
// Wait for builder pods to reach Running state before starting the build.
501+
// Prevents false-positive BuilderPodDeletedError from pod startup latency.
502+
if err = waitForBuilderPods(ciContext, k8sClient, builderPodWaitDuration); err != nil {
503+
return err
504+
}
472505
} else {
473506
err = impl.createBuildxBuilderForMultiArchBuild(ciContext, ciRequest.DockerConnection, dockerBuildConfig.BuildxDriverImage)
474507
if err != nil {
@@ -534,7 +567,7 @@ func (impl *DockerHelperImpl) BuildArtifact(ciRequest *CommonWorkflowRequest) (s
534567
reBuildLogs = []any{fmt.Sprintf("Starting re docker build (Attempt %d) : ", attempt), dockerBuild}
535568
}
536569
return impl.executeDockerReBuild(ciContext, k8sClient, useBuildxK8sDriver, dockerBuild,
537-
deploymentNames, dockerBuildStageMetadata, reBuildLogs)
570+
deploymentNames, dockerBuildStageMetadata, reBuildLogs, builderPodWaitDuration)
538571
}
539572
err = retryFunc.RetryWithOutLogging(callback, retryFunc.IsRetryableError, maxRetry, 1*time.Second)
540573
if err != nil {
@@ -1097,14 +1130,14 @@ func (impl *DockerHelperImpl) createBuildxBuilderForMultiArchBuild(ciContext cic
10971130
return nil
10981131
}
10991132

1100-
func (impl *DockerHelperImpl) createBuildxBuilderWithK8sDriver(ciContext cicxt.CiContext, propagateLabelsInBuildxPod bool, dockerConnection, buildxDriverImage string, builderNodes []map[string]string, ciPipelineId, ciWorkflowId int) ([]string, error) {
1133+
func (impl *DockerHelperImpl) createBuildxBuilderWithK8sDriver(ciContext cicxt.CiContext, propagateLabelsInBuildxPod bool, dockerConnection, buildxDriverImage string, builderNodes []map[string]string, ciPipelineId, ciWorkflowId int, timeout time.Duration) ([]string, error) {
11011134
deploymentNames := make([]string, 0)
11021135
if len(builderNodes) == 0 {
11031136
return deploymentNames, errors.New("atleast one node is expected for builder with kubernetes driver")
11041137
}
11051138
for i := 0; i < len(builderNodes); i++ {
11061139
nodeOpts := builderNodes[i]
1107-
builderCmd, deploymentName, err := getBuildxK8sDriverCmd(propagateLabelsInBuildxPod, dockerConnection, buildxDriverImage, nodeOpts, ciPipelineId, ciWorkflowId)
1140+
builderCmd, deploymentName, err := getBuildxK8sDriverCmd(propagateLabelsInBuildxPod, dockerConnection, buildxDriverImage, nodeOpts, ciPipelineId, ciWorkflowId, timeout)
11081141
if err != nil {
11091142
return deploymentNames, err
11101143
}
@@ -1181,7 +1214,7 @@ func (impl *DockerHelperImpl) runCmd(cmd string) (error, *bytes.Buffer) {
11811214
return err, errBuf
11821215
}
11831216

1184-
func getBuildxK8sDriverCmd(propagateLabelsInBuildxPod bool, dockerConnection, buildxDriverImage string, driverOpts map[string]string, ciPipelineId, ciWorkflowId int) (string, string, error) {
1217+
func getBuildxK8sDriverCmd(propagateLabelsInBuildxPod bool, dockerConnection, buildxDriverImage string, driverOpts map[string]string, ciPipelineId, ciWorkflowId int, timeout time.Duration) (string, string, error) {
11851218
buildxCreate := "docker buildx create --buildkitd-flags '--allow-insecure-entitlement network.host --allow-insecure-entitlement security.insecure' --name=%s --driver=kubernetes --node=%s --bootstrap "
11861219
nodeName := driverOpts["node"]
11871220
if nodeName == "" {
@@ -1203,6 +1236,9 @@ func getBuildxK8sDriverCmd(propagateLabelsInBuildxPod bool, dockerConnection, bu
12031236
}
12041237

12051238
driverOpts["driverOptions"] = getBuildXDriverOptionsWithImage(buildxDriverImage, driverOpts["driverOptions"])
1239+
if timeout > 0 {
1240+
driverOpts["driverOptions"] = getBuildXDriverOptionsWithTimeout(timeout, driverOpts["driverOptions"])
1241+
}
12061242
if len(driverOpts["driverOptions"]) > 0 {
12071243
buildxCreate += " '--driver-opt=%s' "
12081244
buildxCreate = fmt.Sprintf(buildxCreate, driverOpts["driverOptions"])
@@ -1227,6 +1263,21 @@ func getBuildXDriverOptionsWithImage(buildxDriverImage, driverOptions string) st
12271263
return driverOptions
12281264
}
12291265

1266+
func getBuildXDriverOptionsWithTimeout(timeout time.Duration, driverOptions string) string {
1267+
if strings.HasPrefix(driverOptions, "timeout=") ||
1268+
strings.Contains(driverOptions, ",timeout=") {
1269+
// if timeout is already present in driver options then do not override it, just return the existing options
1270+
return driverOptions
1271+
}
1272+
timeoutOption := fmt.Sprintf("\"timeout=%s\"", timeout.String())
1273+
if len(driverOptions) > 0 {
1274+
driverOptions += fmt.Sprintf(",%s", timeoutOption)
1275+
} else {
1276+
driverOptions = timeoutOption
1277+
}
1278+
return driverOptions
1279+
}
1280+
12301281
func getBuildXDriverOptionsWithLabelsAndAnnotations(driverOptions string) (string, error) {
12311282
// not passing annotation as of now because --driver-opt=annotations is not supported by buildx if contains quotes
12321283
labels := make(map[string]string)

ci-runner/helper/DockerHelper_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestCreateBuildXK8sDriver(t *testing.T) {
4141
eligibleK8sNodes := dockerBuildConfig.GetEligibleK8sDriverNodes()
4242
impl := getDockerHelperImpl()
4343
ciContext := cicxt.BuildCiContext(context.Background(), true)
44-
_, err := impl.createBuildxBuilderWithK8sDriver(ciContext, false, "", "", eligibleK8sNodes, 1, 1)
44+
_, err := impl.createBuildxBuilderWithK8sDriver(ciContext, false, "", "", eligibleK8sNodes, 1, 1, 0)
4545
t.Cleanup(func() {
4646
buildxDelete := fmt.Sprintf("docker buildx rm %s", BUILDX_K8S_DRIVER_NAME)
4747
builderRemoveCmd := exec.Command("/bin/sh", "-c", buildxDelete)
@@ -64,7 +64,7 @@ func TestCleanBuildxK8sDriver(t *testing.T) {
6464
eligibleK8sNodes := dockerBuildConfig.GetEligibleK8sDriverNodes()
6565
impl := getDockerHelperImpl()
6666
ciContext := cicxt.BuildCiContext(context.Background(), true)
67-
_, err := impl.createBuildxBuilderWithK8sDriver(ciContext, false, "", "", eligibleK8sNodes, 1, 1)
67+
_, err := impl.createBuildxBuilderWithK8sDriver(ciContext, false, "", "", eligibleK8sNodes, 1, 1, 0)
6868
if err != nil {
6969
fmt.Println(err.Error())
7070
t.Fail()

0 commit comments

Comments
 (0)