Skip to content

Commit 69c4666

Browse files
retry to validate if connection error (#944)
Co-authored-by: jackyu <jackyu@yunify.com>
1 parent 7ee06ee commit 69c4666

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

controllers/jenkins/pipeline/json_converter.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,11 @@ package pipeline
1818

1919
import (
2020
"context"
21+
"errors"
2122
"fmt"
2223
"reflect"
24+
"strings"
25+
"syscall"
2326
"time"
2427

2528
"github.com/go-logr/logr"
@@ -39,6 +42,9 @@ import (
3942
// tokenExpireIn indicates that the temporary token issued by controller will be expired in some time.
4043
const tokenExpireIn time.Duration = 5 * time.Minute
4144

45+
// HttpTimeoutErrStr indicates that connection in http request is timeout(the str in error).
46+
const HttpTimeoutErrStr = " (Client.Timeout exceeded while awaiting headers)"
47+
4248
//+kubebuilder:rbac:groups=devops.kubesphere.io,resources=pipelines,verbs=get;list;update;patch;watch
4349
//+kubebuilder:rbac:groups="",resources=events,verbs=create;patch
4450

@@ -108,6 +114,14 @@ func (r *JenkinsfileReconciler) reconcileJenkinsfileEditMode(pip *v1alpha3.Pipel
108114
var toJSONResult core.GenericResult
109115
if toJSONResult, err = coreClient.ToJSON(jenkinsfile); err != nil || toJSONResult.GetStatus() != "success" {
110116
r.log.Error(err, "failed to convert jenkinsfile to json format")
117+
if err != nil {
118+
// ConnectRefused || Timeout when jenkins is starting(not ready), retry
119+
if errors.Is(err, syscall.ECONNREFUSED) || strings.Contains(err.Error(), HttpTimeoutErrStr) {
120+
r.log.Info("connect to jenkins failed, retry..")
121+
return ctrl.Result{RequeueAfter: 10 * time.Second}, nil
122+
}
123+
}
124+
111125
pip.Annotations[v1alpha3.PipelineJenkinsfileValueAnnoKey] = ""
112126
pip.Annotations[v1alpha3.PipelineJenkinsfileEditModeAnnoKey] = ""
113127
pip.Annotations[v1alpha3.PipelineJenkinsfileValidateAnnoKey] = v1alpha3.PipelineJenkinsfileValidateFailure

0 commit comments

Comments
 (0)