Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix backup post hook issue #8490

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ywk253100
Copy link
Contributor

@ywk253100 ywk253100 commented Dec 6, 2024

Fixes #8159 on main branch.

This PR introduces an overall Handler to handle all kinds of hooks.

The basic workflow is as follows:

  1. The Parser parses the hooks from different specs into a common ResourceHook structure.
  2. The Handler handles the ResourceHook by delegating to a specific ResourceHandler according to the hook type:
    • podBackupPreHookHandler: handles the backup pre hook for pods
    • podBackupPostHookHandler: handles the backup post hook for pods

The changes in this PR will be cherry-picked to branch 1.15 to fix #8159.

And will create another PR to cover restore init/exec hooks for pods and the PR will be only available on main (tracked by #8507 )

@kaovilai
Copy link
Member

kaovilai commented Dec 6, 2024

changelog check

Edit: nvm.. ci failed

@kaovilai kaovilai closed this Dec 6, 2024
@kaovilai kaovilai reopened this Dec 6, 2024
@github-actions github-actions bot requested review from kaovilai and sseago December 6, 2024 20:54
@ywk253100 ywk253100 force-pushed the 241015_post_hook branch 3 times, most recently from cd72052 to 714a8e7 Compare December 9, 2024 09:09
Copy link

codecov bot commented Dec 9, 2024

Codecov Report

Attention: Patch coverage is 86.57718% with 40 lines in your changes missing coverage. Please review.

Project coverage is 59.08%. Comparing base (aa7ca15) to head (3a45a10).
Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
internal/hook/parser.go 80.95% 17 Missing and 3 partials ⚠️
pkg/backup/backup.go 82.60% 6 Missing and 2 partials ⚠️
internal/hook/handler.go 96.34% 2 Missing and 1 partial ⚠️
internal/hook/pod_backup_post_hook_handler.go 86.36% 2 Missing and 1 partial ⚠️
internal/hook/pod_backup_pre_hook_handler.go 85.00% 2 Missing and 1 partial ⚠️
pkg/podvolume/backupper.go 75.00% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #8490      +/-   ##
==========================================
+ Coverage   59.02%   59.08%   +0.06%     
==========================================
  Files         369      374       +5     
  Lines       39056    39214     +158     
==========================================
+ Hits        23052    23169     +117     
- Misses      14542    14575      +33     
- Partials     1462     1470       +8     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@ywk253100 ywk253100 force-pushed the 241015_post_hook branch 2 times, most recently from fbf41f6 to 4952618 Compare December 9, 2024 11:31
internal/hook/handler.go Outdated Show resolved Hide resolved
Fix backup post hook issue: hook executes before the backup is finished

Signed-off-by: Wenkai Yin(尹文开) <[email protected]>
// So when Pods are backed up (when hooks execute), the snapshot is taken already
func (p *podBackupPostHookHandler) WaitUntilReadyToExec(ctx context.Context, log logrus.FieldLogger, res *unstructured.Unstructured) error {
// wait all PVBs processed
_, err := p.podVolumeBackupper.WaitAllPodVolumesProcessed(log)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here is a limitation:
The logic here waits all PVBs of the whole backup to be completed before executing the hooks. This delays the hook execution of one pod although it isn't necessary.

The ideal behavior should be only wait the PVBs belongs to one ItemBlock to be completed before executing the hooks, but this involves the refactor for podvolume.Backupper to make is capable to check whether the PVBs of one ItemBlock completed. The effort isn't tiny, so created another issue #8506 to track.

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

Successfully merging this pull request may close these issues.

Post hook command is executed before the Kopia snapshot is completed
2 participants