[Feat] Pre exechook#990
Conversation
|
|
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: Mohamed-elg The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @Mohamed-elg! |
| The timeout for the --exechook-command. If not specifid, this | ||
| defaults to 30 seconds ("30s"). | ||
|
|
||
| --pre-exechook-backoff <duration>, $GITSYNC_PRE_EXECHOOK_BACKOFF |
There was a problem hiding this comment.
Flags should be in alphabetic-sorted order, sorry
| 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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
you are right, i changed the logic to have the hooks around the symlink rather than the sync event itself
| start := time.Now() | ||
| ctx, cancel := context.WithTimeout(context.Background(), *flSyncTimeout) | ||
|
|
||
| if preExechookRunner != nil { |
There was a problem hiding this comment.
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
}
There was a problem hiding this comment.
correct, fixed it by moving the logic inside git.SyncRepo as suggested
will add the e2e tests once the changes are validated |
thockin
left a comment
There was a problem hiding this comment.
Thanks! My comments are pretty superficial. I think the logic looks good. e2e tests will prove it.
| env = append(env, envKV("GITSYNC_HASH", hash)) | ||
|
|
||
| h.log.V(0).Info("running exechook", "hash", hash, "command", h.command, "timeout", h.timeout) | ||
| h.log.V(0).Info("running hook", "name", h.name, "hash", hash, "command", h.command, "timeout", h.timeout) |
There was a problem hiding this comment.
super nitpicky, but I would leave the key as "exechook". If this is the only thing I flag, I will overlook it :)
| envDuration(3*time.Second, "GITSYNC_EXECHOOK_BACKOFF", "GIT_SYNC_EXECHOOK_BACKOFF"), | ||
| "the time to wait before retrying a failed exechook") | ||
|
|
||
| flPreExechookCommand := pflag.String("pre-exechook-command", |
There was a problem hiding this comment.
I am struggling with the name -- "pre-exechook" makes it sound like it runs before the exechook.
How about "prepub-exechook-*" ? Any better ideas?
| "the time to wait before retrying a failed exechook") | ||
|
|
||
| flPreExechookCommand := pflag.String("pre-exechook-command", | ||
| envString("", "GITSYNC_PRE_EXECHOOK_COMMAND", "GIT_SYNC_PRE_EXECHOOK_COMMAND"), |
There was a problem hiding this comment.
We don't need the old-style names "GIT_SYNC_..." - those are just for backwards compat in older flags.
| An optional command to be executed after syncing a new hash of the | ||
| remote repository. This command does not take any arguments and | ||
| remote repository and publishing the symlink (see --link). | ||
| This command does not take any arguments and |
There was a problem hiding this comment.
Please reflow this to 80 columns (it looks like "executes" can fold back up a line) but make sure to use spaces and not tabs. Sorry, this is annoying, but I like the extra detail
| remote repository but before publishing the symlink (see --link). | ||
| This command does not take any arguments and | ||
| executes with the synced repo as its working directory. The | ||
| $GITSYNC_HASH environment variable will be set to the previous git hash that |
There was a problem hiding this comment.
please reflow this whole block to 80 columns
| @@ -1842,7 +1908,12 @@ func (git *repoSync) SyncRepo(ctx context.Context, refreshCreds func(context.Con | |||
|
|
|||
| // If we have a new hash, update the symlink to point to the new worktree. | |||
| if changed { | |||
There was a problem hiding this comment.
This is super subtle, and we should leave a comment - I had to walk through it to understand the subtlety.
Something like:
"""
If the previous run crashed before publishing the link, then we must call the pre-publish hook, and since changed is true, we will. If the previous run crashed after publishing the link, then we do not need to call the pre-publish hook, and since changed is false, we won't. The post-publish hooks are called in both cases.
/kind feature
What this PR does:
Fixes #937
adds flags for
--pre-exechook-command,--pre-exechook-timeoutand--pre-exechook-backoffto run a command similarly to the exechook but before the syncFollows #937 (comment)