Skip to content

add --init-period and --init-max-failures flags#980

Merged
k8s-ci-robot merged 6 commits intokubernetes:masterfrom
knQzx:add-init-period-flag
Apr 24, 2026
Merged

add --init-period and --init-max-failures flags#980
k8s-ci-robot merged 6 commits intokubernetes:masterfrom
knQzx:add-init-period-flag

Conversation

@knQzx
Copy link
Copy Markdown
Contributor

@knQzx knQzx commented Apr 4, 2026

summary

  • adds --init-period flag - used for retries until the first successful sync, then switches to normal --period
  • adds --init-max-failures flag - aborts after N consecutive failures during the initial sync phase, then --max-failures takes over
  • adds a SYNC PHASES section to --man and README explaining init vs steady-state behavior
  • both flags are optional and backward compatible - behavior is unchanged if not set

test plan

  • unit tests for chooseWaitTime() and isInitFailuresExceeded() helper functions
  • e2e tests for both flags
  • verified all existing tests still pass with go test ./...
  • build tested with go build ./...

fixes #959

@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 4, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@k8s-ci-robot k8s-ci-robot requested review from sdowell and stp-ip April 4, 2026 22:56
@k8s-ci-robot k8s-ci-robot added the cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. label Apr 4, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

Welcome @knQzx!

It looks like this is your first PR to kubernetes/git-sync 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/git-sync has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Apr 4, 2026
Copy link
Copy Markdown
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. The code looks good, but I'd really like e2e tests to cover these (test_e2e.sh)

Comment thread main.go Outdated
dynamic credentials from an external secrets system).
See also $GITSYNC_PASSWORD.

--init-period <duration>, $GITSYNC_INIT_PERIOD
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please keep this section alphabetical -- these should go earlier

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, please add to README

@thockin thockin self-assigned this Apr 5, 2026
@knQzx
Copy link
Copy Markdown
Contributor Author

knQzx commented Apr 5, 2026

thanks for the feedback, fixed - moved flags to alphabetical order, added readme docs, and added e2e tests for both init-period and init-timeout

Copy link
Copy Markdown
Member

@thockin thockin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Apr 13, 2026
@thockin thockin removed approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm "Looks good to me", indicates that a PR is ready to be merged. labels Apr 13, 2026
Comment thread main.go
@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 14, 2026
@knQzx
Copy link
Copy Markdown
Contributor Author

knQzx commented Apr 14, 2026

pushed a fix: the init-timeout test was using a valid repo with a slow fetch wrapper, so git-sync would succeed after 2s and run forever instead of timing out. swapped to a non-existent repo path so fetches actually fail and init-timeout fires as expected.

- rename flag and helper to count-based (int, not duration)
- skip --max-failures during init when init-max-failures is set so main-max does not override init tolerance
- add SYNC PHASES section to --man and README describing init vs steady-state
- update e2e test to use a bad server path, as suggested in review
@knQzx knQzx changed the title add --init-period and --init-timeout flags add --init-period and --init-max-failures flags Apr 22, 2026
@knQzx
Copy link
Copy Markdown
Contributor Author

knQzx commented Apr 22, 2026

reworked per the review:

  • renamed --init-timeout to --init-max-failures (int, counts failures)
  • e2e test now targets a bad server path as you suggested
  • added a SYNC PHASES section in --man and README describing init vs steady-state
  • also skipped --max-failures during init when --init-max-failures is set - otherwise main-max could override init tolerance, caught this while reviewing

lmk if the new shape works

@thockin thockin added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Apr 24, 2026
Comment thread main.go Outdated
Comment thread main.go Outdated
Comment thread main.go Outdated
Comment thread main.go Outdated
Comment thread main.go Outdated
…ures

- move flInitMaxFailures next to flMaxFailures
- default flInitPeriod to flPeriod to kill conditional in hot path
- replace isInitFailuresExceeded + useMainLimit with getMaxFailures closure
- track waitTime as a loop-outer variable, flip on init-done
- detect --init-max-failures via pflag.Changed || GITSYNC_INIT_MAX_FAILURES env; -1 = unlimited, 0 = abort immediately, unset = fall through to --max-failures
- drop now-stale unit tests for removed helpers, update --man and README
@knQzx
Copy link
Copy Markdown
Contributor Author

knQzx commented Apr 24, 2026

applied all five. small deviation in getMaxFailures: kept return *flMaxFailures instead of the literal > 0 gate, otherwise --max-failures=0 would flip from "abort on first failure" (current docs) to "never abort". outer guard is unchanged. lmk if you'd rather have the literal shape and we touch the main docs too

@thockin
Copy link
Copy Markdown
Member

thockin commented Apr 24, 2026

Thanks!

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 24, 2026
@k8s-ci-robot
Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: knQzx, thockin

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit fb0e300 into kubernetes:master Apr 24, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature Request: Different period setting for the initial sync

3 participants