From c1afd4d578efcc316c2fab17bab49cf5e67ddf04 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 15 Jun 2023 14:04:23 -0700 Subject: [PATCH] Fix off-by-one in max-failures and docs --- README.md | 9 ++++----- main.go | 12 ++++++------ v3-to-v4.md | 4 ++++ 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 83606b776..f5a7e52bf 100644 --- a/README.md +++ b/README.md @@ -112,7 +112,6 @@ More documentation on specific topics can be [found here](./docs). ## Manual ``` - GIT-SYNC NAME @@ -266,10 +265,10 @@ OPTIONS Print this manual and exit. --max-failures , $GITSYNC_MAX_FAILURES - The number of consecutive failures allowed before aborting (the - first sync must succeed), Setting this to a negative value will - retry forever after the initial sync. If not specified, this - defaults to 0, meaning any sync failure will terminate git-sync. + The number of consecutive failures allowed before aborting. + Setting this to a negative value will retry forever. If not + specified, this defaults to 0, meaning any sync failure will + terminate git-sync. --one-time, $GITSYNC_ONE_TIME Exit after one sync. diff --git a/main.go b/main.go index 3a562bc02..b8e47d3d9 100644 --- a/main.go +++ b/main.go @@ -384,7 +384,7 @@ func main() { "sync on receipt of the specified signal (e.g. SIGHUP)") flMaxFailures := pflag.Int("max-failures", envInt(0, "GITSYNC_MAX_FAILURES", "GIT_SYNC_MAX_FAILURES"), - "the number of consecutive failures allowed before aborting (the first sync must succeed, -1 will retry forever") + "the number of consecutive failures allowed before aborting (-1 will retry forever") flTouchFile := pflag.String("touch-file", envString("", "GITSYNC_TOUCH_FILE", "GIT_SYNC_TOUCH_FILE"), "the path (absolute or relative to --root) to an optional file which will be touched whenever a sync completes (defaults to disabled)") @@ -964,7 +964,7 @@ func main() { if changed, hash, err := git.SyncRepo(ctx, refreshCreds); err != nil { failCount++ updateSyncMetrics(metricKeyError, start) - if *flMaxFailures >= 0 && failCount > *flMaxFailures { + if *flMaxFailures >= 0 && failCount >= *flMaxFailures { // Exit after too many retries, maybe the error is not recoverable. log.Error(err, "too many failures, aborting", "failCount", failCount) os.Exit(1) @@ -2375,10 +2375,10 @@ OPTIONS Print this manual and exit. --max-failures , $GITSYNC_MAX_FAILURES - The number of consecutive failures allowed before aborting (the - first sync must succeed), Setting this to a negative value will - retry forever after the initial sync. If not specified, this - defaults to 0, meaning any sync failure will terminate git-sync. + The number of consecutive failures allowed before aborting. + Setting this to a negative value will retry forever. If not + specified, this defaults to 0, meaning any sync failure will + terminate git-sync. --one-time, $GITSYNC_ONE_TIME Exit after one sync. diff --git a/v3-to-v4.md b/v3-to-v4.md index 12d0087bc..362376bad 100644 --- a/v3-to-v4.md +++ b/v3-to-v4.md @@ -89,6 +89,10 @@ The new name of this flag is shorter and captures the idea that any non-recoverable error in the sync loop counts as a failure. For backwards compatibility, `--max-sync-failures` will be used if it is specified. +git-sync v3 demanded that the first sync succeed, regardless of this flag. +git-sync v4 always allows failures up to this maximum, whether it is the first +sync or any other. + ### Timeouts: `--timeout` -> `--sync-timeout` The old `--timeout` flag took an integer number of seconds as an argument. The