Skip to content

[Feat] Pre exechook#990

Open
Mohamed-elg wants to merge 3 commits into
kubernetes:masterfrom
Mohamed-elg:pre-hook
Open

[Feat] Pre exechook#990
Mohamed-elg wants to merge 3 commits into
kubernetes:masterfrom
Mohamed-elg:pre-hook

Conversation

@Mohamed-elg

@Mohamed-elg Mohamed-elg commented Jun 11, 2026

Copy link
Copy Markdown

/kind feature

What this PR does:
Fixes #937
adds flags for --pre-exechook-command, --pre-exechook-timeout and --pre-exechook-backoff to run a command similarly to the exechook but before the sync

Follows #937 (comment)

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jun 11, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

  • ✅ login: Mohamed-elg / name: Mohamed-elg (757c143)

@k8s-ci-robot

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Mohamed-elg
Once this PR has been reviewed and has the lgtm label, please assign thockin for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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

Copy link
Copy Markdown
Contributor

Welcome @Mohamed-elg!

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 requested review from stp-ip and thockin June 11, 2026 20:22
@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Jun 11, 2026
@Mohamed-elg Mohamed-elg marked this pull request as draft June 11, 2026 20:23
@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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 Jun 11, 2026
@Mohamed-elg Mohamed-elg marked this pull request as ready for review June 11, 2026 20:56
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 11, 2026
@k8s-ci-robot k8s-ci-robot requested review from janetkuo and sdowell June 11, 2026 20:56

@thockin thockin left a comment

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.

Thanks for the PR! Notes below. Also, this will need e2e tests

Comment thread main.go
The timeout for the --exechook-command. If not specifid, this
defaults to 30 seconds ("30s").

--pre-exechook-backoff <duration>, $GITSYNC_PRE_EXECHOOK_BACKOFF

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.

Flags should be in alphabetic-sorted order, sorry

Comment thread main.go
not specified, this defaults to 3 seconds ("3s").

--pre-exechook-command <string>, $GITSYNC_PRE_EXECHOOK_COMMAND
An optional command to be executed before syncing a new hash of the

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.

This isn't quite right.

I think we should update the docs on --exechook-command to say something like:

"""
An optional command to be executed after syncing a new hash of the remote repository and publishing the symlink (see --link).
"""

Then this can be:

"""
An optional command to be executed after syncing a new hash of the remote repository but before publishing the symlink (see --link).
"""

The rest should the same. What do you think?

Comment thread main.go
start := time.Now()
ctx, cancel := context.WithTimeout(context.Background(), *flSyncTimeout)

if preExechookRunner != nil {

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.

This doesn't seem right? This will send the old hash on every loop, then sync a new hash. Unless I totally misunderstood the request, you want to try to sync, and ONLY IF there is a new hash, call the hook before publishing the symlink.

Did I misunderstand?

Unfortunately, the sync and the publish are inside git.SyncRepo. You can either decompose that (which would need to share a bunch of state) or you could pass function pointers into it like we do for refreshCreds - pass a struct like:

type syncHooks struct {
    refreshCreds func(context.Context) error
    beforePublish func(context.Context, changed bool, hash string) error
    afterPublish func(context.Context, changed bool, hash string) error
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

How to Prevent .env and upload from Being Deleted During git-sync (Similar to .gitignore)

3 participants