kubernetes/git-sync

exechook behavior

jseide opened this issue · 4 comments

Does the exechook run even if the the sync determines an update is not required?

The docs say "If at startup git-sync finds that the root already has correct hash, this hook will still be invoked"

My experience suggests this hook is only invoked when there is a change in the remote.

It should run at startup in the case that it finds data that matches the remote. I just verified:

{"logger":"","ts":"2024-05-03 15:20:49.887866","caller":{"file":"main.go","line":1560},"level":3,"msg":"syncing","repo":"http://github.com/kubernetes/git-sync"}
{"logger":"","ts":"2024-05-03 15:20:49.887892","caller":{"file":"main.go","line":1095},"level":3,"msg":"repo directory exists","path":"/tmp/gst"}
{"logger":"","ts":"2024-05-03 15:20:49.887925","caller":{"file":"main.go","line":1167},"level":3,"msg":"sanity-checking git repo","repo":"/tmp/gst"}
{"logger":"","ts":"2024-05-03 15:20:49.888012","caller":{"file":"main.go","line":1178},"level":5,"msg":"running command","cwd":"/tmp/gst","cmd":"git rev-parse --show-toplevel"}
{"logger":"","ts":"2024-05-03 15:20:49.889827","caller":{"file":"main.go","line":1191},"level":5,"msg":"running command","cwd":"/tmp/gst","cmd":"git fsck --no-progress --connectivity-only"}
{"logger":"","ts":"2024-05-03 15:20:49.899569","caller":{"file":"main.go","line":1097},"level":4,"msg":"repo directory is valid","path":"/tmp/gst"}
{"logger":"","ts":"2024-05-03 15:20:49.899611","caller":{"file":"main.go","line":1124},"level":5,"msg":"running command","cwd":"/tmp/gst","cmd":"git remote get-url origin"}
{"logger":"","ts":"2024-05-03 15:20:49.901315","caller":{"file":"main.go","line":1579},"level":3,"msg":"current state","hash":"df639fddbfbb0af930a1532d836bd65d80ad3417","worktree":"/tmp/gst/.worktrees/df639fddbfbb0af930a1532d836bd65d80ad3417"}
{"logger":"","ts":"2024-05-03 15:20:49.901349","caller":{"file":"main.go","line":1685},"level":2,"msg":"fetching","ref":"HEAD","repo":"http://github.com/kubernetes/git-sync"}
{"logger":"","ts":"2024-05-03 15:20:49.901362","caller":{"file":"main.go","line":1703},"level":5,"msg":"running command","cwd":"/tmp/gst","cmd":"git fetch http://github.com/kubernetes/git-sync HEAD --verbose --no-progress --prune --no-auto-gc --depth 1"}
{"logger":"","ts":"2024-05-03 15:20:50.506173","caller":{"file":"main.go","line":1591},"level":5,"msg":"running command","cwd":"/tmp/gst","cmd":"git rev-parse FETCH_HEAD^{}"}
{"logger":"","ts":"2024-05-03 15:20:50.508478","caller":{"file":"main.go","line":1599},"level":3,"msg":"current hash is same as remote","hash":"df639fddbfbb0af930a1532d836bd65d80ad3417"}
{"logger":"","ts":"2024-05-03 15:20:50.508505","caller":{"file":"main.go","line":1204},"level":3,"msg":"sanity-checking worktree","repo":"/tmp/gst","worktree":"/tmp/gst/.worktrees/df639fddbfbb0af930a1532d836bd65d80ad3417"}
{"logger":"","ts":"2024-05-03 15:20:50.508663","caller":{"file":"main.go","line":1216},"level":5,"msg":"running command","cwd":"/tmp/gst/.worktrees/df639fddbfbb0af930a1532d836bd65d80ad3417","cmd":"git rev-parse HEAD"}
{"logger":"","ts":"2024-05-03 15:20:50.510742","caller":{"file":"main.go","line":1228},"level":5,"msg":"running command","cwd":"/tmp/gst/.worktrees/df639fddbfbb0af930a1532d836bd65d80ad3417","cmd":"git fsck --no-progress --connectivity-only"}
{"logger":"","ts":"2024-05-03 15:20:50.521137","caller":{"file":"main.go","line":1617},"level":0,"msg":"update required","ref":"HEAD","local":"df639fddbfbb0af930a1532d836bd65d80ad3417","remote":"df639fddbfbb0af930a1532d836bd65d80ad3417","syncCount":0}
{"logger":"","ts":"2024-05-03 15:20:50.521186","caller":{"file":"main.go","line":1623},"level":5,"msg":"running command","cwd":"/tmp/gst","cmd":"git reset --soft df639fddbfbb0af930a1532d836bd65d80ad3417"}
{"logger":"","ts":"2024-05-03 15:20:50.525195","caller":{"file":"main.go","line":1426},"level":1,"msg":"setting worktree HEAD","hash":"df639fddbfbb0af930a1532d836bd65d80ad3417"}
{"logger":"","ts":"2024-05-03 15:20:50.525237","caller":{"file":"main.go","line":1427},"level":5,"msg":"running command","cwd":"/tmp/gst/.worktrees/df639fddbfbb0af930a1532d836bd65d80ad3417","cmd":"git reset --hard df639fddbfbb0af930a1532d836bd65d80ad3417 --"}
{"logger":"","ts":"2024-05-03 15:20:50.627406","caller":{"file":"main.go","line":1434},"level":1,"msg":"updating submodules"}
{"logger":"","ts":"2024-05-03 15:20:50.627448","caller":{"file":"main.go","line":1442},"level":5,"msg":"running command","cwd":"/tmp/gst/.worktrees/df639fddbfbb0af930a1532d836bd65d80ad3417","cmd":"git submodule update --init --recursive --depth 1"}
{"logger":"","ts":"2024-05-03 15:20:50.657227","caller":{"file":"main.go","line":1663},"level":0,"msg":"updated successfully","ref":"HEAD","remote":"df639fddbfbb0af930a1532d836bd65d80ad3417","syncCount":1}
{"logger":"","ts":"2024-05-03 15:20:50.657297","caller":{"file":"main.go","line":1148},"level":3,"msg":"cleaning up stale worktrees","currentHash":"df639fddbfbb0af930a1532d836bd65d80ad3417"}
{"logger":"","ts":"2024-05-03 15:20:50.657361","caller":{"file":"main.go","line":1271},"level":4,"msg":"skipping path","path":"/tmp/gst/.worktrees/df639fddbfbb0af930a1532d836bd65d80ad3417"}
{"logger":"","ts":"2024-05-03 15:20:50.657373","caller":{"file":"main.go","line":874},"level":3,"msg":"next sync","waitTime":"10s","syncCount":1}
{"logger":"exechook","ts":"2024-05-03 15:20:50.657371","caller":{"file":"exechook.go","line":71},"level":0,"msg":"running exechook","hash":"df639fddbfbb0af930a1532d836bd65d80ad3417","command":"/usr/bin/date","timeout":"30s"}
{"logger":"exechook","ts":"2024-05-03 15:20:50.657429","caller":{"file":"exechook.go","line":72},"level":5,"msg":"running command","cwd":"/tmp/gst/.worktrees/df639fddbfbb0af930a1532d836bd65d80ad3417","cmd":"/usr/bin/date "}
{"logger":"exechook","ts":"2024-05-03 15:20:50.658278","caller":{"file":"exechook.go","line":74},"level":1,"msg":"exechook succeeded","hash":"df639fddbfbb0af930a1532d836bd65d80ad3417","stdout":"Fri May  3 03:20:50 PM PDT 2024","stderr":""}

Note that this was not always the case - it's new in v4.x. If you have evidence of this NOT being correct, please post full logs (redacted if necessary) and how I can repro.

So the exechook only runs if my remote has new commits?

If that's the case, perhaps the docs could be clarified.

So the exechook only runs if my remote has new commits?

No, exactly the opposite. The docs say "If at startup git-sync finds that the root already has correct hash, this hook will still be invoked". This is correct. To be more clear:

The exechook (and webhook) will be invoked when:

  • git-sync runs the very first sync (every time it starts or restarts); AND
  • git-sync finds the remote hash to be different than the local hash and sucessfully syncs it

Got it thanks. I was hoping the hook would run each time git-sync polls the remote, whether or not the an update is required.