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

ItemSnapshotter Plugin APIs #4077

Merged
merged 1 commit into from
Nov 16, 2021

Conversation

dsu-igeek
Copy link
Contributor

@dsu-igeek dsu-igeek commented Aug 30, 2021

ItemSnapshotter plugin APIs.
Added ItemSnapshotter.proto
Added item_snapshotter Go interface
Added framework components for item_snapshotter
Updated plugins doc with ItemSnapshotter info
Addresses #3754

Please indicate you've done the following:

@dsu-igeek dsu-igeek force-pushed the dsu-item-snapshotter-08-21-2021 branch from 8e3b6d6 to 0db329e Compare August 30, 2021 20:12
@dsu-igeek dsu-igeek force-pushed the dsu-item-snapshotter-08-21-2021 branch from 0db329e to 20c9c41 Compare August 30, 2021 20:15
@dsu-igeek dsu-igeek changed the title parent 74476db9d791fa91bba0147eac8ec189820adb3d ItemSnapshotter Plugin APIs Aug 30, 2021
@dsu-igeek dsu-igeek force-pushed the dsu-item-snapshotter-08-21-2021 branch from 20c9c41 to 078aadd Compare September 4, 2021 01:03
@dsu-igeek dsu-igeek force-pushed the dsu-item-snapshotter-08-21-2021 branch from 078aadd to baf5053 Compare September 4, 2021 01:12
@dsu-igeek dsu-igeek added this to the v1.8.0 milestone Sep 8, 2021
@dsu-igeek dsu-igeek force-pushed the dsu-item-snapshotter-08-21-2021 branch 2 times, most recently from f7b2d6d to 95b4fdf Compare September 13, 2021 18:48
@dsu-igeek dsu-igeek marked this pull request as ready for review September 28, 2021 05:58
@dsu-igeek dsu-igeek requested review from jenting, sseago and dims and removed request for dims September 28, 2021 05:59
return r
}

// getBackupItemAction returns the backup item action for this restartableBackupItemAction. It does *not* restart the
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

return itemSnapshotter, nil
}

// getDelegate restarts the plugin process (if needed) and returns the backup item action for this restartableBackupItemAction.
Copy link
Contributor

Choose a reason for hiding this comment

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

wrong comment

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup

ItemID velero.ResourceIdentifier
// SnapshotID is the snapshot ID returned by ItemSnapshotter
SnapshotID string
// Backup is the representation of the restore resource processed by Velero.
Copy link
Contributor

Choose a reason for hiding this comment

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

restore resource -> backup resource

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

