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

Uploader Implementation: Kopia backup and restore #5221

Merged
merged 3 commits into from Aug 22, 2022

Conversation

qiuming-best
Copy link
Contributor

@qiuming-best qiuming-best commented Aug 16, 2022

Signed-off-by: Ming mqiu@vmware.com

Thank you for contributing to Velero!

Please add a summary of your change

Uploader Implementation: Kopia backup and restore
It's about uploader module implementation, which related to kopia implementation of backup and restore
which reference to #5074 #5073

Please indicate you've done the following:

  • Accepted the DCO. Commits without the DCO will delay acceptance.
  • Created a changelog file or added /kind changelog-not-required as a comment on this pull request.
  • Updated the corresponding documentation in site/content/docs/main.

pkg/uploader/provider/kopia.go Outdated Show resolved Hide resolved
pkg/uploader/provider/kopia.go Outdated Show resolved Hide resolved
pkg/uploader/provider/kopia.go Outdated Show resolved Hide resolved
pkg/repository/mocks/repository_writer.go Show resolved Hide resolved
pkg/uploader/provider/kopia.go Outdated Show resolved Hide resolved
pkg/uploader/provider/kopia.go Outdated Show resolved Hide resolved
pkg/uploader/provider/kopia.go Show resolved Hide resolved
pkg/uploader/provider/provider.go Outdated Show resolved Hide resolved
pkg/uploader/provider/provider.go Outdated Show resolved Hide resolved
@qiuming-best qiuming-best force-pushed the uploader-kopia branch 3 times, most recently from ffe390d to 67c5d38 Compare August 18, 2022 03:40
pkg/uploader/kopia/snapshot.go Outdated Show resolved Hide resolved
pkg/uploader/kopia/snapshot.go Outdated Show resolved Hide resolved
pkg/uploader/kopia/snapshot.go Show resolved Hide resolved
pkg/uploader/provider/kopia.go Outdated Show resolved Hide resolved
pkg/uploader/provider/kopia.go Outdated Show resolved Hide resolved
@qiuming-best qiuming-best force-pushed the uploader-kopia branch 3 times, most recently from db0b2e8 to 4060bec Compare August 19, 2022 08:11
@codecov-commenter
Copy link

codecov-commenter commented Aug 19, 2022

Codecov Report

Merging #5221 (9cb7a15) into main (1ba7b3d) will decrease coverage by 0.39%.
The diff coverage is 39.55%.

@@            Coverage Diff             @@
##             main    #5221      +/-   ##
==========================================
- Coverage   41.79%   41.39%   -0.40%     
==========================================
  Files         225      231       +6     
  Lines       19172    19659     +487     
==========================================
+ Hits         8012     8137     +125     
- Misses      10574    10928     +354     
- Partials      586      594       +8     
Impacted Files Coverage Δ
pkg/cmd/util/output/backup_describer.go 0.00% <0.00%> (ø)
pkg/controller/pod_volume_backup_controller.go 41.93% <0.00%> (-2.14%) ⬇️
pkg/controller/pod_volume_restore_controller.go 21.62% <0.00%> (-1.24%) ⬇️
pkg/uploader/kopia/progress.go 0.00% <0.00%> (ø)
pkg/uploader/provider/provider.go 0.00% <0.00%> (ø)
pkg/uploader/provider/restic.go 0.00% <0.00%> (ø)
pkg/uploader/types.go 100.00% <ø> (ø)
pkg/uploader/kopia/snapshot.go 37.50% <37.50%> (ø)
pkg/uploader/provider/kopia.go 54.38% <54.38%> (ø)
pkg/uploader/kopia/shim.go 0.00% <0.00%> (ø)
... and 1 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@qiuming-best qiuming-best force-pushed the uploader-kopia branch 5 times, most recently from e69a372 to 8d5e38f Compare August 19, 2022 09:12
Lyndon-Li
Lyndon-Li previously approved these changes Aug 19, 2022
}

//NewKopiaUploaderProvider initialized with open or create a repository
func NewKopiaUploaderProvider(
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the velerov1.BackupRepo a parameter of the function? Or how does the uploader know where to put the files?

And seems only the BSL's UID is used, how does the uploader know the access information(e.g. URL) of the storage?

Copy link
Contributor

@Lyndon-Li Lyndon-Li Aug 22, 2022

Choose a reason for hiding this comment

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

Yes, I am considering this problem, we need to use BSL+VolumeNamespace to identify a repository. On the other hand, actually, if we have the velerov1.BackupRepo, it is enough to just use velerov1.BackupRepo's UUID to identify a repository, which is quite simple. However, in the current code, PVB/PVR doesn't get the velerov1.BackupRepo.

Let me consider this for some more time and discuss with you guys later. In the current PR, let's make it as is.

Copy link
Contributor

@Lyndon-Li Lyndon-Li Aug 22, 2022

Choose a reason for hiding this comment

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

Let me add some more explanation here:

  • During the Connect operation of unified repo, a config file containing all the connecting information, except the credentials, is stored in a local file
  • During the backup/restore, as long as the uploader could provide the name of the config file, it could connect to the repo and then write/read data to/from the repo
  • The Connection operation is done during repo initialization, that is, by the velerov1.BackupRepo reconciler
  • We need a unique file name for the local config so that different repos don't mix up their configuration
  • At present, the config file is named by the BSL's UUID

As mentioned above BSL's UUID is not enough, velerov1.BackupRepo's UUID is more suitable, however, it is not currently available in PVB/PVR

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah, I've changed into velerov1.BackupRepo's UUID

//CheckContext check context status periodically
//check if context is timeout or cancel
func (kp *kopiaProvider) CheckContext(ctx context.Context) {
for {
Copy link
Contributor

Choose a reason for hiding this comment

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

The for loop should be stopped once the backup/restore is finished

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I've add one finishChan chan to stop the loop once finished

Copy link
Contributor

Choose a reason for hiding this comment

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

Seems the for loop isn't needed. By removing the default section, we can use select without the for loop

return errors.Wrapf(err, "Failed to run kopia restore")
}

updater.UpdateProgress(&uploader.UploaderProgress{
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need to update the progress here? Could you add comments about it if it is needed indeed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To ensure that the statistic data of TotalBytes is equal to BytesDone when finished, I've added one annotation

prorgess := new(kopia.KopiaProgress)
prorgess.InitThrottle(backupProgressCheckInterval)
prorgess.Updater = updater
kp.uploader.Progress = prorgess
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems the Progress of the shared uploader will be overwritten when calling Runbackups()
more than once.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I've removed the uploader from the kopiaProvider struct. which will make the progress is independent for every backup

bkRepo udmrepo.BackupRepo
credGetter *credentials.CredentialGetter
uploader *snapshotfs.Uploader
restoreCancel chan struct{}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it only for one specific restore? If it is, it should be not the field of kopiaProvider as kopiaProvider are shared by different RunRestore() actions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed it from the kopiaProvider struct.

"parentSnapshot": parentSnapshot,
})
repoWriter := kopia.NewShimRepo(kp.bkRepo)
kp.uploader = snapshotfs.NewUploader(repoWriter)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the uploader shared with other function calls?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've removed uploader from kp

Signed-off-by: Ming <mqiu@vmware.com>
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.

None yet

4 participants