Skip to content

Commit 3bf6147

Browse files
committed
Add retry logic to func deploy to handle transient network errors
Retries func deploy up to 3 times with 5s delay between attempts to handle transient in-cluster-dialer connection failures during parallel E2E execution.
1 parent d6aeb3f commit 3bf6147

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

test/utils/func.go

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ import (
2424
"os/exec"
2525
"path/filepath"
2626
"runtime"
27+
"time"
28+
29+
. "github.com/onsi/ginkgo/v2"
2730
)
2831

2932
// RunFunc executes the func CLI with the current/latest version
@@ -46,7 +49,7 @@ func RunFuncWithVersion(version string, command string, args ...string) (string,
4649
return Run(cmd)
4750
}
4851

49-
// RunFuncDeploy runs func deploy
52+
// RunFuncDeploy runs func deploy with retry logic for transient network errors
5053
func RunFuncDeploy(functionDir string, optFns ...FuncDeployOption) (string, error) {
5154
opts := &FuncDeployOptions{
5255
// defaults
@@ -78,11 +81,28 @@ func RunFuncDeploy(functionDir string, optFns ...FuncDeployOption) (string, erro
7881
args = append(args, "--deployer", opts.Deployer)
7982
}
8083

81-
if opts.CliVersion != "" {
82-
return RunFuncWithVersion(opts.CliVersion, "deploy", args...)
84+
var output string
85+
var err error
86+
87+
// Retry up to 3 times with 5s delay between attempts
88+
for attempt := 0; attempt < 3; attempt++ {
89+
if attempt > 0 {
90+
time.Sleep(5 * time.Second)
91+
_, _ = fmt.Fprintf(GinkgoWriter, "func deploy attempt %d failed: %v (retrying)\n", attempt, err)
92+
}
93+
94+
if opts.CliVersion != "" {
95+
output, err = RunFuncWithVersion(opts.CliVersion, "deploy", args...)
96+
} else {
97+
output, err = RunFunc("deploy", args...)
98+
}
99+
100+
if err == nil {
101+
return output, nil
102+
}
83103
}
84104

85-
return RunFunc("deploy", args...)
105+
return output, err
86106
}
87107

88108
type FuncDeployOptions struct {

0 commit comments

Comments
 (0)