type SnapshotItemOutput struct {
UpdatedItem runtime.Unstructured
SnapshotID string
SnapshotMetadata map[string]string
Copy link
Contributor

Choose a reason for hiding this comment

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

could you give a concrete example of SnapshotMetadata? This is not mentioned in the design and have you considered adding a GetSnapshot method to return the detail information of the snapshot?

// which will be handled by this plugin when snapshotting the item. For example, a database may expose
// a resource that can be snapshotted. If the database uses a PVC that will be snapshotted/backed up as
// part of the database snapshot, that PVC should be returned when AlsoHandles is invoked
AlsoHandles(input *AlsoHandlesInput) ([]velero.ResourceIdentifier, error)
Copy link
Contributor

Choose a reason for hiding this comment

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

This returns the same result as Additionalitems in SnapshotItemOutput?

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 updated the comment to explain:

// AlsoHandles is called for each item this ItemSnapshotter should handle and returns any items
// which will be handled by this plugin when snapshotting the item.  These items will be excluded from the
// items being backed up.  AlsoHandles will be called before SnapshotItem is called.  For example, a database may expose
// a database resource that can be snapshotted. If the database uses a PVC that will be snapshotted/backed up as
// part of the database snapshot, that PVC should be returned when AlsoHandles is invoked.  This is different from
// AdditionalItems (returned in SnapshotItemOutput and CreateItemOutput) which are specifying additional resources
// that Velero should store in the backup or create.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should be explicit in the comment here to explain if AlsoHandles returns the direct children PEs only, or does it recursively traverse the subtree to return all leaf items.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will return everything that should be excluded from the caller's list of things to do. If Astrolabe is backing the ItemSnapshotter, the expectation is that it returns all of the PEs that will be snapshotted so they can be removed from the list. ItemSnapshotter is not limited to Astrolabe, however, and is not a Protected Entity interface here.

Copy link
Contributor

Choose a reason for hiding this comment

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

So all children are handled in one call of SnapshotItem, right? The resources returned by AlsoHandles are only used to tell the caller to just ignore them

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, that's the plan

type CreateItemInput struct {
SnapshottedItem runtime.Unstructured
SnapshotID string
ItemFromBackup runtime.Unstructured
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add some comment to explain ItemFromBackup and SnapshotMetadata

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

if err != nil {
return nil, errors.WithStack(err)
}
itemFromBackupJSOB, err := json.Marshal(input.ItemFromBackup.UnstructuredContent())
Copy link
Contributor

Choose a reason for hiding this comment

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

itemFromBackupJSOB -> itemFromBackupJSON

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

// ProgressInput contains the input parameters for the ItemSnapshotter's Progress function.
type ProgressInput struct {
// ItemID is the id of item that was stored in the backup
ItemID velero.ResourceIdentifier
Copy link
Contributor

Choose a reason for hiding this comment

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

I notice here's a little inconsistency, in SnapshotItemInput the attribute is Item but in ProgressInput the attribute is ItemID

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When we snapshot we pass in the whole resource in case anything in it needs to be used. On progress we only need the ID and we may only have the ID at that point. If the Velero server is restarted before the progress is finished, we will lose the in-memory copy. The resource may be modified or deleted after the backup finishes so in order to pass in the resource here we would need to extract it from the backup. There's no need for anything other than the ID for checking progress so this saves a lot of trouble trying to recover the whole resource.


type DeleteSnapshotInput struct {
SnapshotID string
ItemFromBackup runtime.Unstructured
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't quite understand why ItemFromBackup is needed in the DeleteSnapshotInput, is it for cascade deletion?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We take it in the existing DeleteItemAction, it is probably useful and we have it available.

// DeleteItemActionExecuteInput contains the input parameters for the ItemAction's Execute function. type DeleteItemActionExecuteInput struct { // Item is the item taken from the pristine backed up version of resource. Item runtime.Unstructured // Backup is the representation of the restore resource processed by Velero. Backup *velerov1api.Backup }

UpdatedItem runtime.Unstructured
SnapshotID string
SnapshotMetadata map[string]string // SnapshotMetadata is information in addition to the SnapshotID that the
// plugin wants to store in the backup. SnapshotMetadata will be passed
Copy link
Contributor

Choose a reason for hiding this comment

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

The line of comments are not aligned, could you re-format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done


type CreateItemInput struct {
SnapshottedItem runtime.Unstructured // The snapshotted item at this stage of the restore (RestoreItemActions may
// have modified the item prior to CreateItemFromSnapshot being called)
Copy link
Contributor

Choose a reason for hiding this comment

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

The lines of comments are not aligned, could you re-format?

SnapshottedItem runtime.Unstructured // The snapshotted item at this stage of the restore (RestoreItemActions may
// have modified the item prior to CreateItemFromSnapshot being called)
SnapshotID string
ItemFromBackup runtime.Unstructured // The snapshotted item that was stored in the backup
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the "original version" of the SnapshottedItem?

IMO, if an item is modified by RestoreItemActions, the purpose is to let the subsequent plugins handle the modified version, otherwise, it should not be modified.

Is it for some corner cases that the two versions of an item is needed for ItemSnapshotterplugin to create the item from snapshot?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's useful to be able to see what it looked like before it got backed up. This is the same construct currently used in RestoreItemAction

// RestoreItemActionExecuteInput contains the input parameters for the ItemAction's Execute function. type RestoreItemActionExecuteInput struct { // Item is the item being restored. It is likely different from the pristine backed up version // (metadata reset, changed by various restore item action plugins, etc.). Item runtime.Unstructured // ItemFromBackup is the item taken from the pristine backed up version of resource. ItemFromBackup runtime.Unstructured // Restore is the representation of the restore resource processed by Velero. Restore *api.Restore }

@reasonerjt
Copy link
Contributor

Per discussion with Dave, some of the implementation of the input/output parameters to the API such as

type DeleteSnapshotInput struct {
	SnapshotID       string
	ItemFromBackup   runtime.Unstructured
	SnapshotMetadata map[string]string		// SnapshotMetadata returned from SnapshotItem
	Params           map[string]string
}

maybe modified in the near future before it's established to other APP developers.
My questions in the attributes of the structs can be ignored.

@dsu-igeek dsu-igeek force-pushed the dsu-item-snapshotter-08-21-2021 branch from 01b8c63 to 7cbab01 Compare November 8, 2021 07:31
// that Velero should store in the backup or create.
AlsoHandles(input *AlsoHandlesInput) ([]velero.ResourceIdentifier, error)

// SnapshotItem cause the ItemSnapshotter to snapshot the specified item. Ite may also
Copy link

Choose a reason for hiding this comment

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

Suggested change
// SnapshotItem cause the ItemSnapshotter to snapshot the specified item. Ite may also
// SnapshotItem cause the ItemSnapshotter to snapshot the specified item. It may also

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks

Copy link
Contributor

@zubron zubron left a comment

Choose a reason for hiding this comment

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

This looks good - I just have a few comments, mostly around the values set in the proto request/response objects. I don't know if they are intentionally not set or whether this is something that will be addressed in a follow up change.

pkg/plugin/clientmgmt/restartable_item_snapshotter_test.go Outdated Show resolved Hide resolved
pkg/plugin/framework/util.go Show resolved Hide resolved
pkg/plugin/clientmgmt/restartable_item_snapshotter.go Outdated Show resolved Hide resolved
pkg/plugin/velero/item_snapshotter/v1/item_snapshotter.go Outdated Show resolved Hide resolved
pkg/plugin/framework/item_snapshotter_server.go Outdated Show resolved Hide resolved
pkg/plugin/framework/item_snapshotter_client.go Outdated Show resolved Hide resolved
pkg/plugin/framework/item_snapshotter_server.go Outdated Show resolved Hide resolved
@zubron
Copy link
Contributor

zubron commented Nov 9, 2021

This looks good - I just have a few comments, mostly around the values set in the proto request/response objects. I don't know if they are intentionally not set or whether this is something that will be addressed in a follow up change.

Ah, I just read @reasonerjt's comment above and I'm assuming these are the parameters he's referring to. @dsu-igeek If that is the case, feel free to ignore/resolve my comments below about setting the fields in the requests and responses and I'll approve once the relevant copyright headers are added 👍

@jglick jglick mentioned this pull request Nov 10, 2021
1 task
@dsu-igeek dsu-igeek force-pushed the dsu-item-snapshotter-08-21-2021 branch 3 times, most recently from ece6665 to fe5a799 Compare November 11, 2021 04:26
Added ItemSnapshotter.proto
Added item_snapshotter Go interface
Added framework components for item_snapshotter
Updated plugins doc with ItemSnapshotter info
Added SnapshotPhase to item_snapshotter.go
ProgressOutputOutput now includes a phase as well as an error string for problems that occured

Signed-off-by: Dave Smith-Uchida <[email protected]>
@dsu-igeek dsu-igeek force-pushed the dsu-item-snapshotter-08-21-2021 branch from fe5a799 to 9a6e0f2 Compare November 11, 2021 21:39
Copy link
Contributor

@reasonerjt reasonerjt left a comment

Choose a reason for hiding this comment

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

I still have some different thoughts on the details of the parameters to the functions of the interface.
Given we have the plan to tweak the parameters in near future before the API is published, I'm approving this PR to unblock the progress.

Copy link
Contributor

@zubron zubron left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@zubron zubron merged commit 5150ce4 into vmware-tanzu:main Nov 16, 2021
@dsu-igeek
Copy link
Contributor Author

dsu-igeek commented Nov 17, 2021

Fixes #3754

qiuming-best pushed a commit to qiuming-best/velero that referenced this pull request Nov 22, 2021
…u#4077)

Added ItemSnapshotter.proto
Added item_snapshotter Go interface
Added framework components for item_snapshotter
Updated plugins doc with ItemSnapshotter info
Added SnapshotPhase to item_snapshotter.go
ProgressOutputOutput now includes a phase as well as an error string for problems that occured

Signed-off-by: Dave Smith-Uchida <[email protected]>
qiuming-best pushed a commit to qiuming-best/velero that referenced this pull request Nov 22, 2021
…u#4077)

Added ItemSnapshotter.proto
Added item_snapshotter Go interface
Added framework components for item_snapshotter
Updated plugins doc with ItemSnapshotter info
Added SnapshotPhase to item_snapshotter.go
ProgressOutputOutput now includes a phase as well as an error string for problems that occured

Signed-off-by: Dave Smith-Uchida <[email protected]>
danfengliu pushed a commit to danfengliu/velero that referenced this pull request Jan 25, 2022
…u#4077)

Added ItemSnapshotter.proto
Added item_snapshotter Go interface
Added framework components for item_snapshotter
Updated plugins doc with ItemSnapshotter info
Added SnapshotPhase to item_snapshotter.go
ProgressOutputOutput now includes a phase as well as an error string for problems that occured

Signed-off-by: Dave Smith-Uchida <[email protected]>
gyaozhou pushed a commit to gyaozhou/velero-read that referenced this pull request May 14, 2022
…u#4077)

Added ItemSnapshotter.proto
Added item_snapshotter Go interface
Added framework components for item_snapshotter
Updated plugins doc with ItemSnapshotter info
Added SnapshotPhase to item_snapshotter.go
ProgressOutputOutput now includes a phase as well as an error string for problems that occured

Signed-off-by: Dave Smith-Uchida <[email protected]>
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.

6 participants