@@ -18,8 +18,11 @@ package pipeline
18
18
19
19
import (
20
20
"context"
21
+ "errors"
21
22
"fmt"
22
23
"reflect"
24
+ "strings"
25
+ "syscall"
23
26
"time"
24
27
25
28
"github.com/go-logr/logr"
@@ -39,6 +42,9 @@ import (
39
42
// tokenExpireIn indicates that the temporary token issued by controller will be expired in some time.
40
43
const tokenExpireIn time.Duration = 5 * time .Minute
41
44
45
+ // HttpTimeoutErrStr indicates that connection in http request is timeout(the str in error).
46
+ const HttpTimeoutErrStr = " (Client.Timeout exceeded while awaiting headers)"
47
+
42
48
//+kubebuilder:rbac:groups=devops.kubesphere.io,resources=pipelines,verbs=get;list;update;patch;watch
43
49
//+kubebuilder:rbac:groups="",resources=events,verbs=create;patch
44
50
@@ -108,6 +114,14 @@ func (r *JenkinsfileReconciler) reconcileJenkinsfileEditMode(pip *v1alpha3.Pipel
108
114
var toJSONResult core.GenericResult
109
115
if toJSONResult , err = coreClient .ToJSON (jenkinsfile ); err != nil || toJSONResult .GetStatus () != "success" {
110
116
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
+
111
125
pip .Annotations [v1alpha3 .PipelineJenkinsfileValueAnnoKey ] = ""
112
126
pip .Annotations [v1alpha3 .PipelineJenkinsfileEditModeAnnoKey ] = ""
113
127
pip .Annotations [v1alpha3 .PipelineJenkinsfileValidateAnnoKey ] = v1alpha3 .PipelineJenkinsfileValidateFailure
0 commit comments