@@ -66,10 +66,10 @@ var flRoot = pflag.String("root", envString("GIT_SYNC_ROOT", envString("HOME", "
66
66
"the root directory for git-sync operations, under which --dest will be created" )
67
67
var flDest = pflag .String ("dest" , envString ("GIT_SYNC_DEST" , "" ),
68
68
"the name of (a symlink to) a directory in which to check-out files under --root (defaults to the leaf dir of --repo)" )
69
- var flWait = pflag .Float64 ( "wait " , envFloat ( "GIT_SYNC_WAIT " , 1 ),
70
- "the number of seconds between syncs" )
71
- var flSyncTimeout = pflag .Int ( " timeout" , envInt ( "GIT_SYNC_TIMEOUT " , 120 ),
72
- "the number of seconds allowed for a complete sync" )
69
+ var flPeriod = pflag .Duration ( "period " , envDuration ( "GIT_SYNC_PERIOD " , 10 * time . Second ),
70
+ "how long to wait between syncs, must be >= 10ms; --wait overrides this " )
71
+ var flSyncTimeout = pflag .Duration ( "sync- timeout" , envDuration ( "GIT_SYNC_SYNC_TIMEOUT " , 120 * time . Second ),
72
+ "the total time allowed for one complete sync, must be >= 10ms; --timeout overrides this " )
73
73
var flOneTime = pflag .Bool ("one-time" , envBool ("GIT_SYNC_ONE_TIME" , false ),
74
74
"exit after the first sync" )
75
75
var flMaxSyncFailures = pflag .Int ("max-sync-failures" , envInt ("GIT_SYNC_MAX_SYNC_FAILURES" , 0 ),
@@ -123,6 +123,17 @@ var flHTTPMetrics = pflag.Bool("http-metrics", envBool("GIT_SYNC_HTTP_METRICS",
123
123
var flHTTPprof = pflag .Bool ("http-pprof" , envBool ("GIT_SYNC_HTTP_PPROF" , false ),
124
124
"enable the pprof debug endpoints on git-sync's HTTP endpoint" )
125
125
126
+ // Obsolete flags, kept for compat.
127
+ var flWait = pflag .Float64 ("wait" , envFloat ("GIT_SYNC_WAIT" , 0 ),
128
+ "DEPRECATED: use --period instead" )
129
+ var flTimeout = pflag .Int ("timeout" , envInt ("GIT_SYNC_TIMEOUT" , 0 ),
130
+ "DEPRECATED: use --sync-timeout instead" )
131
+
132
+ func init () {
133
+ pflag .CommandLine .MarkDeprecated ("wait" , "use --period instead" )
134
+ pflag .CommandLine .MarkDeprecated ("timeout" , "use --sync-timeout instead" )
135
+ }
136
+
126
137
var log = glogr .New ()
127
138
128
139
// Total pull/error, summary on pull duration
@@ -150,9 +161,6 @@ const (
150
161
metricKeyNoOp = "noop"
151
162
)
152
163
153
- // initTimeout is a timeout for initialization, like git credentials setup.
154
- const initTimeout = time .Second * 30
155
-
156
164
const (
157
165
submodulesRecursive = "recursive"
158
166
submodulesShallow = "shallow"
@@ -308,14 +316,20 @@ func main() {
308
316
os .Exit (1 )
309
317
}
310
318
311
- if * flWait < 0 {
312
- fmt .Fprintf (os .Stderr , "ERROR: --wait must be greater than or equal to 0\n " )
319
+ if * flWait != 0 {
320
+ * flPeriod = time .Duration (int (* flWait * 1000 )) * time .Millisecond
321
+ }
322
+ if * flPeriod < 10 * time .Millisecond {
323
+ fmt .Fprintf (os .Stderr , "ERROR: --period must be at least 10ms\n " )
313
324
pflag .Usage ()
314
325
os .Exit (1 )
315
326
}
316
327
317
- if * flSyncTimeout < 0 {
318
- fmt .Fprintf (os .Stderr , "ERROR: --timeout must be greater than 0\n " )
328
+ if * flTimeout != 0 {
329
+ * flSyncTimeout = time .Duration (* flTimeout ) * time .Second
330
+ }
331
+ if * flSyncTimeout < 10 * time .Millisecond {
332
+ fmt .Fprintf (os .Stderr , "ERROR: --sync-timeout must be at least 10ms\n " )
319
333
pflag .Usage ()
320
334
os .Exit (1 )
321
335
}
@@ -382,8 +396,8 @@ func main() {
382
396
}
383
397
384
398
// This context is used only for git credentials initialization. There are no long-running operations like
385
- // `git clone`, so initTimeout set to 30 seconds should be enough.
386
- ctx , cancel := context .WithTimeout (context .Background (), initTimeout )
399
+ // `git clone`, so hopefully 30 seconds will be enough.
400
+ ctx , cancel := context .WithTimeout (context .Background (), 30 * time . Second )
387
401
388
402
if * flUsername != "" && * flPassword != "" {
389
403
if err := setupGitAuth (ctx , * flUsername , * flPassword , * flRepo ); err != nil {
@@ -471,7 +485,7 @@ func main() {
471
485
failCount := 0
472
486
for {
473
487
start := time .Now ()
474
- ctx , cancel := context .WithTimeout (context .Background (), time . Second * time . Duration ( * flSyncTimeout ) )
488
+ ctx , cancel := context .WithTimeout (context .Background (), * flSyncTimeout )
475
489
if changed , hash , err := syncRepo (ctx , * flRepo , * flBranch , * flRev , * flDepth , * flRoot , * flDest , * flAskPassURL , * flSubmodules ); err != nil {
476
490
updateSyncMetrics (metricKeyError , start )
477
491
if * flMaxSyncFailures != - 1 && failCount >= * flMaxSyncFailures {
@@ -482,9 +496,9 @@ func main() {
482
496
483
497
failCount ++
484
498
log .Error (err , "unexpected error syncing repo, will retry" )
485
- log .V (0 ).Info ("waiting before retrying" , "waitTime" , waitTime ( * flWait ))
499
+ log .V (0 ).Info ("waiting before retrying" , "waitTime" , flPeriod . String ( ))
486
500
cancel ()
487
- time .Sleep (waitTime ( * flWait ) )
501
+ time .Sleep (* flPeriod )
488
502
continue
489
503
} else if changed {
490
504
if webhook != nil {
@@ -510,9 +524,9 @@ func main() {
510
524
}
511
525
512
526
failCount = 0
513
- log .V (1 ).Info ("next sync" , "wait_time " , waitTime ( * flWait ))
527
+ log .V (1 ).Info ("next sync" , "waitTime " , flPeriod . String ( ))
514
528
cancel ()
515
- time .Sleep (waitTime ( * flWait ) )
529
+ time .Sleep (* flPeriod )
516
530
}
517
531
}
518
532
@@ -521,10 +535,6 @@ func updateSyncMetrics(key string, start time.Time) {
521
535
syncCount .WithLabelValues (key ).Inc ()
522
536
}
523
537
524
- func waitTime (seconds float64 ) time.Duration {
525
- return time .Duration (int (seconds * 1000 )) * time .Millisecond
526
- }
527
-
528
538
// Do no work, but don't do something that triggers go's runtime into thinking
529
539
// it is deadlocked.
530
540
func sleepForever () {
@@ -1113,6 +1123,11 @@ OPTIONS
1113
1123
users should prefer the environment variable for specifying the
1114
1124
password.
1115
1125
1126
+ --period <duration>, $GIT_SYNC_PERIOD
1127
+ How long to wait between sync attempts. This must be at least
1128
+ 10ms. This flag obsoletes --wait, but if --wait is specifed, it
1129
+ will take precedence. (default: 10s)
1130
+
1116
1131
--repo <string>, $GIT_SYNC_REPO
1117
1132
The git repository to sync.
1118
1133
@@ -1145,11 +1160,13 @@ OPTIONS
1145
1160
An optional command to be executed after syncing a new hash of the
1146
1161
remote repository. This command does not take any arguments and
1147
1162
executes with the synced repo as its working directory. The
1148
- execution is subject to the overall --timeout flag and will extend
1149
- the period between syncs attempts.
1163
+ execution is subject to the overall --sync- timeout flag and will
1164
+ extend the effective period between sync attempts.
1150
1165
1151
- --timeout <int>, $GIT_SYNC_TIMEOUT
1152
- The number of seconds allowed for a complete sync. (default: 120)
1166
+ --sync-timeout <duration>, $GIT_SYNC_SYNC_TIMEOUT
1167
+ The total time allowed for one complete sync. This must be at least
1168
+ 10ms. This flag obsoletes --timeout, but if --timeout is specified,
1169
+ it will take precedence. (default: 120s)
1153
1170
1154
1171
--username <string>, $GIT_SYNC_USERNAME
1155
1172
The username to use for git authentication (see --password).
@@ -1161,9 +1178,6 @@ OPTIONS
1161
1178
--version
1162
1179
Print the version and exit.
1163
1180
1164
- --wait <float>, $GIT_SYNC_WAIT
1165
- The number of seconds between sync attempts. (default: 1)
1166
-
1167
1181
--webhook-backoff <duration>, $GIT_SYNC_WEBHOOK_BACKOFF
1168
1182
The time to wait before retrying a failed --webhook-url).
1169
1183
(default: 3s)
@@ -1188,7 +1202,7 @@ EXAMPLE USAGE
1188
1202
--repo=https://github.com/kubernetes/git-sync \
1189
1203
--branch=master \
1190
1204
--rev=HEAD \
1191
- --wait=10 \
1205
+ --period=10s \
1192
1206
--root=/mnt/git
1193
1207
1194
1208
AUTHENTICATION
0 commit comments