Skip to content

Commit 0b74a73

Browse files
Merge pull request #8218 from sseago/itmblock-docs
Update design doc and site docs to reflect ItemBlock implementation
2 parents 95f6729 + e6fb4ba commit 0b74a73

3 files changed

Lines changed: 17 additions & 9 deletions

File tree

design/backup-performance-improvements.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ message ItemBlockActionGetRelatedItemsResponse {
102102
}
103103
```
104104

105-
A new PluginKind, `ItemBlockActionV1`, will be created, and the backup process will be modified to use this plugin kind.
105+
A new PluginKind, `ItemBlockAction`, will be created, and the backup process will be modified to use this plugin kind.
106106

107107
For any BIA plugins which return additional items from `Execute()` that need to be backed up at the same time or sequentially in the same worker thread as the current items should add a new IBA plugin to return these same items (minus any which won't exist before BIA `Execute()` is called).
108108
This mainly applies to plugins that operate on pods which reference resources which must be backed up along with the pod and are potentially affected by pod hooks or for plugins which connect multiple pods whose volumes should be backed up at the same time.
@@ -137,17 +137,21 @@ type ItemBlockItem struct {
137137
In the `BackupWithResolvers` func, the current Velero implementation iterates over the list of items for backup returned by the Item Collector. For each item, Velero loads the item from the file created by the Item Collector, we call `backupItem`, update the GR map if successful, remove the (temporary) file containing item metadata, and update progress for the backup.
138138

139139
#### Modifications to the loop over ItemCollector results
140-
The `kubernetesResource` struct used by the item collector will be modified to add an `orderedResource` bool which will be set true for all of the resources moved to the beginning of the list as a result of being ordered resources.
141-
While the item collector already puts ordered resources first, there is no indication in the list which of these initial items are from the ordered resources list and which are the remaining (unordered) items.
142-
Velero needs to know which resources are ordered because when we process them later, these initial resources must be processed sequentially, one at a time, before processing the remaining resources in a parallel manner.
140+
The `kubernetesResource` struct used by the item collector will be modified to add an `orderedResource` bool which will be set true for all of the resources moved to the beginning for each GroupResource as a result of being ordered resources.
141+
In addition, an `inItemBlock` bool is added to the struct which will be set to true later when processing the list when each item is added to an ItemBlock.
142+
While the item collector already puts ordered resources first for each GR, there is no indication in the list which of these initial items are from the ordered resources list and which are the remaining (unordered) items.
143+
Velero needs to know which resources are ordered because when we process them later, the ordered resources for each GroupResource must be processed sequentially in a single ItemBlock.
143144

144145
The current workflow within each iteration of the ItemCollector.items loop will replaced with the following:
145146
- (note that some of the below should be pulled out into a helper func to facilitate recursive call to it for items returned from `GetRelatedItems`.)
146-
- Before loop iteration, create a new `itemsInBlock` map of type map[velero.ResourceIdentifier]bool which represents the set of items already included in a block.
147-
- If `item` is already in `itemsInBlock`, continue. This one has already been processed.
148-
- Add `item` to `itemsInBlock`.
147+
- Before loop iteration, create a pointer to a `BackupItemBlock` which will represent the current ItemBlock being processed.
148+
- If `item` has `inItemBlock==true`, continue. This one has already been processed.
149+
- If current `itemBlock` is nil, create it.
150+
- Add `item` to `itemBlock`.
149151
- Load item from ItemCollector file. Close/remove file after loading (on error return or not, possibly with similar anonymous func to current impl)
152+
- If other versions of the same item exist (via EnableAPIGroupVersions), add these to the `itemBlock` as well (and load from ItemCollector file)
150153
- Get matching IBA plugins for item, call `GetRelatedItems` for each. For each item returned, get full item content from ItemCollector (if present in item list, pulling from file, removing file when done) or from cluster (if not present in item list), add item to the current block, add item to `itemsInBlock` map, and then recursively apply current step to each (i.e. call IBA method, add to block, etc.)
154+
- If current item and next item are both ordered items for the same GR, then continue to next item, adding to current `itemBlock`.
151155
- Once full ItemBlock list is generated, call `backupItemBlock(block ItemBlock)
152156
- Add `backupItemBlock` return values to `backedUpGroupResources` map
153157

@@ -156,7 +160,7 @@ The current workflow within each iteration of the ItemCollector.items loop will
156160

157161
Method signature for new func `backupItemBlock` is as follows:
158162
```go
159-
func backupItemBlock(block ItemBlock) []schema.GroupResource
163+
func (kb *kubernetesBackupper) backupItemBlock(block BackupItemBlock) []schema.GroupResource
160164
```
161165
The return value is a slice of GRs for resources which were backed up. Velero tracks these to determine which CRDs need to be included in the backup. Note that we need to make sure we include in this not only those resources that were backed up directly, but also those backed up indirectly via additional items BIA execute returns.
162166

@@ -363,4 +367,4 @@ func (a *PodAction) Name() string {
363367
## Implementation
364368
Phase 1 and Phase 2 could be implemented within the same Velero release cycle, but they need not be.
365369
Phase 1 is expected to be implemented in Velero 1.15.
366-
Phase 2 could either be in 1.15 as well, or in a later release, depending on the release timing and resource availability.
370+
Phase 2 is expected to be implemented in Velero 1.16.

site/content/docs/main/backup-hooks.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ processing ("pre" hooks), or after all custom actions have been completed and an
1313
specified by custom action have been backed up ("post" hooks). Note that hooks are _not_ executed within a shell
1414
on the containers.
1515

16+
As of Velero 1.15, related items that must be backed up together are grouped into ItemBlocks, and pod hooks run before and after the ItemBlock is backed up.
17+
In particular, this means that if an ItemBlock contains more than one pod (such as in a scenario where an RWX volume is mounted by multiple pods), pre hooks are run for all pods in the ItemBlock, then the items are backed up, then all post hooks are run.
18+
1619
There are two ways to specify hooks: annotations on the pod itself, and in the Backup spec.
1720

1821
### Specifying Hooks As Pod Annotations

site/content/docs/main/custom-plugins.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ Velero supports the following kinds of plugins:
5858
- **Backup Item Action** - executes arbitrary logic for individual items prior to storing them in a backup file
5959
- **Restore Item Action** - executes arbitrary logic for individual items prior to restoring them into a cluster
6060
- **Delete Item Action** - executes arbitrary logic based on individual items within a backup prior to deleting the backup
61+
- **Item Block Action** - executes arbitrary logic for individual items to determine which items should be backed up together
6162

6263
Plugin binaries are discovered by recursively reading a directory in no particular order. Hence no guarantee is provided for the
6364
order in which item action plugins are invoked. However, if a single binary implements multiple item action plugins,

0 commit comments

Comments
 (0)